5 Replies - 3530 Views - Last Post: 06 February 2012 - 06:02 PM Rate Topic: -----

#1 eseyee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-February 12

How can I add values from a TextBox to an Array via an addButton

Posted 06 February 2012 - 03:16 PM

After I store the values into the array via the addButton I need to display each value and the total of all the values into a TextBox via the createButton
Here is an image of how the application is supposed to look: http://i.imgur.com/DL0cp.jpg

I could really use some help because I am very stuck.

Public Class MainForm
    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Dim salesPerID(5) As Integer
    Dim total As Integer
    Dim sale As Integer

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

        'Loads the ListBox with values and sets index 
        salesIDListBox.Items.Add("101")
        salesIDListBox.Items.Add("112")
        salesIDListBox.Items.Add("203")
        salesIDListBox.Items.Add("301")
        salesIDListBox.Items.Add("302")
        salesIDListBox.SelectedIndex = 0

    End Sub
    Private Sub salesIDListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles salesIDListBox.SelectedIndexChanged

        sale = salesIDListBox.SelectedIndex
        salesTextBox.Text = salesPerID(sale).ToString("C0").


    End Sub

    Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click


        Integer.TryParse(salesTextBox.Text, total)
        salesTextBox.Text = CStr(salesPerID(0))
        salesTextBox.Text = CStr(salesPerID(1))
        salesTextBox.Text = CStr(salesPerID(2))
        salesTextBox.Text = CStr(salesPerID(3))
        salesTextBox.Text = CStr(salesPerID(4))

        For Each sale As Integer In salesPerID
            sale += total
        Next sale


    End Sub
    Private Sub createButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createButton.Click

        totalSalesTextBox.Text = salesPerID(0).ToString("C2")
        totalSalesTextBox.Text = salesPerID(1).ToString("C2")
        totalSalesTextBox.Text = salesPerID(2).ToString("C2")
        totalSalesTextBox.Text = salesPerID(3).ToString("C2")
        totalSalesTextBox.Text = salesPerID(4).ToString("C2")


        totalSalesTextBox.Text = total.ToString("C2")

    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: How can I add values from a TextBox to an Array via an addButton

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9081
  • View blog
  • Posts: 34,127
  • Joined: 12-June 08

Re: How can I add values from a TextBox to an Array via an addButton

Posted 06 February 2012 - 03:22 PM

"I am very stuck."
- How are you stuck? Are you getting an exception? If so what is the text of the exception and what line was it found on? Is something in your project not working as expected? If so what is it doing and what should it be doing? A typical "help us to help you" situation!
Was This Post Helpful? 0
  • +
  • -

#3 eseyee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-February 12

Re: How can I add values from a TextBox to an Array via an addButton

Posted 06 February 2012 - 03:28 PM

There is no exception. I just cannot get anything to display when I use the createButton. I would just appreciate some guidance because I dont know if I am adding to my array correctly or if my createButton does not have the correct code. The image I posted shows how the application should work. Each sales ID should correspond to an input via the salesTextBox and every time the addButton is hit, it should store the values in array. Then the createButton should show each value that was input by the user (via salesTextBox) and their total.
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1048
  • View blog
  • Posts: 4,075
  • Joined: 02-July 08

Re: How can I add values from a TextBox to an Array via an addButton

Posted 06 February 2012 - 03:46 PM

There is a problem here, you are overwriting the data to the textbox so it contains only the last item from the array.

Integer.TryParse(salesTextBox.Text, total)
salesTextBox.Text = CStr(salesPerID(0))
salesTextBox.Text = CStr(salesPerID(1))
salesTextBox.Text = CStr(salesPerID(2))
salesTextBox.Text = CStr(salesPerID(3))
salesTextBox.Text = CStr(salesPerID(4))



Dim total As Integer
If Integer.TryParse(salesTextBox.Text, total)
   'better setup for the TryParse
   'now you can use the total variable in here as it as converted
   'properly
End If


Are you just adding all the vales in the array to the total variable?

This post has been edited by _HAWK_: 06 February 2012 - 03:47 PM

Was This Post Helpful? 1
  • +
  • -

#5 eseyee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-February 12

Re: How can I add values from a TextBox to an Array via an addButton

Posted 06 February 2012 - 04:05 PM

Yes I am. Should I not be adding each value from the array to the total?
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1048
  • View blog
  • Posts: 4,075
  • Joined: 02-July 08

Re: How can I add values from a TextBox to an Array via an addButton

Posted 06 February 2012 - 06:02 PM

If that's what your output needs to be. A simple loop should work.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1