Lemonsun Posted January 7, 2007 Posted January 7, 2007 I am new for autoit . I liked this tool. and the tools provided by Members like Big Daddy.(easy to,learn and use ) here is my code : CODE#include <Word.au3> _WordErrorHandlerRegister() If $CmdLine[0] = 0 Then ; No command line parameters MsgBox(64, "Testing", "No commandline parameters used.") ElseIf $CmdLine[1] = "/myword" Then $sFilePath = FileOpenDialog("Open Word File", @ScriptDir, "Word Doc (*.Doc)") If @error Then MsgBox(4096,"Process Interrupted ", " Process Interrupted by user /System Error ! ") Else $sText1 = InputBox("your name", "Write yourname : ", "", "", _ -1, -1, 0, 0) $sText2 = "." $oWordApp = _WordCreate($sFilePath, 0, 0) $oDoc = $oWordApp.ActiveDocument $oRng1 = $oDoc.Range $oRng1.InsertAfter ($sText1) $iEnd = $oRng1.End $oRng2 = $oDoc.Range($iEnd-StringLen($sText1), $iEnd) $oRng2.Font.Bold = True $oRng2.InsertAfter ($sText2) $iEnd = $oRng2.End $oRng3 = $oDoc.Range($iEnd-StringLen($sText2), $iEnd) $oRng2.Font.Bold = False _WordDocSave($oDoc) _WordQuit($oWordApp) endif endif I compiled this application and run it from command line like this : forum.exe /myword ...works ok Question : Now I want to get the variable $sText1 from the command line as second parameter probably like this forum.exe /myword Greg >> greg is value which must be passed to the script as variable $sText1 , and as a second parameter . How can i accomplish that ... I am messing here ....? I read the manual . but , it seems i did not get it ....??
Xenobiologist Posted January 7, 2007 Posted January 7, 2007 Hi, check the $cmdline[0] whehter it is greater than 1 and then do $sText1 = $cmdline[2] So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Lemonsun Posted January 7, 2007 Author Posted January 7, 2007 Hi, check the $cmdline[0] whehter it is greater than 1 and then do $sText1 = $cmdline[2] So long, Mega would you please show me the changes to be made in my script ?
Xenobiologist Posted January 7, 2007 Posted January 7, 2007 Hi, maybe something like this helps you out: Switch $CmdLine[0] Case 0 MsgBox(64, "Testing", "No commandline parameters used.") Case 1 If $CmdLine[1] = "/myword" Then _Do() Case 2 Global $sText1 = $CmdLine[2] EndSwitch MsgBox(0, "", $sText1) Func _Do() ; your code EndFunc ;==>_Do So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Lemonsun Posted January 7, 2007 Author Posted January 7, 2007 Hi ! here is my modifid code with the switch of yours : expandcollapse popup#include <Word.au3> _WordErrorHandlerRegister() Switch $CmdLine[0] Case 0 MsgBox(64, "Testing", "No commandline parameters used.") Case 1 If $CmdLine[1] = "/myword" Then _Do() Case 2 Global $sText1 = $CmdLine[2] EndSwitch MsgBox(0, "", $sText1) Func _Do() $sFilePath = FileOpenDialog("Open Word File", @ScriptDir, "Word Doc (*.Doc)") If @error Then MsgBox(4096,"Process Interrupted ", " Process Interrupted by user /System Error ! ") Else $sText1 = InputBox("your name", "Write yourname : ", "", "", _ -1, -1, 0, 0) $sText2 = "." $oWordApp = _WordCreate($sFilePath, 0, 0) $oDoc = $oWordApp.ActiveDocument $oRng1 = $oDoc.Range $oRng1.InsertAfter ($sText1) $iEnd = $oRng1.End $oRng2 = $oDoc.Range($iEnd-StringLen($sText1), $iEnd) $oRng2.Font.Bold = True $oRng2.InsertAfter ($sText2) $iEnd = $oRng2.End $oRng3 = $oDoc.Range($iEnd-StringLen($sText2), $iEnd) $oRng2.Font.Bold = False _WordDocSave($oDoc) _WordQuit($oWordApp) endif EndFunc ;==>_Do i run the compiled script forum.exe /myword myname >>>> dont work what i am trying to do is to get " Myname " from the command line and assign it to $sText1 . to get rid of the dialog ! thanks for your help .
Xenobiologist Posted January 7, 2007 Posted January 7, 2007 Hi, try this: #include <Word.au3> _WordErrorHandlerRegister () Switch $CmdLine[0] Case 0 MsgBox(64, "Testing", "No commandline parameters used.") Case 1 Global $sText1 = "Unknown" If $CmdLine[1] = "/myword" Then _Do() Case 2 Global $sText1 = $CmdLine[2] If $CmdLine[1] = "/myword" Then _Do() EndSwitch Func _Do() $sFilePath = FileOpenDialog("Open Word File", @ScriptDir, "Word Doc (*.Doc)") If @error Then MsgBox(4096, "Process Interrupted ", " Process Interrupted by user /System Error ! ") Else $sText2 = "." $oWordApp = _WordCreate ($sFilePath, 0, 0) $oDoc = $oWordApp.ActiveDocument $oRng1 = $oDoc.Range $oRng1.InsertAfter ($sText1) $iEnd = $oRng1.End $oRng2 = $oDoc.Range ($iEnd - StringLen($sText1), $iEnd) $oRng2.Font.Bold = True $oRng2.InsertAfter ($sText2) $iEnd = $oRng2.End $oRng3 = $oDoc.Range ($iEnd - StringLen($sText2), $iEnd) $oRng2.Font.Bold = False _WordDocSave ($oDoc) _WordQuit ($oWordApp) EndIf EndFunc ;==>_Do So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Lemonsun Posted January 7, 2007 Author Posted January 7, 2007 Hi, try this: #include <Word.au3> _WordErrorHandlerRegister () Switch $CmdLine[0] Case 0 MsgBox(64, "Testing", "No commandline parameters used.") Case 1 Global $sText1 = "Unknown" If $CmdLine[1] = "/myword" Then _Do() Case 2 Global $sText1 = $CmdLine[2] If $CmdLine[1] = "/myword" Then _Do() EndSwitch Func _Do() $sFilePath = FileOpenDialog("Open Word File", @ScriptDir, "Word Doc (*.Doc)") If @error Then MsgBox(4096, "Process Interrupted ", " Process Interrupted by user /System Error ! ") Else $sText2 = "." $oWordApp = _WordCreate ($sFilePath, 0, 0) $oDoc = $oWordApp.ActiveDocument $oRng1 = $oDoc.Range $oRng1.InsertAfter ($sText1) $iEnd = $oRng1.End $oRng2 = $oDoc.Range ($iEnd - StringLen($sText1), $iEnd) $oRng2.Font.Bold = True $oRng2.InsertAfter ($sText2) $iEnd = $oRng2.End $oRng3 = $oDoc.Range ($iEnd - StringLen($sText2), $iEnd) $oRng2.Font.Bold = False _WordDocSave ($oDoc) _WordQuit ($oWordApp) EndIf EndFunc ;==>_Do So long, Mega Thanks ....Mega ! why the following switch is not working ? for the third paramer assigning the third variable ?? Switch $CmdLine[0] Case 0 MsgBox(64, "Testing", "No commandline parameters used.") Case 1 Global $sText1 = " " If $CmdLine[1] = "/myword" Then _Do() Case 2 Global $sText1 = $CmdLine[2] If $CmdLine[1] = "/myword" Then _Do() Case 3 Global $sText2 = $CmdLine[3] If $CmdLine[1] = "/myword" Then _Do() EndSwitch
Lemonsun Posted January 7, 2007 Author Posted January 7, 2007 Thanks ....Mega ! why the following switch is not working ? for the third paramer assigning the third variable ?? Switch $CmdLine[0] Case 0 MsgBox(64, "Testing", "No commandline parameters used.") Case 1 Global $sText1 = " " If $CmdLine[1] = "/myword" Then _Do() Case 2 Global $sText1 = $CmdLine[2] If $CmdLine[1] = "/myword" Then _Do() Case 3 Global $sText2 = $CmdLine[3] If $CmdLine[1] = "/myword" Then _Do() EndSwitch Everything is clear now and resolved !
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