1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Visual Studio 2008

Discussion in 'Software Development' started by sushildamle, Dec 18, 2011.

Thread Status:
Not open for further replies.
  1. sushildamle

    sushildamle Thread Starter

    Joined:
    Dec 18, 2011
    Messages:
    1
    Currently, I have a textbox in which I propose to enter on numbers / digits.
    I would like to restrict the user input to be only a range of numbers between 0-125.
    The examples I found in this are working excellent in earlier versions of Visual Basic, but I am trying to use the same in Visual Basic 2008.
    How do I go about this? Kindly guide me in this context.
     
  2. Ent

    Ent Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,467
    First Name:
    Josiah
    Sorry for the delay in responding. If it's still relevant, here's my take on the issue.

    I would suggest that you look at using Masked Text boxes rather than plain old text boxes. as they could quite easily restrict your entry to numbers (which is half the battle). After that I'd have a check whenever the text of that box is changed, using something like the following:

    Code:
        Dim TB1Text As String = ""
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            Dim CheckValue As Integer
            If Integer.TryParse(TextBox1.Text, CheckValue) Then
                If CheckValue > 125 Then
                    TextBox1.Text = TB1Text
                Else
                    TB1Text = TextBox1.Text
                End If
            Else
                TextBox1.Text = TB1Text
            End If
        End Sub
    
    That keeps the previous contents of the text box in a string, and changes it back to that string if the input is either non-numeric or too large. Im sure it's possible to make it more efficient, but it illustrates the point.
     
  3. rjean99

    rjean99

    Joined:
    Jan 4, 2012
    Messages:
    1
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1031774

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice