Noviceatthis Posted May 12, 2013 Share Posted May 12, 2013 (edited) Hello all I wrote this a little while back and iv just noticed it has a problem: expandcollapse popupIf Not FileExists("C:\Program Files (x86)\AutoIt3\AutoIt3.exe") Then MsgBox(0, "", "You Must have AutoIt Software Installed to run this Program") Exit EndIf #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1_1 = GUICreate("AutoIt Command Prompt", 617, 306, 257, 129) GUISetBkColor(0xC0C0C0) $Label1 = GUICtrlCreateLabel("AutoIt Command Prompt", 8, 8, 598, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 18, 800, 4, "MS Sans Serif") GUICtrlSetBkColor(-1, 0x99B4D1) $Input1 = GUICtrlCreateInput("", 8, 144, 601, 28) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Enter Commands below:", 8, 56, 212, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0x99B4D1) $Button1 = GUICtrlCreateButton("Execute", 8, 192, 601, 57) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Help", 8, 264, 601, 33) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Button3 = GUICtrlCreateButton("Include", 48, 96, 209, 33) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("", 272, 97, 332, 30, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xF0F0F0) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### $file = @AppDataDir & "\command.au3" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE FileDelete($file) Exit Case $Button3 While 1 $dialg = FileOpenDialog("Choose include file", "C:\Program Files (x86)\AutoIt3\Include", "AutoIt Files (*.au3)") If @error = 1 Then ExitLoop EndIf $dialge = StringSplit($dialg, "\") $dialg1 = $dialge[5] FileOpen(@AppDataDir & "\command.au3", 2) FileWriteLine(@AppDataDir & "\command.au3", "#include <" & $dialg1 & ">") FileClose(@AppDataDir & "\command.au3") GUICtrlSetData($Label3, $dialg1) ExitLoop WEnd Case $Button1 $command = GUICtrlRead($Input1) $file = @AppDataDir & "\command.au3" FileOpen(@AppDataDir & "\command.au3", 1) FileWriteLine($file, $command) FileClose($file) GUICtrlSetData($Input1, "") GUICtrlSetData($Label3, "") ShellExecute($file) Sleep(1000) FileDelete(@AppDataDir & "\command.au3") Case $Button2 If FileExists("C:\Program Files (x86)\AutoIt3\AutoIt3.chm") Then ShellExecute("C:\Program Files (x86)\AutoIt3\AutoIt3.chm") Else ShellExecute("http://www.autoitscript.com/wiki/Function_list") EndIf EndSwitch WEnd running a command upon opening the script is fine, but when a second command is entered a message pops up saying Error opening file. How do I resolve this?? Thanks in advance Edited May 12, 2013 by Noviceatthis Link to comment Share on other sites More sharing options...
kylomas Posted May 12, 2013 Share Posted May 12, 2013 Noviceatthis, I change the file routine for button1 to use a file handle and it seems to work. You might want to use this wherever you open/write/close the file. expandcollapse popupIf Not FileExists("C:\Program Files (x86)\AutoIt3\AutoIt3.exe") Then MsgBox(0, "", "You Must have AutoIt Software Installed to run this Program") Exit EndIf #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1_1 = GUICreate("AutoIt Command Prompt", 617, 306, 257, 129) GUISetBkColor(0xC0C0C0) $Label1 = GUICtrlCreateLabel("AutoIt Command Prompt", 8, 8, 598, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 18, 800, 4, "MS Sans Serif") GUICtrlSetBkColor(-1, 0x99B4D1) $Input1 = GUICtrlCreateInput("", 8, 144, 601, 28) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Enter Commands below:", 8, 56, 212, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0x99B4D1) $Button1 = GUICtrlCreateButton("Execute", 8, 192, 601, 57) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Help", 8, 264, 601, 33) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Button3 = GUICtrlCreateButton("Include", 48, 96, 209, 33) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("", 272, 97, 332, 30, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xF0F0F0) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### local $file = @AppDataDir & "\command.au3", $hfl While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE FileDelete($file) Exit Case $Button3 While 1 $dialg = FileOpenDialog("Choose include file", "C:\Program Files (x86)\AutoIt3\Include", "AutoIt Files (*.au3)") If @error = 1 Then ExitLoop EndIf $dialge = StringSplit($dialg, "\") $dialg1 = $dialge[5] FileOpen(@AppDataDir & "\command.au3", 2) FileWriteLine(@AppDataDir & "\command.au3", "#include <" & $dialg1 & ">") FileClose(@AppDataDir & "\command.au3") GUICtrlSetData($Label3, $dialg1) ExitLoop WEnd Case $Button1 $command = GUICtrlRead($Input1) $file = @AppDataDir & "\command.au3" $hfl = FileOpen(@AppDataDir & "\command.au3", 1) FileWriteLine($hfl, $command) FileClose($hfl) GUICtrlSetData($Input1, "") GUICtrlSetData($Label3, "") ShellExecute($file) Sleep(1000) FileDelete(@AppDataDir & "\command.au3") Case $Button2 If FileExists("C:\Program Files (x86)\AutoIt3\AutoIt3.chm") Then ShellExecute("C:\Program Files (x86)\AutoIt3\AutoIt3.chm") Else ShellExecute("http://www.autoitscript.com/wiki/Function_list") EndIf EndSwitch WEnd kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Noviceatthis Posted May 12, 2013 Author Share Posted May 12, 2013 I see, thanks kylomas 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