?
Solved

Visual Basic Visual Studio TextChange Sub

Posted on 2007-04-02
1
Medium Priority
?
351 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month16 days, 16 hours left to enroll

864 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