Jump to content

Recommended Posts

Posted

Hi guys!

 

I need some help here, is there a way to use Random with While? 

I need this script to run in between 1 and 4 times but I dont know how to do it, can you please help me?

 

dim $i=1
While $i<=4
Sleep(3000)
Send("{LWINDOWN}r{LWINUP}")
Sleep(3000)
Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
Sleep(3000)
WinActivate("tags: Bloc de notas","")
Sleep(3000)
Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
Sleep(3000)
Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
Sleep(3000)
Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
$i=$i+1
WEnd

  • Developers
Posted

Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

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.
  :)

Posted

The answer is in the title of your thread :)
Replace the upper limit of your While with the Random function.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

The start value of your While loop is 1 (lower limit), the end value is 4 (upper limit).
So replace 4 with the Random function.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

yo  mean like this? but i still need it to be a loop when it gets more than 1 like in 2,3,4

 

Random(1, 4)

Sleep(3000)
Send("{LWINDOWN}r{LWINUP}")
Sleep(3000)
Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
Sleep(3000)
WinActivate("tags: Bloc de notas","")
Sleep(3000)
Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
Sleep(3000)
Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
Sleep(3000)
Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
Next

Posted

Please re-read my last post and you will see that you still need the While statement and need to replace the end value as I described.
Not too hard, isn't it ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Im really sorry but I dont get it 😌, can you please write it down? As you can see Im not that good at writing scripts.... Sorry for this

Posted

yes I did thats why I'm asking if is possible to do a loop with random or how to do it...

I'm not that experienced doing scripts

Can you please help me?

  • Developers
Posted

Well I don't think you really did as example 3 shows a For..Next loop with the exact thing you are asking for. ;) 
Try again and this time take the time to understand how that example works.

Jos

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.
  :)

Posted

Well I'm having a hard time writing down my first script I just wanted some help here, I've seen that you need to to type the script and in base of that you ask your questions and you write the possible answers...

I don't know how to do it Can someone please help me with a written example?? If this is to much to ask? 

  • Developers
Posted
1 minute ago, Garrik said:

Well I'm having a hard time writing down my first script I just wanted some help here, I've seen that you need to to type the script and in base of that you ask your questions and you write the possible answers...

I don't know how to do it Can someone please help me with a written example?? If this is to much to ask? 

Well It can't be that you have even looked closer at what I pointed you to and tried something in these 8 minutes between my and your post. Just cut&pasting a piece of script written by you or somebody else and then expecting us to jump to attention and coding it for you is not the way it works here.  

Jos

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.
  :)

Posted

Another question: Can you please tell us what you try to do with your script?
Using Send is not very reliable as it might interfere with user actions.
Why do you need Random() at all?
 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

thanks for answering me,

what this script do is coping some words from a notepad, but as you can see always copy 4 times I need it to randomly do it between 1 and 4 times

dim $i=1
While $i<=4
Sleep(3000)
Send("{LWINDOWN}r{LWINUP}")
Sleep(3000)
Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
Sleep(3000)
WinActivate("tags: Bloc de notas","")
Sleep(3000)
Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
Sleep(3000)
Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
Sleep(3000)
Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
$i=$i+1
WEnd

Posted
Global $i = 1
Global $EndValue = Random(1, 4)
While $i <= $EndValue
    Sleep(3000)
    Send("{LWINDOWN}r{LWINUP}")
    Sleep(3000)
    Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
    Sleep(3000)
    WinActivate("tags: Bloc de notas", "")
    Sleep(3000)
    Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
    Sleep(3000)
    Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
    Sleep(3000)
    Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
    $i = $i + 1
WEnd

Wasn't too hard, was it?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • Developers
Posted

@Garrik,

Sad to see the zero effort approach.
It won't get you far when you are unwilling to take direction and learn yourself, but that is your choice.

 

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.
  :)

Posted (edited)

Is not that, like I said Im not that expierenced, Im trying to learn by examples applied in what I do, Im sorry if I bother all of you Im just trying yo learn, and as I sayed I did that script by my self.

Now you just said that "send" is not the best option...

 

I'll see what can I do to change it.

 

And again thanks for helping!

Edited by Garrik
Posted (edited)

@garrik

Let's start by answering this question: How does one select a random number?

 

Answer:

https://www.autoitscript.com/autoit3/docs/functions/Random.htm

 

Alright next question: How does one put the randomly selected number into a variable?

 

Answer:

https://www.autoitscript.com/autoit3/docs/functions/Random.htm

 

Next question: How does one use that variable to determine how many times to loop?

 

Answer:

Look at your code! *OR: https://www.autoitscript.com/autoit3/docs/functions/Random.htm

Edited by rm4453

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...