[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Make my own masked edit control

Posted on 1999-12-13
13
Medium Priority
?
163 Views
Last Modified: 2010-08-05
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.
0
Comment
Question by:megageekgirl
  • 5
  • 5
  • 3
13 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2278902
Whats wrong with using a real masked edit control with the mask ###-###-####


Cheers!

0
 

Author Comment

by:megageekgirl
ID: 2278908
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2278953
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 6

Expert Comment

by:VBGuru
ID: 2278996
0
 

Author Comment

by:megageekgirl
ID: 2279015
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2279040
Sorry, guess no extra credit...


Cheers!
0
 

Author Comment

by:megageekgirl
ID: 2279042
Thanks any way.  I appreciate the help.
0
 
LVL 6

Accepted Solution

by:
VBGuru earned 150 total points
ID: 2279051
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
 
LVL 6

Expert Comment

by:VBGuru
ID: 2279055
Source code of the control should be downloaded from the site I have mentioned.
0
 

Author Comment

by:megageekgirl
ID: 2279073
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
 
LVL 6

Expert Comment

by:VBGuru
ID: 2279106
0
 

Author Comment

by:megageekgirl
ID: 2279114
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
 
LVL 6

Expert Comment

by:VBGuru
ID: 2279136
welcome
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question