Jump to content

Scripting issue...


DJI
 Share

Recommended Posts

Hi, I've started writing a script with autoit v3 and Gui... I'm very good at this but i have solved most of my problems on my own yet. But now theres 2 things i totally dont know how to do. ;)

First thing is... Let say i have a gui window and all my things

I have a menu on the top and a menu item. It all works great up to now...

After in the while 1 place i have the things that happen depending on what i click in the menu

Now lets say 1 is : If $msg = $connectitem then msgbox(blablablabla).

Now this also works great.

But what if i want to make it execute many tasks, for example.

If $msg = $connectitem then msgbox(blablablabla)+sleep(1500)+splashtexton(blablabla)+sleep(2000)...

now if i do that all on the same line it doesnt work... program jams

And if i use seperate lines for each other execution, it starts running as soon as the program starts without me not doing anything...

So basicly i'm trying to figure out how can i do "If $msg =xxxx Then" do many diffrent tasks...

----------------------

My second question is:

How can i make the program execute another program that is located in the same folder.

Ex: i have program1.exe running and when i click someone where it does Run(/????.exe????)

How do i make the program execute a certain program that is located in the same folder... what i mean is

program A, located in C:\test1\

How can i make it run program B located aswell in C:\test1\....

Something like Run("/%current-dir%/programb.exe")... i dont know

So that's it... It's gotta be simple but i just don't know how....

THank you SO MUCH for your help and time! :lmao:

Link to comment
Share on other sites

Break the if/then statement into lines.

If $msg = $connectitem Then

; all the lines of code

EndIf

Ok, let program 1 be $Prog1 = "C:\test1\test1.exe"

and program 2 be $Prog2 = "C:\test1\test2.exe"

Then it's simply: Run ($Prog1) and Run ($Prog2)

If you know for certain that another program is going to be in the same directory as the script, you can use

@ScriptDir & "\program.exe" <--- if there are spaces, make sure you add quotes around the scriptdir.

Like this: Run ('"' & @ScriptDir & '"' & "\program.exe"). Note that that is ' " ', not " "

Edited by greenmachine
Link to comment
Share on other sites

But what if i want to make it execute many tasks, for example.

If $msg = $connectitem then msgbox(blablablabla)+sleep(1500)+splashtexton(blablabla)+sleep(2000)...

now if i do that all on the same line it doesnt work... program jams

And if i use seperate lines for each other execution, it starts running as soon as the program starts without me not doing anything...

Maybe you meant something more complex, but and 'If' ends with an 'EndIf' and there can be any number of lines between (don't forget the 'Then' statement):

If $msg = $ConnectItem Then
     $x = $n
     $y = $b
     $z = ($x + $y)/3
     MsgBox(32, "Answer", "The answer is: " & $z)
EndIf

How can i make the program execute another program that is located in the same folder.

Ex: i have program1.exe running and when i click someone where it does Run(/????.exe????)

How do i make the program execute a certain program that is located in the same folder... what i mean is

program A, located in C:\test1\

How can i make it run program B located aswell in C:\test1\....

Something like Run("/%current-dir%/programb.exe")... i dont know

So that's it... It's gotta be simple but i just don't know how....

THank you SO MUCH for your help and time! :lmao:

You run external programs with the Run() program:

$Command = "ProgB.exe"
Run(@ComSpec & " /c " & @ScriptDir & "\" & $Command, @TempDir)

The macro @ComSpec is the ComSpec from the windows environment. The macro @ScriptDir is the folder you ran the script from, and the macro @TempDir is the temp directory (as working directory in this example). The help file makes it pretty plain. One thing I have found usefull when things don't work on this is to use " /k " instead of " /c ", which leaves the cmd shell open after it's done so you can read the errors that might have happened.

If you want more help, you ought to post your code so we can see what's up.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Break the if/then statement into lines.

If $msg = $connectitem Then

; all the lines of code

EndIf

Ok, let program 1 be $Prog1 = "C:\test1\test1.exe"

and program 2 be $Prog2 = "C:\test1\test2.exe"

Then it's simply: Run ($Prog1) and Run ($Prog2)

If you know for certain that another program is going to be in the same directory as the script, you can use

@ScriptDir & "\program.exe" <--- if there are spaces, make sure you add quotes around the scriptdir.

Like this: Run ('"' & @ScriptDir & '"' & "\program.exe"). Note that that is ' " ', not " "

actually if you use the Select...Case structure as in the help file, it makes the program more readable, and also saves lines depending on how many cases...

Select
Case $msg = $blah
;do something
;do something else
;do one more thing
Case $msg = $blah2
;do a different thing
;do another different thing
;do one last different thing
EndSelect
Link to comment
Share on other sites

actually if you use the Select...Case structure as in the help file, it makes the program more readable, and also saves lines depending on how many cases...

Select
Case $msg = $blah
;do something
;do something else
;do one more thing
Case $msg = $blah2
;do a different thing
;do another different thing
;do one last different thing
EndSelect
Well if you're going to do it that way, why not use a Switch structure?

Switch $msg
Case $blah
;do something
;do something else
;do one more thing
Case $blah2
;do a different thing
;do another different thing
;do one last different thing
EndSwitch
Link to comment
Share on other sites

Well if you're going to do it that way, why not use a Switch structure?

Switch $msg
Case $blah
;do something
;do something else
;do one more thing
Case $blah2
;do a different thing
;do another different thing
;do one last different thing
EndSwitch
you could, but switch is best when the case isn't as specific as a select, like if you want the same thing done for a range of possible values.

Switch $Grade
case 94 to 100
$lettergrade = "A"
Case 87 to 93
$lettergrade = "B"
Case 80 to 86
$lettergrade = "C"
Case Else
$response = "retake the test"
EndSwitch
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...