I presumed that these functions for Push and Pop already existed, and that you only had to use them.
Fortunately, because you can find out the status of an array, you don't need to do thing in as complex a fashion as you would if you were working in a lower-level environment.
Tp push a value onto an array, you obtain the index of the top item, add a new item to the array (that is, expand it's size by one), then add the data to that element (that is, set that new element to the value of the data).
Code:
Dim i As Integer
i = UBound(MyArray)
Redim Preserve MyArray(1 to i + 1) ' Preserve is nec. to keep
the existing values.
MyArray(i + 1) = MyNewValue
If you wrap all this in a routine named Push(), you can either make it a Function, returning the new size of the array, or just a Sub that handles the action details, being called from one, simple, self documenting line: Push NewValue, MyArray.
Pulling a value off the array can be done exactly the same, except you read the value at the UBound() position, then ReDim the array i - 1.
Because
VB maintains UBound and LBound, you do not need to increment or decrement any variables and maintain them to keep track of what the status of your array is.
If you are working with strings, you can make this even simpler. The pushing of a value onto the end of the string is just:
Code:
MyString = MyString & MyNewChar
The string will be expanded by 1 for you, if MyNewChar is just one character in size.
The Pop procedure would be a little more complex, but only a little:
Code:
Dim Temp As String * 1 ' Creates a 1-character, fixed-length string
Temp = Right$(MyString, 1) ' Get the right-most character's value.
MyString = Left$(MyString, Len(MyString) - 1) ' Shorten the string by 1