Hi,

I am trying to add (Push) whatever the user enters in (MyStack) into 5 different labels that should show the (UserResponse).
The problem is I don't know how to display each element in a different label.
For example:
- The first element that the user enters (UserResponse) should be in Label1
- The second element that the user enters (UserResponse) should be in Label2 etc....
up to label5.

Also, when I press (Pop) the elements should disappear (Last in first out).

I know I am missing some steps, but could not figure them out.
Thank you for you help.

Public Class Form1
    Private MyStack As New Stack(4)

    Private Sub ButtonPush_Click(sender As System.Object, e As System.EventArgs) Handles ButtonPush.Click

        Dim UserResponse As String = InputBox("Add")

        If MyStack.Count <= 4 Then
            MyStack.Push(UserResponse)
        Else
            MsgBox("Stack is Full")
        End If


    End Sub

    Private Sub ButtonPop_Click(sender As System.Object, e As System.EventArgs) Handles ButtonPop.Click
        Try
            MyStack.Pop()
        Catch ex As Exception
            MessageBox.Show("Error - Stack is empty")
        End Try

    End Sub

    Private Sub Label1Display_Click(sender As System.Object, e As System.EventArgs) Handles Label1Display.Click

    End Sub


    Private Sub Label2Display_Click(sender As System.Object, e As System.EventArgs) Handles Label2Display.Click

    End Sub

    Private Sub Label3Display_Click(sender As System.Object, e As System.EventArgs) Handles Label3Display.Click

    End Sub

    Private Sub Label4Display_Click(sender As System.Object, e As System.EventArgs) Handles Label4Display.Click

    End Sub

    Private Sub Label5Display_Click(sender As System.Object, e As System.EventArgs) Handles Label5Display.Click
    

    End Sub
End Class
Label1Display.Text = Stacks(0).ToString
Label2Display.Text = Stacks(1).ToString
Label3Display.Text = Stacks(2).ToString
Label4Display.Text = Stacks(3).ToString
Label5Display.Text = Stacks(4).ToString
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.