Jump to content

Recommended Posts

Posted

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

Posted (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 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

Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

Posted

@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

Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...