|
-
Jul 10th, 2000, 04:54 PM
#1
Thread Starter
Hyperactive Member
Ok here we go......if i have a text box (Text1.text) and its max length is 8 characters.....if someone types 9....how would i get a msgbox to come up on the 9th character?
-RaY
VB .Net 2010 (Ultimate)
-
Jul 10th, 2000, 04:57 PM
#2
Frenzied Member
if the maxlenght is 8 then there is no way that someone could type 9
NXSupport - Your one-stop source for computer help
-
Jul 10th, 2000, 04:59 PM
#3
Thread Starter
Hyperactive Member
Even........
Even if the max length is 8....there is still a keypress even is going on.......anyone gonna help.
-RaY
VB .Net 2010 (Ultimate)
-
Jul 10th, 2000, 05:10 PM
#4
Try this.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'If the key is not Backspace then...
If Not KeyAscii = 8 Then
'Display a MessageBox on the 9th character
If Len(Text1.Text) = 8 Then MsgBox ("No more letters")
End If
End Sub
-
Jul 10th, 2000, 05:11 PM
#5
VB will intercept that 9th keystroke and beep. I don't think you can programatically intercept it without using the API (I'm about 90% sure, Regis!).
If you want a MsgBox to come up on the 9th keystroke, instead of using MaxLength, you could intercept it as it happens in the KeyPress event or after it happens in the Change event. For example:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
' weed out control characters
If KeyAscii < 32 Then Exit Sub
If Len(Text1.Text) = 8 Then
MsgBox "Sorry. Limit is 8."
KeyAscii = 0
End If
End Sub
- or -
Code:
Private Sub Text1_Change
If Len(Text1.Text) > 8 Then
MsgBox "Sorry. Limit is 8."
Text1.Text = Left$(Text1.Text, 8)
End If
End Sub
"It's cold gin time again ..."
Check out my website here.
-
Jul 10th, 2000, 05:14 PM
#6
Member
-
Jul 10th, 2000, 05:33 PM
#7
Addicted Member
Re: Works using vb5
Originally posted by mark_dep
This works for me
put this in general declarations
Dim max As Integer
Then this anywhere
Private Sub Text1_KeyPress(KeyAscii As Integer)
Let max = max + 1
If max > 8 Then
MsgBox "To many letters", vbCritical,"letter Count"
End If
End Sub
Good Luck
Mark_Dep 
but what if they backspace or type over some of the characters? You'd want the backspace to at least decrease the max variable, and you'd have to consider that the text box could possibly contain characters to begin with.
-
Jul 11th, 2000, 08:09 AM
#8
Thread Starter
Hyperactive Member
Thanks for the help
I would try your suggesions when I get off work, I appreciate the replies!
-RaY
VB .Net 2010 (Ultimate)
-
Jul 11th, 2000, 09:00 AM
#9
Thread Starter
Hyperactive Member
Works
Megatron it works like a charm! Thanks guys!
-RaY
VB .Net 2010 (Ultimate)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|