megageekgirl
asked on
Make my own masked edit control
I need to know how to make my own masked edit control for a phone number. The code that I have written is buggy to say the least. Any help would be appreciated.
ASKER
Believe me I would love to, but it is an extra credit assignment and I just can't get my code to work right. Do you have some code suggestions.
Well, you could do something like this:
1) Add 3 textboxes to a new form... Call them Ttext1(0) Text1(1) and Text1(2)
2) Put the 3 textboxes side by side.
3) Add the following code to the DECLARATIONS SECTION of the form:
Private Sub Form_Load()
Text1(0).MaxLength = 3
Text1(1).MaxLength = 3
Text1(2).MaxLength = 4
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
On Error Resume Next
Select Case KeyAscii
Case 48 To 57
Case 8
If Text1(Index).SelStart = 0 Then
Text1(Index - 1).SetFocus
If Err = 0 Then
Text1(Index - 1) = Left$(Text1(Index - 1).Text, Len(Text1(Index - 1).Text) - 1)
Text1(Index - 1).SelStart = Len(Text1(Index - 1).Text)
End If
End If
Exit Sub
Case Else
KeyAscii = ""
End Select
If Text1(Index).MaxLength - 1 = Len(Text1(Index).Text) Then
Text1(Index + 1).SetFocus
End If
End Sub
Have Fun!
Cheers!
1) Add 3 textboxes to a new form... Call them Ttext1(0) Text1(1) and Text1(2)
2) Put the 3 textboxes side by side.
3) Add the following code to the DECLARATIONS SECTION of the form:
Private Sub Form_Load()
Text1(0).MaxLength = 3
Text1(1).MaxLength = 3
Text1(2).MaxLength = 4
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
On Error Resume Next
Select Case KeyAscii
Case 48 To 57
Case 8
If Text1(Index).SelStart = 0 Then
Text1(Index - 1).SetFocus
If Err = 0 Then
Text1(Index - 1) = Left$(Text1(Index - 1).Text, Len(Text1(Index - 1).Text) - 1)
Text1(Index - 1).SelStart = Len(Text1(Index - 1).Text)
End If
End If
Exit Sub
Case Else
KeyAscii = ""
End Select
If Text1(Index).MaxLength - 1 = Len(Text1(Index).Text) Then
Text1(Index + 1).SetFocus
End If
End Sub
Have Fun!
Cheers!
check out
http://www.geocities.com/vb4developer
http://www.geocities.com/vb4developer
ASKER
I don't think that this will give the desired effect. Want a mask to actually show up in the textbox like (###) ###-####, then have the input replace only the #. Backspace must work the erase the input but not the (,), and -.
Thanks anyway. It has turned out to be harder than it looked.
Thanks anyway. It has turned out to be harder than it looked.
Sorry, guess no extra credit...
Cheers!
Cheers!
ASKER
Thanks any way. I appreciate the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Source code of the control should be downloaded from the site I have mentioned.
ASKER
I am having trouble getting the page to load. Geocities keeps telling me it is unavailable. Will keep trying. Do you know the name of the source code that I am looking for?
ASKER
Got it. Thank you so much. You have been wonderful. Maybe I can return the favor sometime.
Have a great day or night(as the case may be)!
Have a great day or night(as the case may be)!
welcome
Cheers!