DarkAngel Posted June 13, 2010 Share Posted June 13, 2010 i am new to autoit..is there a way by which we can compile and run a snippet of a code from a larger code by executing the larger code?? For example if there is 10 lines in the main code and wen i execute it i want a part of the code form it to form a sub smaller code...and then i want to execute the smaller code..please help. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 13, 2010 Developers Share Posted June 13, 2010 Your question is as clear as mud to me. Gives us a simple example where/how you want to use it. 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. Link to comment Share on other sites More sharing options...
DarkAngel Posted June 14, 2010 Author Share Posted June 14, 2010 Your question is as clear as mud to me. Gives us a simple example where/how you want to use it. Well lets suppose i am creating an utility script for say 1>removing temp files from the temp folder b>for doing job 2...now as far as i can code..i write the whole stuff in a single script and compile it to an exe,, now suppose i want the snippet (1),which is a subcode..to be a new independent piece of code..Like when i run the exe ..i want that snippet of code to be extracted/copied from the main program and be created into a separate existence so that now we have two codes..In vbs this can be done(i suppose with procreatecopy i am not sure)..how to dio that in autoit?? plz help / Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 14, 2010 Share Posted June 14, 2010 There are two fairly simple ways of doing something similar. 1. you can write 2 seperate codes and compile them to exe. At the end of the first code you can have a Gui asking if they wish to proceed to 2nd job. Then have the first app run the 2nd app and close. 2. write 2 seperate codes and use fileinstall to include the 2nd script in the first and extract when called. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
DarkAngel Posted June 14, 2010 Author Share Posted June 14, 2010 There are two fairly simple ways of doing something similar.1. you can write 2 seperate codes and compile them to exe. At the end of the first code you can have a Gui asking if they wish to proceed to 2nd job.Then have the first app run the 2nd app and close.2. write 2 seperate codes and use fileinstall to include the 2nd script in the first and extract when called.Hmmm...that seems simple enuf...bt still..can u give a simple code as an example..i find it easier to learn that way..and as for the gui..i guess silent install can also be performed..newaz thanks a ton and plz try and give an example..wud find it easier to learn.. Link to comment Share on other sites More sharing options...
James Posted June 14, 2010 Share Posted June 14, 2010 DarkAngel, Snippet1() Snippet2() Func Snippet1() MsgBox(0, @ScriptName, "This is snippet 1") EndFunc Func Snippet2() MsgBox(0, @ScriptName, "This is snippet 2") EndFunc Hope that helps. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
DarkAngel Posted June 14, 2010 Author Share Posted June 14, 2010 DarkAngel, Snippet1() Snippet2() Func Snippet1() MsgBox(0, @ScriptName, "This is snippet 1") EndFunc Func Snippet2() MsgBox(0, @ScriptName, "This is snippet 2") EndFunc Hope that helps. Hey thats really simple..i never thot of implementing this..thanks a ton.. I have another question..can a snippet be compiled to an exe from the body of the main script?? like wen the funtion 2 is called is there any way of compiling that part and making it a new independent exe?? Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 14, 2010 Share Posted June 14, 2010 For the GUI example, this would be script 1 (compiled to exe) expandcollapse popup#include <GUIConstantsEx.au3> Run("notepad.exe") WinWait("[CLASS:Notepad]") ControlSend("[CLASS:Notepad]", "", "Edit1", "This is a line of text in the notepad window") $count=5 GUICreate("Continue?",200,80) $ok=GUICtrlCreateButton("OK",10,20) $stop=GUICtrlCreateButton("End",40,20) $timer=GUICtrlCreateLabel($count,25,55) GUISetState(@SW_SHOW) $start=TimerInit() While 1 $msg=GUIGetMsg() $diff=TimerDiff($start) If $diff>1000 Then $start=TimerInit() $count-=1 GUICtrlSetData($timer,$count) EndIf If $count<1 Then Run(@ScriptDir&"\script2.exe") Exit(1) EndIf If $msg=$ok Then Run(@ScriptDir&"\script2.exe") Exit(1) ElseIf $msg=$stop Then Exit(1) ElseIf $msg=$GUI_EVENT_CLOSE Then Exit(1) EndIf WEnd Then you would have a 2nd compiled exe (named script2.exe and in the same location as script1) ControlSend("[CLASS:Notepad]", "", "Edit1", @CRLF&"This is a line from the 2nd script") Exit(1) 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
DarkAngel Posted June 14, 2010 Author Share Posted June 14, 2010 DarkAngel, Snippet1() Snippet2() Func Snippet1() MsgBox(0, @ScriptName, "This is snippet 1") EndFunc Func Snippet2() MsgBox(0, @ScriptName, "This is snippet 2") EndFunc Hope that helps. Hey thats really simple..i never thot of implementing this..thanks a ton.. I have another question..can a snippet be compiled to an exe from the body of the main script?? like wen the funtion 2 is called is there any way of compiling that part and making it a new independent exe?? Link to comment Share on other sites More sharing options...
DarkAngel Posted June 14, 2010 Author Share Posted June 14, 2010 kewl..lemme try with my piece of codes.. Link to comment Share on other sites More sharing options...
DarkAngel Posted June 14, 2010 Author Share Posted June 14, 2010 kewl..lemme try with my piece of codes.. can additional files be added with the compiled source code to make a single standalone exe??like we do in sfx..anythng similar can be done in autoit?? Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 14, 2010 Share Posted June 14, 2010 This is program 1 with some modifications. First, if you compile the 2nd script here and name it script2.exe, when compiling this script, it will include script2.exe inside of it. Also, it will open, write to, save and close notepad. expandcollapse popup#include <GUIConstantsEx.au3> Run("notepad.exe " &@ScriptDir&"\test.txt") WinWait("[CLASS:Notepad]") Sleep(500) If WinExists("Notepad", "") Then ControlClick("Notepad", "&Yes", "[CLASS:Button;INSTANCE:1]", "LEFT", 1) EndIf ControlSend("[CLASS:Notepad]", "", "Edit1", "This is a line of text in the notepad window") Sleep(500) $logo = WinExists("[CLASS:Notepad]") While $logo = 1 $logo = WinExists("[CLASS:Notepad]") WinClose("[CLASS:Notepad]", "") Sleep(1000) If WinExists("Notepad", "Do you want to save") Then ControlSend("Notepad", "Do you want to save", "[CLASS:Button; INSTANCE:1]", "{ENTER}") EndIf Sleep(1000) $logo = WinExists("[CLASS:Notepad]") WEnd $count=5 FileInstall(@ScriptDir&"\script2.exe",@ScriptDir&"\script2.exe");this line includes the 2nd exe in the first exe GUICreate("Continue?",200,80) $ok=GUICtrlCreateButton("OK",10,20) $stop=GUICtrlCreateButton("End",40,20) $timer=GUICtrlCreateLabel($count,25,55) GUISetState(@SW_SHOW) $start=TimerInit() While 1 $msg=GUIGetMsg() $diff=TimerDiff($start) If $diff>1000 Then $start=TimerInit() $count-=1 GUICtrlSetData($timer,$count) EndIf If $count<1 Then Run(@ScriptDir&"\script2.exe") Exit(1) EndIf If $msg=$ok Then Run(@ScriptDir&"\script2.exe") Exit(1) ElseIf $msg=$stop Then Exit(1) ElseIf $msg=$GUI_EVENT_CLOSE Then Exit(1) EndIf WEnd script2 will be extracted by script1 and can be run on it's own or by the end part of script1. it also openes the txt file created by the first script, or creates a new one if it is not there, writes to it, saves and closes it. Run("notepad.exe " &@ScriptDir&"\test.txt") WinWait("[CLASS:Notepad]") Sleep(500) If WinExists("Notepad", "") Then ControlClick("Notepad", "&Yes", "[CLASS:Button;INSTANCE:1]", "LEFT", 1) EndIf ControlSend("[CLASS:Notepad]", "", "Edit1", "This is a line from the 2nd script"&@CRLF) Sleep(500) $logo = WinExists("[CLASS:Notepad]") While $logo = 1 $logo = WinExists("[CLASS:Notepad]") WinClose("[CLASS:Notepad]", "") Sleep(1000) If WinExists("Notepad", "Do you want to save") Then ControlSend("Notepad", "Do you want to save", "[CLASS:Button; INSTANCE:1]", "{ENTER}") EndIf Sleep(1000) $logo = WinExists("[CLASS:Notepad]") WEnd 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
DarkAngel Posted June 15, 2010 Author Share Posted June 15, 2010 k...i did the file install with .txt and some .vbs files..it works...the soundplay function plays a sound from a specific location..is it possible to include that sound in the main program while compiling..??? so that the standalone .exe is portable and when executed from any machine that sound file wud play??...same for the splash screen...can the sound n the image files be included in the same exe,instead of making a separate resource folder,then extracting it to a temp n then playing the file from there...can the whole thing be self contained?? Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 15, 2010 Share Posted June 15, 2010 You can fileinstall as many files as you like (I have yet to hit a limit) 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
DarkAngel Posted June 15, 2010 Author Share Posted June 15, 2010 hmmm..k but pray help me with the splash screen and the sound file thing..i want to include both in the standalone exe..for details plz see my last post Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 15, 2010 Share Posted June 15, 2010 for each file you want to include, you need a new fileinstall line. What you can do is at the beginning of your main script extract those files to a temp dir to be played/used when needed and filedelete when done. There are other ways (someone wrote a UDF that would use included files without extracting them) that can be found with a forum search. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
DarkAngel Posted June 15, 2010 Author Share Posted June 15, 2010 for each file you want to include, you need a new fileinstall line. What you can do is at the beginning of your main script extract those files to a temp dir to be played/used when needed and filedelete when done.There are other ways (someone wrote a UDF that would use included files without extracting them) that can be found with a forum search.Hmmm i use the temp extraction ad filedelete..i told u bout taht.. but i want to include it in the main func..maybe the udf u told bout may help...can u gimme the thread to it?? Link to comment Share on other sites More sharing options...
DarkAngel Posted June 15, 2010 Author Share Posted June 15, 2010 mind if i ask u sumthng? how old are u man?? I mean u people have the answer to every thing..kewl i feel so silly asking my stupid questions Link to comment Share on other sites More sharing options...
Developers Jos Posted June 15, 2010 Developers Share Posted June 15, 2010 mind if i ask u sumthng? how old are u man?? I mean u people have the answer to every thing..kewl i feel so silly asking my stupid questions Click on the member name to show the profile where you can find the date of birth when people want to share it.As to the knowledge bit: It is just a matter of investing time in research, trial and error and patience. 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. Link to comment Share on other sites More sharing options...
DarkAngel Posted June 15, 2010 Author Share Posted June 15, 2010 Click on the member name to show the profile where you can find the date of birth when people want to share it.As to the knowledge bit: It is just a matter of investing time in research, trial and error and patience. JosWell jos .. i am just 4 days old in autoit3 .. the only experiences i have in scripting is in vbs and batch.. and if research and patience is concerned then i wud like to say that the day i downloaded it i spent 18 hrs at a stretch behind the laptop trying to gulp in as much as i could but u guys rock Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now