Paul Edward SanGabriel Pagente Paul Edward SanGabriel Pagente - 5 months ago 17x Question

Formatting and Computing Numbers in Textbox VB.Net

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

I have 3 Textboxes and they are:


and 1

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

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

= 20 and
= 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?



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.