Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27215

VS 2010 allowedChars As String = ""

$
0
0
I am new to this forum so Hello! :)

Also, I am new to VB and I have problem with setting up the limit in text box. I am using two text boxes, one of them has a limit between 2 and 6 so other numbers like 7 cannot be inserted. My second text box has a limit between 1 and 25. For first text box I am using this code:

Code:

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

        Dim allowedChars As String = "23456"
        If e.KeyChar <> ControlChars.Back Then
            If allowedChars.IndexOf(e.KeyChar) = -1 Then
                MsgBox("Value must be between 2 and 6 ")
                e.Handled = True
            End If
        End If
    End Sub

I want the same code for second text box but with limit between 1 and 25 so e.g. 26 cannot be inserted. I tried Dim allowedChars As String = "123456...25" but it allows me to insert e.g. 26 and so on. Is there any way to limit my text box while using this code but it won't accept e.g. 26.

Thanks a lot
Dzak

Viewing all articles
Browse latest Browse all 27215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>