1,105,225 Community Members

Adding stack elements to labels

Member Avatar
Alex_2011
Light Poster
34 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
Member Avatar
Jx_Man
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]
Featured
 
0
 
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
Question Answered as of 2 Years Ago by Jx_Man
Member Avatar
Alex_2011
Light Poster
34 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: