0

Hello Everyone Good Afternoon. I Hope Someone Helps me with my Problem.

I have 3 Textboxes and they are:

GrandTotal.Text
VatAmount.Text
TotalAmount.Text

and 1 NumericUpdown1.Value

Here is the Scenario, As the system goes, there is a code that will trigger and Will put a Number value in GrandTotal.Text and after that, The User will press NumericUpdown1.Value. Every time the user press it A computation will be triggered and a Number value will be Displayed in TotalAmount.Text and VatAmount.Text

To Make it more specific it is like a computation form that will include VAT. For Example.

Grandtotal.text = 2000

and if I press the NumericUpDown to + 1

VatAmount.Text = 20 and TotalAmount.Text = 2020

I hope you get what I mean

and Here is my code for It:

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
VatAmount.Text = Val(Grandtotal.text) * NumericUpDown1.Value * 0.01
End Sub



Private Sub VatAmount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VatAmount.TextChanged
        TotalAmount.Text = Val(VatAmount.Text) + Val(TextBox14.Text)
    End Sub

Now I`m done Explaining it here is My Question.

How to put Commas on that Textboxes and Compute It? My Prof. asked that He wants to put commas on the numbers that will bi inputted? No need to literally put Commas. Put it Automatically when value is greater that 3 Digits

How can I put commas in Textboxes and Compute it using the NumericUpdown?

TYSM

  • A `TextBox` simply displays a `String`. If you want a `TextBox` to display a `String` with commas in it then put commas in the `String` before displaying it. If you don't know how to concatenate multiple substrings then I suggest that you review your notes or check out a beginners tutorial online because that's a pretty fundamental concept. – jmcilhinney May 17 '16 at 06:53
  • Have you tried this? http://stackoverflow.com/a/19999643/6144259 – A Friend May 17 '16 at 08:10
  • Here is my code Sir ` Dim dblValue As Double = TextBox14.Text TextBox14.Text = dblValue.ToString("N", CultureInfo.InvariantCulture)` and I put it in Textchange but when I type the number the textbox dont accept 0 –  May 17 '16 at 08:24
  • You missed the 0 from the first parameter of `toString()`. It should be "N0", not just "N" – A Friend May 17 '16 at 08:37

1 Answers1

0

This is roughly what you need:

Private Sub GrandTotal_TextChanged(sender As Object, e As EventArgs) Handles GrandTotal.TextChanged
    Dim input As Double = Double.Parse(GrandTotal.Text)
    Dim inputStringWithCommas As String = input.ToString("N0", CultureInfo.InvariantCulture)
    GrandTotal.Text = inputStringWithCommas

    Dim vat As Double = Double.Parse(GrandTotal.Text) * NumericUpDown1.Value * 0.01
    VatAmount.Text = vat.ToString()
    TotalAmount.Text = (Double.Parse(GrandTotal.Text) + vat).ToString("N0", CultureInfo.InvariantCulture)
End Sub

It is similar to what you have, so you should be able to make it work for the NumericUpDown event as well.

A Friend
  • 2,750
  • 2
  • 14
  • 23
  • TYSM Again Sir, Ahmm Sir I have a very little problem, I have the code now of summing up the number in a column but there`s a decimal point there like 2,200.50 the total is rounding up. How can I prevent from rounding up. –  May 18 '16 at 08:11
  • If that .50 is not relevant then there are a few ways to get rid of it. You could convert to integer or perform a truncate on the total before putting it back into text. Alternatively you could use a string split on the text before assigning it to the value of the textbox.. – A Friend May 18 '16 at 12:54