AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[solved]Check if variable contains letters/numbers etc..

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ShadowfoxXXX



Joined: 20 Apr 2009
Posts: 9

PostPosted: Tue Apr 21, 2009 4:36 am    Post subject: [solved]Check if variable contains letters/numbers etc.. Reply with quote

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
View user's profile Send private message
Slanter



Joined: 28 May 2008
Posts: 739
Location: Minnesota, USA

PostPosted: Tue Apr 21, 2009 5:12 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
keybored



Joined: 18 Jun 2006
Posts: 343
Location: Phoenix, AZ

PostPosted: Tue Apr 21, 2009 5:14 am    Post subject: please Reply with quote

ShadowfoxXXX,
First read about how to get answers effectively.
http://www.autohotkey.com/forum/viewtopic.php?t=4986
Then check the command list for "If var is [not] type"
Back to top
View user's profile Send private message
ShadowfoxXXX



Joined: 20 Apr 2009
Posts: 9

PostPosted: Wed Apr 22, 2009 1:39 am    Post subject: Reply with quote

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
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Wed Apr 22, 2009 2:58 am    Post subject: Reply with quote

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
View user's profile Send private message
rulfzid



Joined: 27 Nov 2008
Posts: 62

PostPosted: Wed Apr 22, 2009 4:44 am    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Wed Apr 22, 2009 5:04 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
ShadowfoxXXX



Joined: 20 Apr 2009
Posts: 9

PostPosted: Wed Apr 22, 2009 5:25 am    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Wed Apr 22, 2009 5:38 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
ShadowfoxXXX



Joined: 20 Apr 2009
Posts: 9

PostPosted: Wed Apr 22, 2009 5:44 am    Post subject: Reply with quote

a a

Last edited by ShadowfoxXXX on Wed Apr 22, 2009 5:45 am; edited 1 time in total
Back to top
View user's profile Send private message
ShadowfoxXXX



Joined: 20 Apr 2009
Posts: 9

PostPosted: Wed Apr 22, 2009 5:44 am    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Wed Apr 22, 2009 6:09 am    Post subject: Reply with quote

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.

[VxE] wrote:
Link to docs: If vars is [not] type
Back to top
View user's profile Send private message AIM Address
keybored



Joined: 18 Jun 2006
Posts: 343
Location: Phoenix, AZ

PostPosted: Wed Apr 22, 2009 2:29 pm    Post subject: Progress Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group