A Better Way for Select

D

DS

I have this Select Case statement that works but I was wondering if
there is a better way to code this. I have ten of these on a number
pad, one for each number 0 to 9,
It takes the first number and places it in a phone format (000)-000-0000
in the first digit as such (100)-000-0000
Then takes the second number and places it as such (110)-000-0000
So on and so forth.
After it places the final digit it stops any further input.

Any suggestions welcome.
Thank You
DS

Select Case Me.TxtCount
Case 10
Case Else
Me.TxtHidden = Me.TxtHidden & 1
Me.TxtCount = Len(Me.TxtHidden.Value)

Dim strX As String
Select Case Me.TxtCount
Case 1
strX = TxtHidden.Value & "000000000"
Case 2
strX = TxtHidden.Value & "00000000"
Case 3
strX = TxtHidden.Value & "0000000"
Case 4
strX = TxtHidden.Value & "000000"
Case 5
strX = TxtHidden.Value & "00000"
Case 6
strX = TxtHidden.Value & "0000"
Case 7
strX = TxtHidden.Value & "000"
Case 8
strX = TxtHidden.Value & "00"
Case 9
strX = TxtHidden.Value & "0"
Case 10
strX = TxtHidden.Value
'Case Else
' MsgBox "Stop"
End Select
Me.LblDisplay.Caption = Format(strX, "(000)-000-0000")
End Select
 
T

tina

*instead of* your current code setup, try adding the following code to the
form's module, as

Dim strA As String

Public Function isNumber(ByVal num As String)

Const strzeros As String = "0000000000"
Const byt As Byte = 10

If Len(strA) = byt Then Exit Function
strA = strA & num
Me!LblDisplay.Caption = Format(strA & Left(strzeros, _
byt - (Len(strA))), "(000)-000-0000")

End Function

make sure that the Dim statement is above all procedures in the module.

add the following function call directly to the Click event property line of
each button on your number "pad", as

=isNumber(1)

make sure you include the equal (=) sign, and set the number in parentheses
to match the number on the button (1) for button "1", (2) for button "2",
etc.

having given you the above setup, i have to ask: do you really make your
users click these command buttons one by one to enter a phone number,
instead of just letting them type the number into a control - which would be
so much faster and easier?

hth
 
D

DS

tina said:
*instead of* your current code setup, try adding the following code to the
form's module, as

Dim strA As String

Public Function isNumber(ByVal num As String)

Const strzeros As String = "0000000000"
Const byt As Byte = 10

If Len(strA) = byt Then Exit Function
strA = strA & num
Me!LblDisplay.Caption = Format(strA & Left(strzeros, _
byt - (Len(strA))), "(000)-000-0000")

End Function

make sure that the Dim statement is above all procedures in the module.

add the following function call directly to the Click event property line of
each button on your number "pad", as

=isNumber(1)

make sure you include the equal (=) sign, and set the number in parentheses
to match the number on the button (1) for button "1", (2) for button "2",
etc.

having given you the above setup, i have to ask: do you really make your
users click these command buttons one by one to enter a phone number,
instead of just letting them type the number into a control - which would be
so much faster and easier?

hth
Thanks, Its almost there. ****The only problem is that it keeps
replacing the first number and doesn't add any others.*** The user has
to use a Pad since hey don't have a keyboard and are using a touch screen.
Once again, Thank You
DS
 
D

DS

DS said:
Thanks, Its almost there. ****The only problem is that it keeps
replacing the first number and doesn't add any others.*** The user has
to use a Pad since hey don't have a keyboard and are using a touch screen.
Once again, Thank You
DS
I removed the = Sign and it works fine now. BTW how do you clear the
LblDisplay? I tried (000)-000-0000 but that really doesn't work. ay
other suggestions appreciated.
Thanks
DS
 
T

tina

if removing the = sign worked, then i'm guessing that you're calling the
function from each command button's Click event *procedure*, not directly
from the Click event property line. that will certainly work just as well;
it's just quicker to set up the code if you type the function directly on
the property line in the Properties box, using the = sign. that's why i
wrote a function instead of a sub, because only functions can be called in
that manner.

hth
 
D

DS

tina said:
if removing the = sign worked, then i'm guessing that you're calling the
function from each command button's Click event *procedure*, not directly
from the Click event property line. that will certainly work just as well;
it's just quicker to set up the code if you type the function directly on
the property line in the Properties box, using the = sign. that's why i
wrote a function instead of a sub, because only functions can be called in
that manner.

hth
Thanks, I appreciate the tutorial. Something I never realised!
So I'mstill having problems with the clearing of the label...
I tried...Me.LabelDisplay="" but the label disappears and the when I
start inputing again it show back up with the old values still in tact,
Thank You
DS
 
D

DS

DS said:
Thanks, I appreciate the tutorial. Something I never realised!
So I'mstill having problems with the clearing of the label...
I tried...Me.LabelDisplay="" but the label disappears and the when I
start inputing again it show back up with the old values still in tact,
Thank You
DS
I also tried this
strA.Close
And this
Set strA = Nothing
Only by closing the form can I clear the LblDisplay and have it read
(000)-000-0000 once again.

Thanks
DS
 
T

tina

oh, sorry. i answered specifically about the label, not thinking about the
variable. as a module level variable, strA will retain its' value until the
form closes, unless you explicitly change that value in VBA, as

strA = ""

btw, the Close and set to Nothing code didn't work because strA is not an
object variable - it's a simple string variable.

hth
 
D

DS

tina said:
oh, sorry. i answered specifically about the label, not thinking about the
variable. as a module level variable, strA will retain its' value until the
form closes, unless you explicitly change that value in VBA, as

strA = ""

btw, the Close and set to Nothing code didn't work because strA is not an
object variable - it's a simple string variable.

hth
Wow great thanks! This has been a valuable learning experience! BTW
that works. In he meantime I also worked out a scenerio to delete one
at a time.

Me.TxtCount = Len(Me.TxtHidden.Value)
Dim strX As String
Select Case Me.TxtCount
Case 1
Me.TxtHidden = Left(Me.TxtHidden.Value, 0)
strX = Me.TxtHidden.Value & "0000000000"
Case 2
Me.TxtHidden = Left(Me.TxtHidden.Value, 1)
strX = Me.TxtHidden.Value & "000000000"
Case 3
Me.TxtHidden = Left(Me.TxtHidden.Value, 2)
strX = Me.TxtHidden.Value & "00000000"
Case 4
Me.TxtHidden = Left(Me.TxtHidden.Value, 3)
strX = Me.TxtHidden.Value & "0000000"
Case 5
Me.TxtHidden = Left(Me.TxtHidden.Value, 4)
strX = Me.TxtHidden.Value & "000000"
Case 6
Me.TxtHidden = Left(Me.TxtHidden.Value, 5)
strX = Me.TxtHidden.Value & "00000"
Case 7
Me.TxtHidden = Left(Me.TxtHidden.Value, 6)
strX = Me.TxtHidden.Value & "0000"
Case 8
Me.TxtHidden = Left(Me.TxtHidden.Value, 7)
strX = Me.TxtHidden.Value & "000"
Case 9
Me.TxtHidden = Left(Me.TxtHidden.Value, 8)
strX = Me.TxtHidden.Value & "00"
Case 10
Me.TxtHidden = Left(Me.TxtHidden.Value, 9)
strX = Me.TxtHidden.Value & "0"
'Case Else
' MsgBox "Stop"
End Select
Me.LblDisplay.Caption = Format(strX, "(000)-000-0000")
Once again Thank You!
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top