It seems like the maskedtextbox would be able to handle this type of input without using the keypress events to alter the text. NET Video Tutorials | Login Form using backend database (. NET | Encrypt/Decrypt data in SQL Server 2005 using SQL statements | Writing Managed Stored Procedures in SQL Server 2005 | FREE . NET using Visual Basic 2010 Express.) If the user manually entered a "$" into the textbox there an unhandled exception would result.A+, DCSE, e-Biz+, i-Net+, MCDST, MCP, Network+, Security+, A. NET Calendar Control | Useful Win Form Controls | Regular Expression (Regex) Library | Backup/Restore SQL Server 2005 Database using code | Verify SQL Server 2005 database backup using SMO | Backup SQL Server 2005 database using SMO | Restore SQL Server 2005 database using SMO | Use Fx Cop from Microsoft to aid with code optimization The Masked Text Box is not a panacea because it requires a fixed length mask. Just use a Numberic Up Down with the Decimal Places property set to 2 or a regular Text Box and validate it for currency: 2007-2016 Why is my data not saved to my database? " Videos: VB | C# VBForums Database Development FAQ My Code Bank Submissions: VB | C# My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control Beginner Tutorials: VB | C# | SQL I found the above code by jmcilhinney to be very helpful. I eventually fixed this by adding one line of code into the Sub Textbox1_Validating(...). Controls Clear Text Box(ctrl) If Type Of ctrl Is Text Box Then CType(ctrl, Text Box). Empty End If Next ctrl End Sub Private Sub Button2_Click(By Val sender As System.
It will allow the user to include or omit the currency symbol in the data, reformatting the text correctly when the control loses focus regardless.
Does anyone know how to set the maskedtextbox to a currency format that actually works?
I have set the mask to $999,999.00 but the user input looks like this $120,0__.__ instead of this $___._12.00.
By Dan Mabbutt While working on a program recently, I needed to guarantee that some text input contained only numbers. Visible = False End Sub This works better and it's shorter.
(The app required the user to enter a numeric serial number.) I bingled the web for a while to see if anyone had any better ideas about how to do it than I did and I discovered (Yet again!! This article covers the common recommendations and then the one I recommend. But if you're going to do it this way, why not use the technology invented to do it: Regular Expressions.