Results 1 to 2 of 2

Thread: Vb2010 Listbox question

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    2

    Vb2010 Listbox question

    ok so i am using vb2010 and I have created two listboxes and a textbox and a button. the first list box has a my list in it like seen below:

    U-Ad ($350)
    Striker ($190)
    New Ad ($250)
    Samson ($530)

    as you select one of these list items in the first box and click the button it adds that item to the second listbox. Then the textbox is being used to add the monetary value of the items to a total of the ones you have selected. textbox updates as you add more from the first listbox to the second. I cannot figure out what code to write to have the values add up in the textbox? any help?

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Vb2010 Listbox question

    Try this
    Code:
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ListBox1.Items.Add("U-Ad ($350)")
            ListBox1.Items.Add("Striker ($190)")
            ListBox1.Items.Add("New Ad ($250)")
            ListBox1.Items.Add("Samson ($530)")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim v As Decimal
    
            ListBox2.Items.Add(ListBox1.SelectedItem)
            Decimal.TryParse(TextBox1.Text, v)
    
            v += GetMoney(ListBox1.SelectedItem)
            TextBox1.Text = v.ToString
        End Sub
    
        Private Function GetMoney(ByVal strValue As String) As Decimal
            Dim a As Integer = strValue.IndexOf("($")
            Dim b As Integer = strValue.IndexOf(")")
            Dim v As String = strValue.Substring(a + 2, b - a - 2)
            Dim r As Decimal
    
            Decimal.TryParse(v, r)
    
            Return r
        End Function
    End Class



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width