Solved

Visual Basic Visual Studio TextChange Sub

Posted on 2007-04-02
1
326 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
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…

808 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