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.
megageekgirlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
Whats wrong with using a real masked edit control with the mask ###-###-####


Cheers!

0
megageekgirlAuthor Commented:
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.
0
mcriderCommented:
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!
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

VBGuruCommented:
0
megageekgirlAuthor Commented:
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.
0
mcriderCommented:
Sorry, guess no extra credit...


Cheers!
0
megageekgirlAuthor Commented:
Thanks any way.  I appreciate the help.
0
VBGuruCommented:
Yes, ofcourse! you can do that using that control. Only thing you got to do is,
1. Uncomment the code in UserControl_ReadProperties method
2. In the code replace
change the statement
tempstr = tempstr & "_"     to
tempstr = tempstr & "#"
3. In txtMKDEdit_KeyPres method
chenge statement
txtMKDEdit = strPrevious & "_" & strNext
                      TO
txtMKDEdit = strPrevious & "#" & strNext
4. So tchenge the property "FORMAT" of the control to (ddd)ddd-dddd

The control will just work for you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VBGuruCommented:
Source code of the control should be downloaded from the site I have mentioned.
0
megageekgirlAuthor Commented:
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?
0
megageekgirlAuthor Commented:
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)!
0
VBGuruCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.