Where is your stack declaration?
Dim Stack(4) As String -> Your Declaration is for array
You need to declare stack before add it. Dim MyStack as New Stack(4) -> This for Stack
To Add stack MyStack.Push(userMsg )
' Declare as global variable
Dim MaxSize As Integer = 4
Dim MyStack As New Stack(maxsize)
Private Sub Button1Push_Click(sender As System.Object, e As System.EventArgs) Handles Button1Push.Click
Dim userMsg As String
userMsg = InputBox("Push", "Stacks", "Enter your letter here", 500, 500)
If MyStack.Count <= MaxSize Then
MyStack.Push(userMsg)
Else
MsgBox("Stack is Full")
End If
End Sub
Private Sub Button2Pop_Click(sender As System.Object, e As System.EventArgs) Handles Button2Pop.Click
MsgBox(MyStack.Pop) ' Remove and return object at the top of stack
End Sub Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444