Jump to content

Repeat Inputbox until "finish" is clicked


Recommended Posts

Hello,

so im new to auto it and have been playing around a bit.

What i am looking to do is creat and input box, that keeps opening until finish is clicked. E.g i want to add 4 url's to a .txt file, if i click OK i get a new input box with a different veriable, and so on untill i click finish.

what i have so far works like a charm !! however i have to prespecifie how many links can be inputed...

; Links Input
   $var1 = InputBox("Your Link....", "1", "type the url here", "", 500, 100)
   $var2 = InputBox("Your Link....", "2", "type the url here", "", 500, 100)
   $var3 = InputBox("Your Link....", "3", "type the url here", "", 500, 100)
   $var4 = InputBox("Your Link....", "4", "type the url here", "", 500, 100)
   $var5 = InputBox("Your Link....", "5", "type the url here", "", 500, 100)
; Save to Text file
   FileWrite("url.txt", $var1 & @CRLF)
   FileWrite("url.txt", $var2 & @CRLF)
   FileWrite("url.txt", $var3 & @CRLF)
   FileWrite("url.txt", $var4 & @CRLF)
   FileWrite("url.txt", $var5 & @CRLF)

will i have to creat a GUI with 3 buttons and give them a value of say, click NEXT will repeat with +1 to the variable and click FINISH will end the script??

thanks in advance for any help !!

regards,

NiitriiX

Link to comment
Share on other sites

  • Moderators

Hi, NiitriiX, welcome to the forum. You could do something like this to loop through the Inputboxes. This would allow you to easily add more at some point if you would like.

Local $var[5]

For $element in $var
  $x = InputBox("Your Link....", "1", "type the url here", "", 500, 100)
  FileWrite("url.txt", $x & @CRLF)
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanx for the reply JLogan3o13,

i just tried this and it works but it only allows for a max of 5 inputs, and even if cancel is clicked another input box opens until the 5 variables have been used.

ok so sometimes i will need to add maybe 20 links and sometimes only 2 or 3... is their a way of doing this?

Edited by NiitriiX
Link to comment
Share on other sites

  • Moderators

To change the number, just change the first line. You can also catch the @error if you would like to stop when someone clicks Cancel.

Local $var[15]

For $element in $var
  $x = InputBox("Your Link....", "1", "type the url here", "", 500, 100)
  If @error Then ExitLoop
  FileWrite("url.txt", $x & @CRLF)
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Put the @error right where I have it in post #5 above. If someone clicks cancel, it will exit out of the For loop. If you have more code after the For loop, THAT will continue to process. If not, the script will end. Alternatively, if you do not know how many url's you will capture each time, do a While instead of a For loop:

While 1
 
$x = InputBox("Your Link....", "1", "type the url here", "", 500, 100)
  If @error Then ExitLoop
FileWrite("url.txt", $x & @CRLF)
 
WEnd

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Here's another way of doing it. I don't get how FileWrite is working, it's not used correctly. Unless you have more code that has the FileOpen and FileClose commands.

$file = FileOpen("url.txt", 1)
While 1
    $var = InputBox("Your Link....", "Type the url here", "type the url here", "", 500, 150)
    Sleep(10)
    FileWrite($file, $var & @CRLF)
    Sleep(10)
    If MsgBox(36, "", "Do it again?") = 7 Then ExitLoop ; 36 adds yes and no buttons, the no button = 7
WEnd
FileClose($file)

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

I don't get how FileWrite is working, it's not used correctly. Unless you have more code that has the FileOpen and FileClose commands.

From the help file for FileWrite

If a filename is given rather than a file handle, the file will be opened and closed during the function call. For parsing large text files this will be much slower than using filehandles. However, filename will be created if it does not already exist.

For small files like this, not using FileOpen/FileClose shouldn't affect the speed much.

BTW. With an InputBox, it's going to pause the script until it is processed or closed so there's no need to sleep the loop.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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