We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,453 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Adding stack elements to labels

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
2
Contributors
2
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
Alex_2011
Light Poster
34 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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
Jx_Man
Senior Poster
3,553 posts since Nov 2007
Reputation Points: 1,500
Solved Threads: 531
Skill Endorsements: 65
Question Answered as of 1 Year Ago by Jx_Man

Thank you

Alex_2011
Light Poster
34 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0616 seconds using 2.69MB