Pop

From Xojo Documentation

Method

Removes the last element from an array and returns its value.

Usage

result = array.Pop

Part Type Description
result Same as array The element of array that was removed.
array Any valid data type for an array The array from which the last value will be popped.

Notes

The Append and Pop methods can be used together to treat an array as a stack.The Append method pushes a new element onto the array/stack and the Pop method removes the last element from the array/stack and returns its value.

If array has no values then an OutOfBoundsException is raised.

Sample Code

This example pushes "One", "Two", "Three" onto an array used as a stack and then Pops the values off in reverse order:

Dim stack() As String

stack.Append("One")
stack.Append("Two")
stack.Append("Three")

MsgBox(stack.Pop)
MsgBox(stack.Pop)
MsgBox(stack.Pop)

This is a directory-crawling routine that performs a depth-first traversal without using recursion:

Dim itemsToInspect(0) As FolderItem
Dim item As FolderItem
Dim directory As FolderItem
Dim ctr As Integer
directory = SelectFolder
If directory.Exists Then
itemsToInspect(0) = directory
While Ubound(itemsToInspect) >= 0
item = itemsToInspect.Pop
If item.Directory Then
For ctr = 1 To item.Count
itemsToInspect.Append(item.Item(ctr))
Next
End If
Wend
End If

See Also

Dim statement; Array, Join, Split, Ubound functions; Append, IndexOf, Insert, Redim, Remove, Shuffle, Sort, Sortwith methods; ParamArray keyword; Arrays concept