Jump to content

Ubound Not Consistent


 Share

Recommended Posts

hello fellow autoit programmers,

I have been using this code for quite sometime.

but i find that sometime the code will give the

value of "8" rather than the option of selection

in $arrr

is it normal or not? anyone can improve this code?

$arrr="@gmail.com,@yahoo.com,@hotmail.com.my,@live.com,@live.com.my,@yahoo.co.uk,@msn.com,@facebook.com"
$arrr1=StringSplit($arrr,",")
$i4=Random(0,UBound($arrr1)-1,1)
$domain=$arrr1[$i4]
MsgBox(4096, "Generated", $domain )

So maybe any1 can modify and remove 8 from the result. Thanks

Link to comment
Share on other sites

StringSplit() stores the return count in element 0 of the array. As Random() will be between 0 and 8 for your code you've got a 1 in 9 chance it shows the return count.

To fix it you can set StringSplit() to not return the return count, or have Random() start at 1, instead of 0. In that case you can do away with Ubound as long as you don't resize the array:

$arrr="@gmail.com,@yahoo.com,@hotmail.com.my,@live.com,@live.com.my,@yahoo.co.uk,@msn.com,@facebook.com" 
$arrr1=StringSplit($arrr,",") 
$i4=Random(1,$arrr1[0],1) ;Make ubound return a number between (and including) 1 and 8
$domain=$arrr1[$i4] 
MsgBox(4096, "Generated", $domain )
Link to comment
Share on other sites

Try it with

$arrr1=StringSplit($arrr,",", 2);; create the array as 0 based

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!"

Link to comment
Share on other sites

Just in case you don't know where to look in the helpfile:

look at StringSplit and what the return value is.

Unlucky use of Random() is just a lgical error. :unsure:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Glad you guys found it so that means it must be clearly defined then. :unsure:

Look at the posting times of those threads.

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!"

Link to comment
Share on other sites

You couldn't upset me given a year and a half to do it in my friend.

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!"

Link to comment
Share on other sites

StringSplit() stores the return count in element 0 of the array. As Random() will be between 0 and 8 for your code you've got a 1 in 9 chance it shows the return count.

To fix it you can set StringSplit() to not return the return count, or have Random() start at 1, instead of 0. In that case you can do away with Ubound as long as you don't resize the array:

$arrr="@gmail.com,@yahoo.com,@hotmail.com.my,@live.com,@live.com.my,@yahoo.co.uk,@msn.com,@facebook.com" 
$arrr1=StringSplit($arrr,",") 
$i4=Random(1,$arrr1[0],1) ;Make ubound return a number between (and including) 1 and 8
$domain=$arrr1[$i4] 
MsgBox(4096, "Generated", $domain )

Try it with

$arrr1=StringSplit($arrr,",", 2);; create the array as 0 based

Thank you so much Tvern and GEOSoft. Both method works great! Awesome!

Sorry for troubling some of you. I thought anyone can ask question

if they did not understand because thats what the forum are for.

Because I am only a newbie on autoit, I dont even understand the explanation

in the help file. at least I show what I have done. Because I see a lot of

new user post their question with not enough information and code, they were

just being chased away.

You are not born to quickly master the autoit programs. If 5-6years ago

you are in the same boat as me now, I think you also learn from the forum

and people show you the way. Now is the time for you to give back to the community.

Thank you so much AutoIt programmers

Link to comment
Share on other sites

  • Developers

Sorry for troubling some of you. I thought anyone can ask question

if they did not understand because thats what the forum are for.

You are not troubling anybody at all so no worries.

Jos :unsure:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...