Click here to Skip to main content
14,545,215 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have been working with a program which involves amounts in textboxes, that is for unit price, tax amount as well as total amount. But i'm struggling with to display the currency. In other words i mean the amounts in textboxes must include currency. I have tried some coding even on property settings but with no luck. I attached the tried code he3re.

What I have tried:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
2
    If TextBox1.Text = "" Then
3
        TextBox1.Text = "$"
4
        TextBox1.Selectionstart = 1
5
    End If
6    End Sub
Posted
Updated 5 days ago
Rate this:
Please Sign up or sign in to vote.

Solution 1

This can be done using the ToString[^] method of a numeric value using one of the Currency values within the Standard Numeric Format Strings
   
Comments
Maciej Los 5 days ago
   
5ed!
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can try

Textbox1.Text = FormatCurrency(sum.ToString())
   
Comments
Maciej Los 5 days ago
   
ToString() method is redundant in this case!
Rate this:
Please Sign up or sign in to vote.

Solution 3

If i understand you well, you want to use input mask[^].
I'd suggest to replace TextBox with MaskedTextBox Class (System.Windows.Forms) | Microsoft Docs[^] and provide proper Mask[^]

Quote:



MaskBehavior
$999,999.00A currency value in the range of 0 to 999999. The currency, thousandth, and decimal characters will be replaced at run time with their culture-specific equivalents.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100