Page 2 of 2 FirstFirst 12
Results 41 to 54 of 54

Thread: Need help with listbox texts to have a value and add onto another textbox

  1. #41

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    32

    Re: Need help with listbox texts to have a value and add onto another textbox

    Quote Originally Posted by .paul. View Post
    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
    
    End Sub
    Error - Type 'CultureInfo" is not defined.

  2. #42
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Need help with listbox texts to have a value and add onto another textbox

    Code:
    Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB")

  3. #43

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    32

    Re: Need help with listbox texts to have a value and add onto another textbox

    Quote Originally Posted by .paul. View Post
    Code:
    Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB")
    awesome that made into pounds, the two other questions that remain are as follows. There's a checkbox that when selected itll add 50 pounds to the total which it did but then the pound symbol disappears and the second question is that, theres a textbox2 that calculates a discount basically if the total value is over 200 pounds itll deduce 10% from the total and put it on the textbox3 which is labeled as New total

    Code:
            If CheckBox1.Checked = True Then
                TextBox1.Text = total.ToString("c2") + 50

  4. #44
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Need help with listbox texts to have a value and add onto another textbox

    Where do you put the original total code?

  5. #45
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Need help with listbox texts to have a value and add onto another textbox

    The reason I ask is that between the end of the loops and setting textbox1.text you can use an if statement where you add 50 to total if your checkbox is checked. Then after setting textbox.text, use another if statement for your case where total >= 200 to calculate and display a discounted price in textbox3 in the same way I showed you with textbox1

  6. #46

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    32

    Re: Need help with listbox texts to have a value and add onto another textbox

    Quote Originally Posted by .paul. View Post
    The reason I ask is that between the end of the loops and setting textbox1.text you can use an if statement where you add 50 to total if your checkbox is checked. Then after setting textbox.text, use another if statement for your case where total >= 200 to calculate and display a discounted price in textbox3 in the same way I showed you with textbox1
    Code:
    Private Sub purbtn_Click(sender As Object, e As EventArgs) Handles purbtn.Click
            Dim prices1(0) As Integer
            Dim prices2(4) As Integer
            prices1(0) = 10
            prices2(0) = 11
            prices2(1) = 15
            prices2(2) = 20
            prices2(3) = 50
            prices2(4) = 90
    
            Dim allPrices(1)() As Integer
            allPrices(0) = prices1
            allPrices(1) = prices2
    
            Dim listBoxes() As ListBox = {ListBox1, ListBox2}
            Dim total As Integer = 0
    
            For x As Integer = 0 To listBoxes.GetUpperBound(0)
                For y As Integer = 0 To listBoxes(x).Items.Count - 1
                    If listBoxes(x).SelectedIndices.Contains(y) Then
                        total += allPrices(x)(y)
                    End If
                Next
            Next
    
            TextBox1.Text = total.ToString("c2")
    
            If CheckBox1.Checked = True Then
                TextBox1.Text = total.ToString("c2") + 50
            End If
    
            If TextBox1.Text = total.ToString("c2") Then
                TextBox3.Text = total.ToString("c2")
            End If
    
            If TextBox1.Text = total.ToString("c2") + 50 Then
                TextBox3.Text = total.ToString("c2") + 50
            End If

  7. #47
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Need help with listbox texts to have a value and add onto another textbox

    Code:
    If CheckBox1.Checked = True Then
        total += 50
    End If
    
    TextBox1.Text = total.ToString("c2")
    
    If total >= 200 then
        Dim discountedTotal As Decimal = CDec(total * 0.9)
        TextBox3.Text = discountedTotal.ToString("c2")
    End If

  8. #48
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Need help with listbox texts to have a value and add onto another textbox

    Your new homework is to figure out where to put that last code, and tell me why it works…

  9. #49

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    32

    Re: Need help with listbox texts to have a value and add onto another textbox

    Quote Originally Posted by .paul. View Post
    Code:
    If CheckBox1.Checked = True Then
        total += 50
    End If
    
    TextBox1.Text = total.ToString("c2")
    
    If total >= 200 then
        Dim discountedTotal As Decimal = CDec(total * 0.9)
        TextBox3.Text = discountedTotal.ToString("c2")
    End If
    youre an angel sent from above

    Code:
    Private Sub purbtn_Click(sender As Object, e As EventArgs) Handles purbtn.Click
            'declaring that the prices are numbers and that there is 5 of them
            Dim prices1(0) As Integer
            Dim prices2(4) As Integer
            prices1(0) = 10
            prices2(0) = 11
            prices2(1) = 15
            prices2(2) = 20
            prices2(3) = 50
            prices2(4) = 90
    
            Dim allPrices(1)() As Integer
            allPrices(0) = prices1
            allPrices(1) = prices2
    
            Dim listBoxes() As ListBox = {ListBox1, ListBox2}
            Dim total As Integer = 0
            'making sure they all add up properly in a specified text box based on which one was highlighted
            For x As Integer = 0 To listBoxes.GetUpperBound(0)
                For y As Integer = 0 To listBoxes(x).Items.Count - 1
                    If listBoxes(x).SelectedIndices.Contains(y) Then
                        total += allPrices(x)(y)
                    End If
                Next
            Next
            'declaring that ticking that will add 50 pounds to the total
            If CheckBox1.Checked = True Then
                total += 50
            End If
            TextBox1.Text = total.ToString("c2")
    
    
            If total >= 200 Then
                Dim discountedTotal As Decimal = CDec(total * 0.9)
                TextBox3.Text = discountedTotal.ToString("c2")
            End If
    i did it but when i uncheck it, it doesnt go away and the value of the discount is not shown in the textbox2.text

  10. #50
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Need help with listbox texts to have a value and add onto another textbox

    Code:
    Private Sub calculateTotals
            'declaring that the prices are numbers and that there is 5 of them
            Dim prices1(0) As Integer
            Dim prices2(4) As Integer
            prices1(0) = 10
            prices2(0) = 11
            prices2(1) = 15
            prices2(2) = 20
            prices2(3) = 50
            prices2(4) = 90
    
            Dim allPrices(1)() As Integer
            allPrices(0) = prices1
            allPrices(1) = prices2
    
            Dim listBoxes() As ListBox = {ListBox1, ListBox2}
            Dim total As Integer = 0
            'making sure they all add up properly in a specified text box based on which one was highlighted
            For x As Integer = 0 To listBoxes.GetUpperBound(0)
                For y As Integer = 0 To listBoxes(x).Items.Count - 1
                    If listBoxes(x).SelectedIndices.Contains(y) Then
                        total += allPrices(x)(y)
                    End If
                Next
            Next
            'declaring that ticking that will add 50 pounds to the total
            If CheckBox1.Checked = True Then
                total += 50
            End If
            TextBox1.Text = total.ToString("c2")
    
    
            If total >= 200 Then
                Dim discountedTotal As Decimal = CDec(total * 0.9)
                TextBox3.Text = discountedTotal.ToString("c2")
            End If
    End Sub
    Code:
    Private Sub purbtn_Click(sender As Object, e As EventArgs) Handles purbtn.Click
        CalculateTotals
    End Sub
    Code:
    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        CalculateTotals
    End Sub
    Honestly, you’d better know why this homework does what it does, because if your teacher asks you to explain it…

  11. #51

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    32

    Re: Need help with listbox texts to have a value and add onto another textbox

    Quote Originally Posted by .paul. View Post
    Code:
    Private Sub calculateTotals
            'declaring that the prices are numbers and that there is 5 of them
            Dim prices1(0) As Integer
            Dim prices2(4) As Integer
            prices1(0) = 10
            prices2(0) = 11
            prices2(1) = 15
            prices2(2) = 20
            prices2(3) = 50
            prices2(4) = 90
    
            Dim allPrices(1)() As Integer
            allPrices(0) = prices1
            allPrices(1) = prices2
    
            Dim listBoxes() As ListBox = {ListBox1, ListBox2}
            Dim total As Integer = 0
            'making sure they all add up properly in a specified text box based on which one was highlighted
            For x As Integer = 0 To listBoxes.GetUpperBound(0)
                For y As Integer = 0 To listBoxes(x).Items.Count - 1
                    If listBoxes(x).SelectedIndices.Contains(y) Then
                        total += allPrices(x)(y)
                    End If
                Next
            Next
            'declaring that ticking that will add 50 pounds to the total
            If CheckBox1.Checked = True Then
                total += 50
            End If
            TextBox1.Text = total.ToString("c2")
    
    
            If total >= 200 Then
                Dim discountedTotal As Decimal = CDec(total * 0.9)
                TextBox3.Text = discountedTotal.ToString("c2")
            End If
    End Sub
    Code:
    Private Sub purbtn_Click(sender As Object, e As EventArgs) Handles purbtn.Click
        CalculateTotals
    End Sub
    Code:
    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        CalculateTotals
    End Sub
    Honestly, you’d better know why this homework does what it does, because if your teacher asks you to explain it…
    I understand that but now values are not showing in textbox3.text until the value of textbox1.text is over 200, the discounts in textbox2.text is not being shown either and when the checkbox1.checked = false, the amount is not substracted back from the new total in textbox3.text

  12. #52
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Need help with listbox texts to have a value and add onto another textbox

    You told me…
    textbox1 is the sum from the listBoxes
    TextBox3 is the discounted total
    and Textbox2 you haven’t previously mentioned

    Anyway. Everything I told you will work. I’m logging off now it’s 03:40 and I have to sleep…

  13. #53

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    32

    Re: Need help with listbox texts to have a value and add onto another textbox

    Quote Originally Posted by .paul. View Post
    You told me…
    textbox1 is the sum from the listBoxes
    TextBox3 is the discounted total
    and Textbox2 you haven’t previously mentioned

    Anyway. Everything I told you will work. I’m logging off now it’s 03:40 and I have to sleep…
    i don't know how to thank you enough! thanks for for everything

  14. #54

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    32

    Re: Need help with listbox texts to have a value and add onto another textbox

    Quote Originally Posted by .paul. View Post
    You told me…
    textbox1 is the sum from the listBoxes
    TextBox3 is the discounted total
    and Textbox2 you haven’t previously mentioned

    Anyway. Everything I told you will work. I’m logging off now it’s 03:40 and I have to sleep…
    I will literally pray for you, thank you so much you guys! i solved it and wish i could show you <33333 thank you thank you thank you

Page 2 of 2 FirstFirst 12

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