Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

character codes? 1

Status
Not open for further replies.

Toastie

Programmer
May 19, 2001
123
AU
can anyone tell me what a "$" = as as chr(x)
also a "," and "." not the one on the keypad
the only reason for this is that there is no vbkey for "," and "."
also i dont know how to use chr(x) yet
cant be too hard
some tips might be usefull

thanks people
 
i should have written that i am trying to check the text that a user enters in a maskedbox
if a user presses $ more than once then msgbox
if a user presses . more than once then msgbox
if a user presses , then exit sub

i have got the . happening but only from the numpad
 
Add the "Microsoft Masked Edit Control" to your project and use that to accept formatted input rather than a standard text box. I'm guessing you are inputting currency values.

-- To add the control to your project --
Click the Project menu
Click on Components
Scroll down to Microsoft Masked Edit Control...
------------------------------------------------

Replace your text box with the Masked Edit control and set the mask property to something like $###,###.##

Help on the Mask property:

--------------------------------------------------
Sloppy solution:

Sub Text1_Change()
Text1.Text = Format(Text1.Text, "Currency")
End Sub
--------------------------------------------------

-Adam-
 
Hi Toastie

You could use ascii values. "$" = 36 "," = 44 "." = 46

Private Sub <Object>_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 44 ' &quot;,&quot;
intA = intA + 1
If intA = 2 Then
MsgBox
intA = 0
End If
Case 46 ' &quot;.&quot;
'code
Case 36 ' &quot;$&quot;
'code
Case Else ' any other keypress
'code
End Select
End Sub

Jon
 
oh it is all getting too hard now
what i want to do is if my mask edit box recieves anything but a number and &quot;.&quot; and &quot;$&quot; and &quot;,&quot;
the &quot;.&quot; and the &quot;$&quot; may only be entered once but the comma can be entered as many times as the user specifies.

the maskedit box can take $1.00 to $999999999
if anyone knows a quick fix for that i will send them the program which calculates tax that is to be witheld by the employer in australia
 
The following bit of code uses the keypress event of a textbox and will stop you entering more than one $ and anything other than numbers and , and .

it does stop you using backspace(asc 8) and enter(asc 13) but you could add code to handle them too.

Private Sub Text1_KeyPress(KeyAscii As Integer)

Dim i As Long

' check if it is outside 48 -> 57 as these are codes for numbers. 46 and 44 are , and .

If (KeyAscii < 48 Or KeyAscii > 57) And (KeyAscii <> 46 And KeyAscii <> 44) Then

' This bit stops more than 1 $
If KeyAscii = 36 Then
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = &quot;$&quot; Then
KeyAscii = 0 ' cancel the keypress
Exit For
End If
Next
Else
KeyAscii = 0 ' cancel the keypress
End If

End If
End Sub


hope this helps!

Mat
 
Have you tried regular expressions to solve this problem. I find that they can be very effective. Scott
Programmer Analyst
 
The following pattern should only allow a dollar format of
$######.##

&quot;^\$[0-9]{1,10}\.[0-9]{2}$&quot;

^\$ = looks for the $ at the beginning of the string
[0-9]{1,10} = only numeric chars
min character 1
max char 10
\. = expects a decimal (.)
[0-9]{2}$ = only numeric
two char allowed/required
Looks for this at the end of the string.

Scott
Programmer Analyst
 
After all i used jon4747 's ascii codes and thats all.
As a wise man once said &quot;There is more than one way to skin a cat.&quot;
I did it my own way because i hate the look of masks and they arent very appealing to the end user.
The maskedbox is for a calculator that calculates tax to be witheld. So the user is going to be using the maskedbox as easy to use as possible.

AND THIS IS WHAT I COME UP WITH.
It works and will support any combination of entry into maskedbox without error. (unless you can find one)
to download the program goto well in about an hour
oh and if you have vb (everyone here does) press &quot;I HAVE GOT THE DRIVERS&quot;

ok here it is


Private Sub MaskEdBox1_Change()
If Len(MaskEdBox1.Text) >= 1 Then
If MaskEdBox1.Text = &quot;$&quot; Then
Exit Sub
ElseIf MaskEdBox1.Text = &quot;.&quot; Then
Exit Sub
ElseIf MaskEdBox1.Text = &quot;$.&quot; Then
Exit Sub
ElseIf Not IsNumeric(MaskEdBox1.Text) Then
MaskEdBox1.Text = Left(MaskEdBox1.Text, Len(MaskEdBox1.Text) - 1)
MaskEdBox1.SelStart = Len(MaskEdBox1.Text)
End If
End If
End Sub
Private Sub check()
If dol >= 2 Then

If Len(MaskEdBox1.Text) >= 2 Then

If Not IsNumeric(MaskEdBox1.Text) Then
MaskEdBox1.Text = Left(MaskEdBox1.Text, Len(MaskEdBox1.Text) - 1)
MaskEdBox1.SelStart = Len(MaskEdBox1.Text)
End If
End If
End If
If dec >= 2 Then

If Len(MaskEdBox1.Text) >= 1 Then

If Not IsNumeric(MaskEdBox1.Text) Then
MaskEdBox1.Text = Left(MaskEdBox1.Text, Len(MaskEdBox1.Text) - 1)
MaskEdBox1.SelStart = Len(MaskEdBox1.Text)
End If
End If
End If
End Sub
Private Sub MaskEdBox1_KeyPress(KeyAscii As Integer)

If KeyAscii = 36 Then

dol = dol + 1

check
End If
If KeyAscii = 46 Then
dec = dec + 1

check
End If
End Sub

Private Sub MaskEdBox1_LostFocus()
dol = 0
dec = 0
End Sub

I sincerely do thank all of those people who helped or even thought of helping.
Glad to be a programmer.

Quote for the year by Toastie &quot;VB programmers are nicer, have more ettiquite and are more willing to help others than C or C++ programmers.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top