AutoHotkey Community

It is currently May 26th, 2012, 7:46 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: May 13th, 2009, 5:06 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Each employee has a UID. There are six different teams of employees. If agent A belong to group 1, then MsgBox out something. If agent B belongs to group 2, msg box somethign else out. 6 teams, 6 different messages, 6 different if/if-else statments.

So I have a section in my GUI script that uses a variable for the UID agenst a list.

Is there a limit on how many characters you can have in a "else if(char_limit_in_here?)"

Using my 6 sets of ID's; group 1, has 38 id's, group 2 has 78, group 3 has 38 ect... but group 6 has almost 400 ID's, The script works if I break up group 6 into smaller if/else statments, but does not work when I have all 400 in one large else if() command.

Is this accurate?

Code:
;works
else if(GuiOpID = "A001" or GuiOpID = "A002" ..... GuiOpID = "A033")
{
command
}

;works
else if(GuiOpID = "B001" or GuiOpID = "B002" .... GuiOpID = "A078")
{
command
}

;does -NOT- work
else if(GuiOpID = "E001" ...... GuiOpID = "E400" or GuiOpID = "E401")
{
other command
}




Last edited by Carcophan on May 13th, 2009, 5:15 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5:15 pm 
I sugget using if Var in MatchList
http://www.autohotkey.com/docs/commands/IfIn.htm


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5:22 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
As a referrence, there are almost 4800 characters in the 'big' else/if statment.

[ guiOpID = "xzy" ] x 370 ID's = 4800 +/- characters within the else if ( here)



------
Edit, You posted when I did, I will look into the match list now.

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5:33 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Something like this? Or does the E001 through E405 need ""s or %%'s, I still get confused with when to sue them, the link doesnt have any syntax around the car name. But I wanted to check.

Code:
;A001 - A033 = group1 Id's
;B001 - B078 = group2 Id's
;E001 - E405 = The large list group 3 Id's

if GuiOpID in E001, E002, E003...... E405
{
;this is the 5K character list
BlockInput, on                 
 click 31, 114
 send, {Tab 6}
 Send, ^a
 send, {Del}
 send, Group3 ( %GuiOpID% ): 
 send, {Space 2}
 Send, {Tab 2}
 send, N   
 BlockInput, off
 MsgBox, Group3
 return
}

else if(GuiOpID = "A001" or GuiOpID = "A002" or GuiOpID = "A003"...)
{
;smaller, functional lists.
group1 commands
}
else if(GuiOpID = "B001" or GuiOpID = "B002" .... GuiOpID "B078")
{
group 2 commands
}



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5:44 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Hmm...I can't see any reason why this wouldn't work:

Code:
;A001 - A033 = group1 Id's
;B001 - B078 = group2 Id's
;E001 - E405 = The large list group 3 Id's

if GuiOpID between E001 and E405
{
;this is the 5K character list
BlockInput, on                 
 click 31, 114
 send, {Tab 6}
 Send, ^a
 send, {Del}
 send, Group3 ( %GuiOpID% ): 
 send, {Space 2}
 Send, {Tab 2}
 send, N   
 BlockInput, off
 MsgBox, Group3
 return
}
else if GuiOpID between A001 and A033
{
;smaller, functional lists.
group1 commands
}
else if GuiOpID between B001 and B078
{
group 2 commands
}


As long as the bounds are strictly alphanumeric I believe the function should understand what's within them. You can try that.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5:48 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
I used 'B004' as an example, they unfortunitly are not in any order.

ID's are as follows: 23Y, A04 0Ou, UvI, vVu, 4PF, FF0, FFo, FFO, ectectect.

No real order or anything, no patterns. 23Y and A04 may be in the same group. So sadly the 'bewteen' is not an option.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5:51 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Are the IDs that are in each group every day the same? And do you have a means by which you can extract the member IDs of each group into a list?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 6:00 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
The ID's stay the same from 'day to day', we may add/remove Id's as time goes on though. Generally the ID's come in excel format, but have info 'before' the OpId.

I have:
Code:

{stuff stuff stuff}

gosub, checkOpID

;and then

checkOpId:

{stuff stuff}

if(GuiOpID = "6VR" or GuiOpID = "S2H" or GuiOpID = "M6D"
{react}
return

else if(GuiOpID = "23Y" or GuiOpID = "40v" or GuiOpID = "123"
{react differently}
return





When my script encounters the OpId, to make its first choice on action, it only needs to process the '23y' or 'U0X' part of it. When we get the entire list of OpID's, they come to use in like 'NNJ23Y' 'CNJU0X' 'NATV1234', but only the last 3 digits of the OpId are of use to me/us.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 6:25 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Well it will be best to find a way to isolate the data you need somehow. If you can copy the data for each group from Excel to individual text files, you can run a file-reading loop when you start your script to save the data you need into match lists, something like this (assuming that all the IDs are listed vertically in one column of the spreadsheet):

Code:
Loop, read, Group1.txt
  Group1 .= SubStr(A_LoopReadLine,-2) "," ; extracts the last three characters from the line and appends it to the variable followed by a comma
Loop,read, Group2.txt
  Group2 .= SubStr(A_LoopReadLine,-2) ","
Loop,read, Group3.txt
  Group3 .= SubStr(A_LoopReadLine,-2) ","
Loop,read, Group4.txt
  Group4 .= SubStr(A_LoopReadLine,-2) ","
Loop,read, Group5.txt
  Group5 .= SubStr(A_LoopReadLine,-2) ","
Loop,read, Group6.txt
  Group6 .= SubStr(A_LoopReadLine,-2) ","
MsgBox, Match list loading is complete.


Then you can run the if [var] in statements with the appropriate match lists:

Code:
if GuiOpID in Group1
{
  << group1 commands >>
}
else if GuiOpID in Group2
{
  << group 2 commands >>
}
...


Now if group 6 is the only large group, you can just skip saving its contents to var and just use the logical inference that if it isn't in any of the other 5 groups, it must be in group 6:

Code:
...
else if GuiOpID in Group4
{
  << group 4 commands >>
}
else if GuiOpID in Group5
{
  << group 5 commands >>
}
else
{
  << group 6 commands >>
}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 6:46 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
I love your enthusiasm Sinkfaze, honestly :!:

I like the idea of 'defualting' the group 6 to the last 'else' statement, but besides the "6 groups", we have a '7th group'. Group 7 is every single OTHER employee (80,000+ lol), besieds the few hundred special ID's.

so group 1, 2, 3 , 4, 5 and 6 have special rules, we use the script to tell which group they are in and thus which action. The final else is 'group 7' which is the everyday employee who have no special rules.



I don't know. This has grown overly complicated.


I was able to cut the long 'group 6' into smaller if/else statements, making a group 6A, 6B, 6C, 6D...all belong to the same 'group', but it is broken into 30-40 ID sections vs the 400+ Id's in one section.

It's not the cleanest work around, but tested and works for now.


I was just kind of curious if there was a character limit or whitespace limit inside the '(' and ')'s.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 8:00 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Carcophan wrote:
I was able to cut the long 'group 6' into smaller if/else statements, making a group 6A, 6B, 6C, 6D...all belong to the same 'group', but it is broken into 30-40 ID sections vs the 400+ Id's in one section.

It's not the cleanest work around, but tested and works for now.


So if we assume, for example, you have groups 6A through 6J, you might also be able to use a loop to check all of them rather than creating a long string of if a OR b OR c...:

Code:
Loop, 10 ; or however many groups you have
{
  Ltr := Chr(64 + A_Index) ; saves 'A' to var and increments through the alphabet with each loop iteration
  if InStr(6%Ltr%,GuiOpID)
  {
    << group 6 commands >>
    break
  }
}




Carcophan wrote:
I don't know. This has grown overly complicated.


Your company has nearly 90K employees, I'm surprised you thought it wouldn't get complicated. :wink:

Carcophan wrote:
I love your enthusiasm Sinkfaze, honestly


I'm getting an opportunity to do some small-scale testing implementing AHK on machines at my place of work, if successful I'm going to lead a project for a much larger implementation. I'm trying to take advantage of any opportunity I can get to solve AHK problems in a work-related environment to hone my skills, so don't expect that I'll give up easily. :lol:

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2009, 2:05 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
The limitations I know of are:
  • Each line of script may be up to 16384 characters. Note that in the following example, there is only one "line":
    Code:
    If (x = A
        or x = B)
  • Each expression can have no more than 512 tokens. Each operator (open/close parenthesis, 'or', '=', etc.) or operand (variable or function reference, literal string, number, etc.) counts as one token. For instance, in the code above there are 9 tokens.
  • There can be no more than 512 derefs (variable references or function calls), but the above limit will typically be reached first.
Btw,
Code:
if GuiOpID in Group1
...should be...
Code:
if GuiOpID in %Group1%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2009, 2:34 pm 
Lexikos wrote:
Each expression can have no more than 512 tokens. Each operator (open/close parenthesis, 'or', '=', etc.) or operand (variable or function reference, literal string, number, etc.) counts as one token. For instance, in the code above there are 9 tokens.


That would be it then. :roll:

That makes sense, considering how many '=' and 'or's I have in there.

Poo.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2009, 4:14 pm 
Why not create 6 text files with the three special employee codes, you could use an excel macro, or ahk. Whether a space, comma, tab as delimiter doesn't matter.

Code:
; assumes file names group1.txt thru group6.txt

; test ID
thisOpID = 6FD

Loop 6
{
   FileRead, group%A_Index%, group%A_Index%.txt
   If (InStr(group%A_Index%, thisOpID) != 0) ; found it!
   {
      actionID := A_Index
      Break ; stop scanning
   }
}

If actionID =
{
   ; "other" employee, no action
}
Else If actionID = 1
{
   ; action for group 1
}

; etcet...



not-tested.

HTH


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2009, 8:22 pm 
Offline

Joined: April 8th, 2009, 7:21 pm
Posts: 16
You guys are making it WAY too complicated. A single IF statement using regular expression can handle the "largest" group:

Your GroupIDs have a specific pattern, and a regular expression can handle that match.

Code:
;A001 - A033 = group1 Id's
;B001 - B078 = group2 Id's
;E001 - E405 = The large list group 3 Id's

If (RegExMatch(GuiOpID, "E([0-3][0-9][0-9]|40[0-5])"))
{
  ; Do stuff for E000 - E405
}


This code has been tested.

I can explain the regular expression, but check the help file for full documentation:

"E([0-3][0-9][0-9]|40[0-5])"

The "E" should be obvious. Matches the letter "E"

([0-3][0-9][0-9] | 40[0-5])

The "|" is an "or" statement, so it's broken up in two parts.

First part:

[0-3][0-9][0-9]

Matches 3 numbers. First one between 0-3. Second between 0-9, third one between 0-9, effectively matching anything from 000 to 399.

If you have a mix of alphanumeric, you can do [0-9a-f] for hexidecimal, for example.

Second part:
40[0-5]

Matches another 3 number. First two being 40, last one from 0 to 5, matching 400 - 405.

Do note that my example matches E000 to E405. If you do not want to match E000, it'll be quicker to add a "IF" statement checking specifically for E000 than to modify the regular expression to exclude E000 out of the range.

You can match billions of IDs with regular expression and it wouldn't slow it down by much.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, Azevedo, over21, perlsmith, Yahoo [Bot] and 70 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