Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Basic Visual Studio TextChange Sub

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses

610 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