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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i block alpha characters in my text box?

Status
Not open for further replies.

ParkerWrecker

Programmer
Nov 13, 2003
18
PH
the only characters i wanted to be inputed in my text box are numeric, and is it possible that if i have already entered 3 characters on that text box, the focus will automatically move into the other text box? how? thanks!
 
Use the keypress event. Check the value and set keyascii = 0 if it is non-numeric.

Can use len on the field to be = 2 to set the focus to the next field.

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
as what ive known calling keyascii as 0 means disabling all the possible input chars from d keyboard right...is there something else... or maybe i just didn't understand what ur trying to say..... : ( help please....?
 
the numeric keys all have a "keyascii" value. Put the line "msgbox keyascii" in the keypress routine of your textbox then hit the keys to find out their numbers. Then put in the code:

if keyascii < ##1 or keyascii > ##2 then
keyascii=0
endif

where ##1 is the lowest keyascii value and ##2 is the highest ( i believe they run in sequence )
 
you also want to put in a routine for textbox_change, because as discussed in an earlier thread yesterday, the user can copy and paste whatever they want into your textbox.

Using the onchange procedure, you can then iterate through the pasted text, and remove any char that is not numeric.

dim tex_cont as string

for i=1 to len(textbox1.text)
if isnumeric(mid(textbox1.text,i,1))=true then
tex_cont=tex_cont & mid(textbox1.text,i,1)
end if
next i

textbox1.text=tex_cont

Good luck

BB
 
ParkerWrecker,
use the Change event also.
In the KeyPress, you would cancel out JUST the printable non-numeric characters, in order to allow other non-printable characters to still work (backspace, copy, cut, paste).
If the Change event you would validate the value (possibly again) using the IsNumeric() function.
This is needed because of the possibility the user is trying to paste in non-numeric chars.
In the change event you could also have the cursor move to the next edit box if the Len(text1.text) >= 3.
This may have the undesirable effect that the cursor moves when the default value of the text box already has 3 or more chars. (because a value was set in code).
Therefore, you will in addition need to use other methods such as the checking if the ActiveControl is the same control and the one in the Change event, or using a boolean variable to determine if a default value is being entered in code.
 
YES!!! Thanks men: NIGELRIVETT, MARCDOYLE, BB, CCLINT!!! i have combined logically your help's' and learned something from it.... ' hope to hear from you again sometime if ever i ll be needing help again... thanks Bro's...!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top