Sign in to follow this  
Followers 0
XenonTech

Looping script changing variables.

12 posts in this topic

#1 ·  Posted (edited)

While True
$vVariable = "Have a nice day!"
$vVariable = "Tacos taste good."
$vVariable = "Shrek is love!"

Send($vVariable)
WEnd

So basically the first time it loops I want it to send "Have a nice day!" then the second time, "Tacos taste good." and then on the third time to send "Shrek is love!" and then make it go back to the first variable and repeat the process. How is this possible?

Edited by XenonTech

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

 Something like this..

$counter = 0

While True
    If $counter = 0 Then
        $vVariable = "Have a nice day!"
        Send($vVariable)
    EndIf
    If $counter = 1 Then
        $vVariable = "Tacos taste good."
        Send($vVariable)
    EndIf
    If $counter = 2 Then
        $vVariable = "Shrek is love!"
        Send($vVariable)
    EndIf
    $counter += 1
WEnd

EDIT: Fixed formatting

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

HI.

Local $aArray[3]=["Have a nice day!", "Tacos taste good.", "Shrek is love!"]

Local $i=0
While True
ConsoleWrite($aArray[$i] & @CRLF)
Send($vVariable)
$i+=1
if $i=3 Then $i=0
WEnd

Saludos

Share this post


Link to post
Share on other sites

Doh on my part; Using an array would be the simplest method as shown by Danyfirex ;)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

But that's overcomplicating. Both of the examples can be reduced to:

While True
    Send("Have a nice day!")
    Send("Tacos taste good.")
    Send("Shrek is love!")
WEnd

Somehow I think that's not what the OP meant.

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

But that's overcomplicating. Both of the examples can be reduced to:

While True
    Send("Have a nice day!")
    Send("Tacos taste good.")
    Send("Shrek is love!")
WEnd

Somehow I think that's not what the OP meant.

I was using this method, but I recently went from 5 or 6 variables to a few thousand. I just want the code to be as compact as possible.

Share this post


Link to post
Share on other sites

Thanks for the help everyone!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

HI.

Local $aArray[3]=["Have a nice day!", "Tacos taste good.", "Shrek is love!"]

Local $i=0
While True
ConsoleWrite($aArray[$i] & @CRLF)
Send($vVariable)
$i+=1
if $i=3 Then $i=0
WEnd

Saludos

So would I write Send($vVariable) to send the varaible? The array doesn't define the variable name in there. Sorry, I'm new to autoit.

Edited by XenonTech

Share this post


Link to post
Share on other sites

of course you should send the array.

Local $aArray[3]=["Have a nice day!", "Tacos taste good.", "Shrek is love!"]

Local $i=0
While True
ConsoleWrite($aArray[$i] & @CRLF)
Send($aArray[$i])
$i+=1
if $i=3 Then $i=0
WEnd

Saludos

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

also this could do:

Local $aArray[3]=["Have a nice day!", "Tacos taste good.", "Shrek is love!"]
for $i = 0 to UBound($aArray)-1
    Send($aArray[$i])
Next

Edit:

better reading OP I see that the loop should repeat forever
this will correct my previous listing.
Sorry.

Local $aArray[3] = ["Have a nice day!", "Tacos taste good.", "Shrek is love!"]
HotKeySet('{ESC}', '_exit')
While True
    For $i = 0 To UBound($aArray) - 1
        Send($aArray[$i] & @CR, 1)
    Next
WEnd
Func _exit()
    Exit
EndFunc   ;==>_exit
Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Mod() is sometimes a good function for this kind of thing.

;

HotKeySet('{ESC}', '_exit')

Local $aArray[3] = ["Have a nice day!", "Tacos taste good.", "Shrek is love!"], _
      $i = 0

While True
    Send($aArray[Mod($i, 3)] & @CR, 1)
    $i += 1 ; This value will eventually go out of range (> 99999999999999).
WEnd

Func _exit()
    Exit
EndFunc   ;==>_exit

;

Theoretically the code will stop working because the variable $i will eventually go out of range. It probably won't happen within a milenium: because the Send function is really slow. If the looped process is millions of times faster, then out of range values could become a problem, in which case the code will need to be ammended.

Edited by czardas
1 person likes this

Share this post


Link to post
Share on other sites

my two Cents:

ControlFocus("[CLASS:SciTEWindow]","","Scintilla2")
HotKeySet('{ESC}', '_exit')
Func _exit()
    Exit
EndFunc   ;==>_exit
Local $aArray[3] = ["Have a nice day!", "Tacos taste good.", "Shrek is love!"]
For $i = 0 To 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    Send($aArray[Mod($i, 3)] & @CRLF, 1)
Next

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
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
Sign in to follow this  
Followers 0