Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: using an array for a call stack

    I just read something:
    "A stack is typically implemented with an array. Initialize the array when your application starts. Then, at the beginning of each procedure, place the procedure’s name as the last element of the array, moving all other array elements up by one. Just before the procedure exits, it should remove its name from the array. "

    but dont know how to create array, initialize, or move all element arrays up by one, can anyone give me an example please.


    Thanks

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    What is the end goal / what are you trying to solve?
    Arrays are a notorious PITA in Access, but if this is the right solution then I'm sure we can sort something out!
    George
    Home | Blog

  3. #3
    Join Date
    Oct 2003
    Posts
    233
    Quote Originally Posted by georgev
    What is the end goal / what are you trying to solve?
    Arrays are a notorious PITA in Access, but if this is the right solution then I'm sure we can sort something out!
    The goal is to add method names to the array as they are called, so if i have an error i have a stack trace, hmmm im using 2000

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Declare your array
    Code:
    Public myArray() As Variant
    How to use it
    Code:
    On Error GoTo ErrorHandler
    
      Dim x As Integer
      
      x = 1/0
    
    ErrorHandler:
      myArray(UBound(myArray) + 1) = Err.Number
    The above should add the error number to the top element + 1 (a new element).
    Please note I've not tested this, just pulled it straight out of the mindbox.

    Let me know how you get on
    George
    Home | Blog

  5. #5
    Join Date
    Oct 2003
    Posts
    233
    i tried the code below, and i am getting a script out of range on sub One

    Private callStack() As String
    Sub one()
    callStack(UBound(callStack) + 1) = "One"
    End Sub
    Sub two()
    callStack(UBound(callStack) + 1) = "Two"
    End Sub
    Sub three()
    callStack(UBound(callStack) + 1) = "three"
    End Sub
    Sub StartHere()
    one
    two
    three
    Dim i As Integer
    For i = 0 To UBound(callStack)
    Debug.Print callStack(i)
    Next
    End Sub

  6. #6
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You have to redim dynamically sized arrays if you want to add elements to them. It's telling you you're not allowed to to set callStack(1) = "whatever" because it has zero elements. You have to Redim it to have the number of required elements first. At one time I had a bunch of array manipulation routines for push, pop, shift etc. I'll see if I can locate those.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  7. #7
    Join Date
    Oct 2003
    Posts
    233
    Cool thanks!

  8. #8
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I used this as a reference for my global error hanlder (check the bottom of the page):

    http://www.fmsinc.com/tpapers/vbacode/Debug.asp

    I have added a couple of features, including a form that will show the callstack. An error log (errors written to a file with the callstack).

  9. #9
    Join Date
    Oct 2003
    Posts
    233
    Quote Originally Posted by DCKunkle
    I used this as a reference for my global error hanlder (check the bottom of the page):

    http://www.fmsinc.com/tpapers/vbacode/Debug.asp

    I have added a couple of features, including a form that will show the callstack. An error log (errors written to a file with the callstack).

    excellent, thats where i got the idea of the stack!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •