abc Posted June 4, 2008 Posted June 4, 2008 Hi, I have little to no experience with Autoit and scripting in general. Here is the problem which I have encountered: There are various numbers corresponding to values. In total, there are 9999 numbers assigned to 180 values. Example: 0001 - 0250: Value A 0251 - 1200: Value B ...and so on. What I want to do, is to check a 4 digit string and have the proper value returned. For example, if I check the number 0235, i want to have Value A returned since 0235 falls within the number range of 0001 - 0250. I retrieve the number like this: Func Find() Dim $abc="12345678" $kilde=(_INetGetSource( 'URL' & $abc )) $nr=StringRegExp( $kilde, '(?:<br/>)([0-9]{4})(?: )', 1) If @error == 0 Then return Plass() Else return "X" EndIf EndFunc Then, I check what value the number corresponds to, like this: Func Plass() If ($nr [0] >= "0001") and ($nr [0] <= "1295") Then return "Value A" EndIf If ($nr [0] >= "1300") and ($nr [0] <= "1369") Then return "Value B" EndIf If ($nr [0] >= "1371") and ($nr [0] <= "1399") Then return "Value C" EndIf If ($nr [0] >= "1400") and ($nr [0] <= "1459") Then return "Value D" EndIf ...and so on. It works, however this seems to be an extremely redundant way to get the proper value returned. I need hundreds of lines of code just to find out if the number falls within one of 180 possible number ranges. Is there a more efficient way to do this? I hope I have stated my problem clearly enough, and look forward to any kind of help.
Moderators SmOke_N Posted June 4, 2008 Moderators Posted June 4, 2008 1. You are using >= on a string and not a number, in order to keep correct results, I suggest If Number(x) >= Number(y) 2. You could try to create a for/next loop to loop through all 180 scenerios... you may want to look at how arrays are set up, and possibly use that scenerio pseudoDim $aMin(180) = [1, 1300, 1371, 1400, etc..] Dim $aMax(180) = [1295, 1369, 1399, 1459, etc] Dim $aValues(180) = ["value a", "value b", "value c", "value d", etc] For $i = 0 To 179 If Number($n[0]) >= $aMin[$i] And Number($n[0]) <= $aMax[$i] Then Return $aValues[$i] Next 3. You could create an incredibly long hash table. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
abc Posted June 4, 2008 Author Posted June 4, 2008 You pointed me in the right direction, and now the script seems much tidy. Thanks!
Valuater Posted June 4, 2008 Posted June 4, 2008 ??? C:\Program Files\AutoIt3\Examples\My Stuff\junk.au3(3,10) : ERROR: syntax error Dim $aMin( ~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\junk.au3 - 1 error(s), 0 warning(s) 8)
Moderators SmOke_N Posted June 4, 2008 Moderators Posted June 4, 2008 ??? C:\Program Files\AutoIt3\Examples\My Stuff\junk.au3(3,10) : ERROR: syntax error Dim $aMin( ~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\junk.au3 - 1 error(s), 0 warning(s) 8)Yeah, I was just telling George I saw that... Freebasic uses ()'s to determine their arrays, and I was writing a function there when I answered here ... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Valuater Posted June 4, 2008 Posted June 4, 2008 I didn't know you were studying VB... thats great!! 8)
GEOSoft Posted June 4, 2008 Posted June 4, 2008 Yeah, I was just telling George I saw that... Freebasic uses ()'s to determine their arrays, and I was writing a function there when I answered here ... You can be forgiven. Just blame it on me distracting you. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Moderators SmOke_N Posted June 4, 2008 Moderators Posted June 4, 2008 I didn't know you were studying VB... thats great!!8) (it's not vb lol) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now