Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 25-May-20 22:22pm

This can be done using the ToString[^] method of a numeric value using one of the Currency values within the Standard Numeric Format Strings
 
Share this answer
 
Comments
Maciej Los 26-May-20 3:59am    
5ed!
You can try

VB
Textbox1.Text = FormatCurrency(sum.ToString())
 
Share this answer
 
Comments
Maciej Los 26-May-20 4:00am    
ToString() method is redundant in this case!
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900