?
Solved

Visual Basic Visual Studio TextChange Sub

Posted on 2007-04-02
1
Medium Priority
?
338 Views
Last Modified: 2013-11-06
Have Code Below, Trying to have it insert a comma every third number

 Private Sub physicalroomstxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles physicalroomstxt.TextChanged


        Dim TextValue As String = physicalroomstxt.Text.Trim()
        If Not Regex.IsMatch(TextValue, "^[-\+]?(?:\d{1,3}|\d{1,3},\d{1,3}|\d{1,2},\d{1,3},\d{1,3})$") Then     MessageBox.Show("Value must be numeric" & vbCrLf & _
                "")
            Me.physicalroomstxt.Text = "0"
     End If

    End Sub

But when it gets to past the third number the message box displays its "Value must be numeric"
Thanks JK
0
Comment
Question by:fsuedu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
SStory earned 2000 total points
ID: 18838426
There's always the format function
Format("###,###,###,###,###,###,0",TextValue)

The ### may be on the right side instead of left (I'm doing this from memory).  Anyhow, this formats a string with 1000's separators.  Be aware that I think that by changing the value of a text box from within the textbox change text event you may refire that event in the process.  You may need a flag to set while changing that ignores immediate changetext events until after it is changed.

Another possibility is the MaskedEditControl--I can't remember if it allows commas in the mask or not.
The Format command would be the simplest.  # means can have a digit but not required. 0 means must have a digit here.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question