| View previous topic :: View next topic |
| Author |
Message |
ShadowfoxXXX
Joined: 20 Apr 2009 Posts: 9
|
Posted: Tue Apr 21, 2009 4:36 am Post subject: [solved]Check if variable contains letters/numbers etc.. |
|
|
I have a program that takes in an area code.
I need a way to check if it contains anything other than numbers.
[ Moderator!: Do not use all caps in the subject line "CHECK IF VARIABLE CONTAINS LETTERS, NUMBERS, ETC..." ]
Last edited by ShadowfoxXXX on Wed Apr 22, 2009 10:02 pm; edited 2 times in total |
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 739 Location: Minnesota, USA
|
Posted: Tue Apr 21, 2009 5:12 am Post subject: |
|
|
| Code: | MyVar = 123abc
If MyVar is not digit
MsgBox MyVar contains something other than the numbers 0-9!
; Or
MyVar2 = 123456
If MyVar2 is digit
MsgBox MyVar2 contains only the numbers 0-9! |
_________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
keybored
Joined: 18 Jun 2006 Posts: 343 Location: Phoenix, AZ
|
|
| Back to top |
|
 |
ShadowfoxXXX
Joined: 20 Apr 2009 Posts: 9
|
Posted: Wed Apr 22, 2009 1:39 am Post subject: |
|
|
ok... I read it.
I'm assuming you're trying to say I did something incorrectly?
I did check all over the place, and i found nothing.
I don't need to include any further information,
and the "If var is [not] type" didn't show up anywhere, because AHK has no explicitly defined variable types. They're all just variables. No ints, strgins, or booleans.
I need a way to analyze the contents of a variable, even if it reads one character at a time, and then report if it contains any letters.
I tried:
If AreaCode is not digit {
MsgBox Area Code contains something other than the numbers 0-9!
Gui, Show
}
with and without % around AreaCode. It didnt work. At all |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
Posted: Wed Apr 22, 2009 2:58 am Post subject: |
|
|
Link to docs: If vars is [not] type
Braces are used incorrectly here. | ShadowfoxXXX wrote: | | Code: | If AreaCode is not digit {
MsgBox Area Code contains something other than the numbers 0-9!
Gui, Show
} |
|
this is correct: | Code: | If AreaCode is not digit
{ ; OTB style is only supported in some cases
MsgBox Area Code contains something other than the numbers 0-9!
Gui, Show
} |
Or with regex: | Code: | InputBox, userinput, input a number
If !RegexMatch( userinput, "[^0-9]" ) && userinput != ""
msgbox, You entered nothing but numbers
else
msgbox, You entered something that wasn't a number |
_________________ Ternary (a ? b : c) guide TSV Table Manipulation Library
Post code inside [code][/code] tags! |
|
| Back to top |
|
 |
rulfzid
Joined: 27 Nov 2008 Posts: 62
|
Posted: Wed Apr 22, 2009 4:44 am Post subject: |
|
|
Another method that I find useful:
| Code: | InputBox, userinput, input a number
If userinput+0 ; only evaluates to true if userinput is a number
msgbox, You entered nothing but numbers
else
msgbox, You entered something that wasn't a number |
|
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Wed Apr 22, 2009 5:04 am Post subject: |
|
|
| rulfzid wrote: | | Another method that I find useful: |
That method will also accept hexadecimal values, though, which in this case would not be desirable. |
|
| Back to top |
|
 |
ShadowfoxXXX
Joined: 20 Apr 2009 Posts: 9
|
Posted: Wed Apr 22, 2009 5:25 am Post subject: |
|
|
braces used this way
if (blablabl){
stuff here
}
has always worked for me.
in fact i used it multiple times in this program and it worked fine.
somehow that particular method only works when i change it.
I guess i gotta get off the whole java thing.
Last edited by ShadowfoxXXX on Wed Apr 22, 2009 5:43 am; edited 1 time in total |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Wed Apr 22, 2009 5:38 am Post subject: |
|
|
OTB style, in which the brace is placed on the same line as the if-statement, is only valid for if-statements that are expressions. Normal if-statements such as
If SomeVar = SomeString
or the special if-statements such as
If SomeVar is [not] type
and
If SomeVar [not] in/contains MatchList
do NOT support OTB, and must have the brace appear on the next line. |
|
| Back to top |
|
 |
ShadowfoxXXX
Joined: 20 Apr 2009 Posts: 9
|
Posted: Wed Apr 22, 2009 5:44 am Post subject: |
|
|
a a
Last edited by ShadowfoxXXX on Wed Apr 22, 2009 5:45 am; edited 1 time in total |
|
| Back to top |
|
 |
ShadowfoxXXX
Joined: 20 Apr 2009 Posts: 9
|
Posted: Wed Apr 22, 2009 5:44 am Post subject: |
|
|
so what if i wanted to check for numbers?
and symbols?
is it
if blank is not letter
if blank is not string
what is it? |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Wed Apr 22, 2009 6:09 am Post subject: |
|
|
Please, at the very least, read what has been posted in your thread. [VxE] has already posted a link to the help file, where you will find all of the information you need.
|
|
| Back to top |
|
 |
keybored
Joined: 18 Jun 2006 Posts: 343 Location: Phoenix, AZ
|
Posted: Wed Apr 22, 2009 2:29 pm Post subject: Progress |
|
|
| Quote: | so what if i wanted to check for numbers?
and symbols?... |
Please give some examples of the variables you are evaluating. I thought you were looking for just numbers, guess not.
The initial direction to read the "faq" on how to get answers was because you posted no code. Had you done so it might have provided some examples of what you were evaluating. Looks like we're making progress. Hang in there. |
|
| Back to top |
|
 |
|