Kamakazy Posted January 4, 2013 Posted January 4, 2013 Hey Guys. Happy Christmas and Merry new Year and all that.. I'm currently automating our entire system for end-2-end testing. I have about 12 Complex scripts all joined together in a GUI and it all works. But I want to bring down the amount of lines of code that I used (I Started coding these script without any knowledge of coding/scripting so bear with me..) Currently, I am generating a random number with the following code.. IniWrite(@ScriptDir & "\Iteration.ini ", "Boat Details", "Engine" , Random(111, 999, 1) & Chr(Random(Asc("A"), _ Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(111, 999, 1) & Chr(Random(Asc("A"), Asc("Z"), 1)) & _ Chr(Random(Asc("A"), Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1)) & _ Random(111, 999, 1) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1))) Please note that the amount of characters is critical for my tests. Now the question, Is there a better way of doing this? Thanx for the assist. Kama _IEFrameGetObjByID |
kylomas Posted January 4, 2013 Posted January 4, 2013 (edited) Kamakazy, If I was going to do something like that I would structure it like this IniWrite( @ScriptDir & "\Iteration.ini ", "Boat Details", "Engine" , _num() & _ _chr() & _ _chr() & _ _num() ) ; etc for as long as you require func _chr() return Chr(Random(Asc("A"), Asc("Z"), 1)) EndFunc func _num() Random(111, 999, 1) endfunc just for readability. kylomas edit: it does NOT bring down the # of lines of code but it's a hell of a lot easier to read. The # of lines of source should be considered only after readability and maintainability, if at all. Edited January 4, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Kamakazy Posted January 4, 2013 Author Posted January 4, 2013 Duly noted! Thanx for the input dude.. Regards. Kama _IEFrameGetObjByID |
jchd Posted January 4, 2013 Posted January 4, 2013 func _num() Return Random(111, 999, 1) endfunc will work even better ;-) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
kylomas Posted January 4, 2013 Posted January 4, 2013 @jchd - Thanks! @Kamakazy - jchd caught a mistake that I made. I forgot the "return" stmt in the _num() func. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
jchd Posted January 4, 2013 Posted January 4, 2013 This is a pretty easy error to make and AutoIt won't bark: Local $a = fct() Func fct() Random(0, 9, 1) ; or whatever without Return EndFunc This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
kylomas Posted January 4, 2013 Posted January 4, 2013 Yes, I understand. Kamakazy is a new user however and will think that he did something wrong when the code does not work. That is why I made sure to point out the error. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Kamakazy Posted January 7, 2013 Author Posted January 7, 2013 Thanx Guys. I actually caught the missing "return". Let's just say that I'm a very fast learner... but nothing beats asking questions... Thanx again Kama _IEFrameGetObjByID |
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