Solved

Visual Basic Visual Studio TextChange Sub

Posted on 2007-04-02
1
312 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
1 Comment
 
LVL 25

Accepted Solution

by:
SStory earned 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now