AutoHotkey Community

It is currently May 26th, 2012, 5:35 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: April 21st, 2009, 5:36 am 
Offline

Joined: April 20th, 2009, 7:28 am
Posts: 9
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 April 22nd, 2009, 11:02 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 21st, 2009, 6:12 am 
Offline

Joined: May 28th, 2008, 2:11 am
Posts: 739
Location: Minnesota, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: please
PostPosted: April 21st, 2009, 6:14 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
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"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 2:39 am 
Offline

Joined: April 20th, 2009, 7:28 am
Posts: 9
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 3:58 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 5:44 am 
Offline

Joined: November 27th, 2008, 9:44 am
Posts: 62
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 6:04 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
rulfzid wrote:
Another method that I find useful:


That method will also accept hexadecimal values, though, which in this case would not be desirable.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 6:25 am 
Offline

Joined: April 20th, 2009, 7:28 am
Posts: 9
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 April 22nd, 2009, 6:43 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 6:38 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 6:44 am 
Offline

Joined: April 20th, 2009, 7:28 am
Posts: 9
a a


Last edited by ShadowfoxXXX on April 22nd, 2009, 6:45 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 6:44 am 
Offline

Joined: April 20th, 2009, 7:28 am
Posts: 9
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 7:09 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Progress
PostPosted: April 22nd, 2009, 3:29 pm 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, BrandonHotkey, Miguel, mrhobbeys, MSN [Bot], Mtes, notsoobvious, rbrtryn, stanman and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group