Help

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
iPol
Just Registered
Just Registered
Posts: 6
Joined: Wed Jan 05, 2011 6:09 pm

Help
iPol
I need to know how to make a textbox able to enter any digit between 1-25 but nothing else. I mean how do I disable like anything above 25, I am bad at putting things into words, but hopefully you know what I mean, Thanks.
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Re: Help
Agust1337
Hello ipol,
Click the textbox on your form, and to the properties, and find something called MaxLenght put it to 25, as shown on the image below.
Capture.PNG
Then if you want the user to not be able to write alphabetical characters, use this:
Code: Select all
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "1111122222333334444455555" Then
            MsgBox("valid key!")
        Else
            MsgBox("invalid key!")
        End If
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar <> ChrW(Keys.Back) Then
            If (e.KeyChar.ToString >= "0" And e.KeyChar.ToString <= "9") Then
            Else
                e.Handled = True
            End If
        End If
    End Sub
You do not have the required permissions to view the files attached to this post.
Top-notch casual Dating
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Help
mandai
It is not clear how you would limit the number range with that code.

You can use this:
Code: Select all
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Dim number As Integer

        Try
            number = Integer.Parse(TextBox1.Text)
        Catch ex As Exception
            TextBox1.Text = ""
            Return
        End Try

        If number < 1 Or number > 25 Then
            MsgBox("Number is not allowed")
            TextBox1.Text = ""
        End If
    End Sub
User avatar
iPol
Just Registered
Just Registered
Posts: 6
Joined: Wed Jan 05, 2011 6:09 pm

Re: Help
iPol
Thank you.
4 posts Page 1 of 1
Return to “Tutorial Requests”