Jump to content

Function that takes code as parameter?


kzar
 Share

Recommended Posts

No I don't meen run a executable or somthing. In your example you pass sample a string containing the filename of the program you would like to execute. I would like it to actually treat the string as autoit code and run it.

Link to comment
Share on other sites

Cool thanks thats what I was after. I was trying to cut out code duplication in my scripts.

I have been using lod3n's idea from another topic to automate program installs reliably by looping through all the possible different windows there could be, handling them and waiting till they are gone:

run("installer.exe")
  while 1
   sleep(100)
  select
    case WinExists("Confirmation","Are you sure")
       ControlClick("Confirmation","Are you sure","Button2")
       While WinExists("Confirmation","Are you sure")
           sleep(100)
       wend
    case WinExists("Installation Complete","Installation completed succ")
        ControlClick("Installation Complete","Installation completed succ","Button1")
        While WinExists("Installation Complete","Installation completed succ")
           sleep(100)
       wend
       exitloop
   endselect
wend
exit

So here is what I have got so far, I get an error on line 4 I think because I have a string going over several lines. Anyway my question is am I on the right track here or would you do it a different way? I am trying to make reliable installer automation scripts that are as neat as possible with little duplicated code.

; This If statement would be a case in a select inside a loop normaly
If WinExists("Example window", "Welcome to the example program blah blah") Then
  HandleWin("Confirmation","Are you sure", 
          "Example window", "Welcome to the example program blah blah",
          "MsgBox(0, 'Huray', 'it worked!')
           MsgBox(0, 'Huray', 'And this!')")
EndIf

Func HandleWin($title, $text, $commands)
; Split up the commands and count
     $command = StringSplit($commands, '\n', 1)
     $commandCount = UBound($command)

; Loop through commands and execute them
     For $i = 0 to $commandCount Step +1
         Execute($command[$i])
     Next

; Wait for window to close
     While WinExists($title,$text)
           sleep(100)
     wend
     Return $value
EndFunc

Thanks

Edited by kzar
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...