![]() |
Syntax for Logical Operators to Limit Input?
Good Morning, I am creating a data entry form and have followed the tutorials written by Peter Aitken in MSDN . He shows how to limit entry to numerical values and that is very clear. I am trying to allow the user to enter a percent such as 21.2%. I just can't seem to find the right syntax . I can limit to the decimal point or to the percent sign with a single statement. Or I can limit to the numerical range of 1 through 9, but I can't seem to do all three with one statement. Here is the last statement I tried: Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _ As MSForms.ReturnInteger) If KeyAscii < 36 Or KeyAscii < 46 Or KeyAscii < 48 _ Or KeyAscii < 49 Or KeyAscii < 50 Or KeyAscii < 51 _ Or KeyAscii < 52 Or KeyAscii < 53 Or KeyAscii < 54 _ Or KeyAscii < 55 Or KeyAscii < 56 Or KeyAscii < 57 Then KeyAscii = 0 End If End Sub -- DCSwearingen ------------------------------------------------------------------------ DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506 View this thread: http://www.excelforum.com/showthread...hreadid=499375 |
Syntax for Logical Operators to Limit Input?
% is 37
? asc("%") 37 Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _ As MSForms.ReturnInteger) If not ((KeyAscii 48 And KeyAscii <= 57) or KeyAscii = 46 _ or KeyAscii = 37) Then KeyAscii = 0 End If end if -- Regards, Tom Ogilvy "DCSwearingen" wrote in message news:DCSwearingen.21dfrm_1136816702.3105@excelforu m-nospam.com... Good Morning, I am creating a data entry form and have followed the tutorials written by Peter Aitken in MSDN . He shows how to limit entry to numerical values and that is very clear. I am trying to allow the user to enter a percent such as 21.2%. I just can't seem to find the right syntax . I can limit to the decimal point or to the percent sign with a single statement. Or I can limit to the numerical range of 1 through 9, but I can't seem to do all three with one statement. Here is the last statement I tried: Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _ As MSForms.ReturnInteger) If KeyAscii < 36 Or KeyAscii < 46 Or KeyAscii < 48 _ Or KeyAscii < 49 Or KeyAscii < 50 Or KeyAscii < 51 _ Or KeyAscii < 52 Or KeyAscii < 53 Or KeyAscii < 54 _ Or KeyAscii < 55 Or KeyAscii < 56 Or KeyAscii < 57 Then KeyAscii = 0 End If End Sub -- DCSwearingen ------------------------------------------------------------------------ DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506 View this thread: http://www.excelforum.com/showthread...hreadid=499375 |
Syntax for Logical Operators to Limit Input?
Thank You!! I had a typo in my earlier message. I did have 37 for the percen sign in my code. I needed the parenthesis to combine the operations. I'll have to remember that in the future!! Again, thanks to all who post answers on this forum. I read a lot o the answers, even if I have not run across the issue -- DCSwearinge ----------------------------------------------------------------------- DCSwearingen's Profile: http://www.excelforum.com/member.php...fo&userid=2150 View this thread: http://www.excelforum.com/showthread.php?threadid=49937 |
All times are GMT +1. The time now is 01:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com