mikemonk 0 Posted April 9, 2010 I am fairly new to AutoIT. I have been working on some scripts that make heavy use of random variables to choose from blocks of text for an article. I have been working on it a couple of days, but I recently started having problems with errors saying my variables are undefined. I set a variable of a random number, and then I use If or Select/Case statements to determine a random piece of code. I am having decidedly mixed results. It was working perfectly the past two days, but I am now running into problems, even doing things the same way. I am a newbie, so I am hoping its an obvious mistake on my part. If anybody has any suggestions, I would be enormously grateful. The error say that $ran is undefined in the Case statement, but has worked before with the same syntax in similar case statements, and seems to work in the If/Then statements. Here is some of the relevant code: #region determine if filler text is used Select ; $ran = Random(1, 3, 1) ; Case $ran >= 1 AND $ran<= 2 ; proceed with filler #region selection of adverb $ran = Random(1, 3, 1) If $ran = 1 Then $Snippet2 = "closely " If $ran = 2 Then $Snippet2 = "in conjunction " If $ran = 3 Then $Snippet2 = "" #endregion $Snippet3 = "with " ; #region name of team $ran = Random(1, 4, 1) If $ran = 1 Then $Snippet4 = "customer service and sales teams " If $ran = 2 Then $Snippet4 = "customer service teams " If $ran = 3 Then $Snippet4 = "sales teams " If $ran = 4 Then $Snippet4 = "client relationship team " Case $ran = 3 ; no filler $Snippet2 = "" ; $Snippet3 = "" ; $Snippet4 = "" ; #endregion EndSelect #endregion I have also tried it with the following alteration, with a similar error: $ran = Random(1, 3, 1) ; Case $ran = 1 OR $ran = 2 Share this post Link to post Share on other sites
mikemonk 0 Posted April 9, 2010 Nevermind, for anybody else that has this problem, you have to put the random statements outside of the select line, and not inside it. Share this post Link to post Share on other sites
Yoriz 6 Posted April 9, 2010 Move your $ran = Random(1, 3, 1) ; line to before the Select ; #region determine if filler text is used $ran = Random(1, 3, 1) ; Select ; Case $ran >= 1 AND $ran<= 2 ; proceed with filler #region selection of adverb $ran = Random(1, 3, 1) If $ran = 1 Then $Snippet2 = "closely " If $ran = 2 Then $Snippet2 = "in conjunction " If $ran = 3 Then $Snippet2 = "" #endregion $Snippet3 = "with " ; #region name of team $ran = Random(1, 4, 1) If $ran = 1 Then $Snippet4 = "customer service and sales teams " If $ran = 2 Then $Snippet4 = "customer service teams " If $ran = 3 Then $Snippet4 = "sales teams " If $ran = 4 Then $Snippet4 = "client relationship team " Case $ran = 3 ; no filler $Snippet2 = "" ; $Snippet3 = "" ; $Snippet4 = "" ; #endregion EndSelect #endregion GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Share this post Link to post Share on other sites
kaotkbliss 146 Posted April 9, 2010 I did this to get completely random snippits #Region determine if filler text is used $ran = Random(1, 3, 1) $ran2 = Random(1, 4, 1) Select ; ; Case $ran >= 1 And $ran <= 2 ; proceed with filler #Region selection of adverb $ran = Random(1, 3, 1) If $ran = 1 Then $Snippet2 = "closely " If $ran = 2 Then $Snippet2 = "in conjunction " If $ran = 3 Then $Snippet2 = "" #EndRegion selection of adverb $Snippet3 = "with " ; #Region name of team If $ran2 = 1 Then $Snippet4 = "customer service and sales teams " If $ran2 = 2 Then $Snippet4 = "customer service teams " If $ran2 = 3 Then $Snippet4 = "sales teams " If $ran2 = 4 Then $Snippet4 = "client relationship team " Case $ran = 3 ; no filler $Snippet2 = "" ; $Snippet3 = "" ; $Snippet4 = "" ; #EndRegion name of team EndSelect #EndRegion determine if filler text is used MsgBox(0, "", $Snippet2 & $Snippet3 & $Snippet4) 010101000110100001101001011100110010000001101001011100110010000001101101011110010010000001110011011010010110011100100001My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueekWe're gonna need another Timmy! Share this post Link to post Share on other sites