Guest Doxie Posted June 18, 2004 Share Posted June 18, 2004 Is it possible to have two action on one "Then"?Below you can see the string that is working:If $compare1 >= $compare2 Then Run ($File, "",)I would like to add this:IniWrite($UserName, "Options", "Count", "Yes")So it would look like this:If $compare1 >= $compare2 Then Run ($File, "",) & IniWrite($UserName, "Options", "Count", "Yes")Should i use the "&" between the strings?Anyway, its not working with or without it Thanks in advance Link to comment Share on other sites More sharing options...
Guest Doxie Posted June 18, 2004 Share Posted June 18, 2004 Its working partly with that... If $Action = "Yes" Then Run ($File, "",) If $Action = "No" Then IniWrite($UserName, "Options", "Count", "3")If $compare1 <= $compare2 Then Run ($File, "",) IniWrite($UserName, "Options", "Count", "Yes")EndIfIf $count = "3" Then IniWrite ($UserName, "Options", "Count", "2")If $count = "2" Then IniWrite ($UserName, "Options", "Count", "1")If $count = "1" Then IniWrite ($UserName, "Options", "Count", "0")If $count = "0" Then Run ($File, "",) IniWrite($UserName, "Options", "Count", "Yes")EndIfThe thing in bold above is the one i changed.When the count is 0, it change to Yes in the .ini file but if the file is running because of date compare (wich is working) is does not add the Yes in the ini? Link to comment Share on other sites More sharing options...
CyberSlug Posted June 18, 2004 Share Posted June 18, 2004 If the ini file is open by another process/application--or if the ini file is read-only--then the IniWrite will fail. You can check the return value of IniWrite to see if the update failed; 1=success, 0=failure. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Developers Jos Posted June 18, 2004 Developers Share Posted June 18, 2004 (edited) Its working partly with that...When the count is 0, it change to Yes in the .ini file but if the file is running because of date compare (wich is working) is does not add the Yes in the ini?You could use RunWait in stead of Run or do the IniWrite first. Edited June 18, 2004 by JdeB 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...
Guest Guest Posted June 19, 2004 Share Posted June 19, 2004 At the top of the script i got this: If FileExists($Finished) Then Exit Else EndIf;Some GUI scripting here....Func Processing() Global $UserName = $SD & "Users\"&@UserName&".ini" Global $count = IniRead($UserName, "Options", "Count", "") Global $day = IniRead($ConfigINI, "Options", "Day", "") Global $month = IniRead($ConfigINI, "Options", "Month", "") Global $year = IniRead($ConfigINI, "Options", "Year", "") Global $compare1 = ($day) + (($month - 1) * 30) + ($year * 360) Global $compare2 = (@MDAY) + ((@MON - 1) * 30) + (@YEAR * 360) Global $Check = IniRead($UserName, "Options", "Count", "") If $Action = "Yes" Then Run ($File, "",) If $Action = "No" Then IniWrite($UserName, "Options", "Count", "3") If $compare1 <= $compare2 Then IniWrite($UserName, "Options", "Count", "Yes") RunWait ($File, "",) EndIf If $count = "3" Then IniWrite ($UserName, "Options", "Count", "2") If $count = "2" Then IniWrite ($UserName, "Options", "Count", "1") If $count = "1" Then IniWrite ($UserName, "Options", "Count", "0") If $count = "0" Then IniWrite($UserName, "Options", "Count", "Yes") RunWait ($File, "",) EndIf If $Check = "Yes" Then FileMove($UserName, $Finished)EndFuncAs you can see, it should rename the .INI file to .DONE if the file has runned.But its only working after i run the au3 file twice. Like its not reading the "If $Check..." on first run. I also tried to add the blue line above the red at the top of the script, but then it run the whole script anyway. Next time i try to run the script, its working as it should. Link to comment Share on other sites More sharing options...
Guest Doxie Posted June 19, 2004 Share Posted June 19, 2004 I add the whole script, so you guys can get an idea of what i'm doing. *************Save as Config.au3**************** ;Author: Marcus Sundberg ;E-Mail: sundberg_marcus_nonlilly@lilly.com ; ;Made with AutoIt v3.0 (Build 102) Beta: ;http://www.autoitscript.com/autoit3/files/unstable/autoit/ $g_szVersion = "Script" If WinExists($g_szVersion) Then MsgBox(4096,"", "Its already running") Exit ; It's already running EndIf AutoItWinSetTitle($g_szVersion) #include <GUIConstants.au3> Init() Config() Exit Func Init() Global $SD = @ScriptDir & "\" Global $ProgTitel = "Config for Patch" Global $ConfigINI = $SD & "Config.ini" Global $FileErr = 0 Global $TargetErr = 0 Global $ViewerErr = 0 Global $MDirErr = 0 Global $FileList = "" Global $File = IniRead($ConfigINI, "Options", "File", "") Global $day = IniRead($ConfigINI, "Options", "Day", "") Global $month = IniRead($ConfigINI, "Options", "Month", "") Global $year = IniRead($ConfigINI, "Options", "Year", "") Global $search = FileFindFirstFile("*.*") Global $message = "Locate the patch file to be used." If FileExists($SD & "Config.ini") Then MsgBox(4096,"Eli Lilly","Configuration tool for patches.") Else IniWrite($ConfigINI, "Options", "Installed","Yes" ) DirCreate($SD & "Patches") DirCreate($SD & "Users") MsgBox(4096,"", "Move your patches to "&$SD &"Patches") EndIf EndFunc Func Config() GuiCreate($ProgTitel, 370,180) WinActivate($ProgTitel, "") GuiSetControl("label", "Patch File:", 10,10,260,15) $inpFile = GUISetControl("input", $File, 10,25,325,20) $butSource = GuiSetControl("button", "...", 335,25,25,20) GUISetControlFont(-1, 9, 800) GuiSetControlNotify() GuiSetControl("label", "Force to run on:", 10,50,170,15) GuiSetControl("label", "Day:", 10,65,170,15) $inpDay = GUISetControl("input", $day, 10,80,30,20) GuiSetControlEx(0,0,0, "Day") GuiSetControl("label", "Month:", 50,65,170,15) $inpMonth = GUISetControl("input", $month, 50,80,30,20) GuiSetControlEx(0,0,0, "Month") GuiSetControl("label", "Year:", 90,65,170,15) $inpYear = GUISetControl("input", $year, 90,80,30,20) GuiSetControlEx(0,0,0, "Year") $butSave = GuiSetControl("button", "Save", 190,140,80,25) GuiSetControlNotify() $butCancel = GuiSetControl("button", "Cancel", 280,140,80,25) GuiSetControlNotify() GuiShow() While 1 sleep(100) $Msg = GuiMsg(0) Select Case $Msg = -3 Exit Case $Msg = $butCancel ExitLoop Case $Msg = $butSource $newSource = FileOpenDialog($message, $SD &"Patches\", "Patch (*.exe;*.com;*.bat)", 1 + 4 ) If @error Then MsgBox(4096,"","No File(s) chosen") Else $var = StringReplace($var, "|", @CRLF) MsgBox(4096,"Patch","You chose " & $newSource) EndIf If $newSource <> 1 Then GuiWrite($inpFile, 0, $newSource) Case $Msg = $butSave $File = GuiRead($inpFile) $day = GuiRead($inpDay) $month = GuiRead($inpMonth) $year = GuiRead($inpYear) IniWrite($ConfigINI, "Options", "File", $File) IniWrite($ConfigINI, "Options", "Day", $day) IniWrite($ConfigINI, "Options", "Month", $month) IniWrite($ConfigINI, "Options", "Year", $year) ExitLoop EndSelect WEnd GuiDelete() EndFunc ******************************************* ************Save as Patch.au3**************** ;Author: Marcus Sundberg ;E-Mail: sundberg_marcus_nonlilly@lilly.com ; ;Made with AutoIt v3.0 (Build 102) Beta: ;http://www.autoitscript.com/autoit3/files/unstable/autoit/ $g_szVersion = "Script" If WinExists($g_szVersion) Then MsgBox(4096,"", "Its already running") Exit ; It's already running EndIf AutoItWinSetTitle($g_szVersion) #include <GUIConstants.au3> Init() Main() Processing() Exit Func Init() Opt("TrayIconHide", 1) Global $SD = @ScriptDir & "\" Global $ProgTitel = "Eli Lilly Patch Tool" Global $ConfigINI = $SD & "Config.ini" Global $PrgIcon16 = $SD & "Data\migration.ico" Global $PrgIcon32 = $SD & "Data\migration.ico" Global $UserName = $SD & "Users\"&@UserName&".ini" Global $count = IniRead($UserName, "Options", "Count", "3") Global $Check = IniRead($UserName, "Options", "Count", "") Global $FileErr = 0 Global $TargetErr = 0 Global $File = IniRead($ConfigINI, "Options", "File", "") Global $SourceDir = IniRead($ConfigINI, "Options", "SourceDir", "") Global $Patch = IniRead($ConfigINI, "Patch", "Version", "") Global $MainMsg = "You can say NO " &$Count &" time(s)." Global $Finished = $SD & "Users\"&@UserName&".DONE" EndFunc Func Main() If FileExists($Finished) Then Exit Else EndIf GuiCreate($ProgTitel, 190,90) WinActivate($ProgTitel, "") GuiSetControl("label", $MainMsg, 55,20,-1,15) GuiSetControl("icon", $PrgIcon32, 10,10) GuiSetControlEx(-1,128) $butMove = GuiSetControl("button", "Yes", 10,55,80,25,$BS_DEFPUSHBUTTON) $butCopy = GuiSetControl("button", "No", 100,55,80,25) GuiSetControlEx($butMove,$GUI_FOCUS) If $FileErr = 1 OR $TargetErr = 1 Then GuiSetControlEx($butMove,128) GuiSetControlEx($butCopy,128) EndIf GuiWaitClose() If GuiRead() = $butMove then Global $Action = "Yes" IniWrite($UserName, "Options", "Count", "Yes") Global $ActMsg = "Installing: " EndIf If GuiRead() = $butCopy then Global $Action = "No" Global $ActMsg = "Nothing: " EndIf EndFunc Func Processing() Global $UserName = $SD & "Users\"&@UserName&".ini" Global $count = IniRead($UserName, "Options", "Count", "") Global $day = IniRead($ConfigINI, "Options", "Day", "") Global $month = IniRead($ConfigINI, "Options", "Month", "") Global $year = IniRead($ConfigINI, "Options", "Year", "") Global $compare1 = ($day) + (($month - 1) * 30) + ($year * 360) Global $compare2 = (@MDAY) + ((@MON - 1) * 30) + (@YEAR * 360) If $Action = "Yes" Then Run ($File, "",) If $Action = "No" Then IniWrite($UserName, "Options", "Count", "2") If $compare1 <= $compare2 Then IniWrite($UserName, "Options", "Count", "Yes") RunWait ($File, "",) EndIf ; If $count = "3" Then IniWrite ($UserName, "Options", "Count", "2") If $count = "2" Then IniWrite ($UserName, "Options", "Count", "1") If $count = "1" Then IniWrite ($UserName, "Options", "Count", "0") If $count = "0" Then IniWrite($UserName, "Options", "Count", "Yes") RunWait ($File, "",) EndIf If $Check = "Yes" Then FileMove($UserName, $Finished) EndFunc ********************************************** Link to comment Share on other sites More sharing options...
Guest Guest Posted June 19, 2004 Share Posted June 19, 2004 Copy/Paste any .exe file to the new folder called Patches, so you can try the tool. Then run Patch.au3 three times and answer NO, on the fourth time, it should not work, but then it launch the program anyway and gimme message: "You can say NO Yes time(s)" Wich is strange, since it should not even start. Link to comment Share on other sites More sharing options...
Doxie Posted June 24, 2004 Share Posted June 24, 2004 What happend The script above worked perfectly when i copied it in here, and now its not working anymore. I tried the script on three different machines.I get the error:Line 83If $Action = "Yes" Then Run ($File, "",)If ^ERRORError: Variable used without being declared.I know what this mean, but if you look in the function above this, you can see that its declared in a Global statement.Any ideas what can happend... I need this script working on monday And while you look at the script, you might also find my other problem.When you have run the script and chosed "Yes" the patch (file) runs perfectly.And when you push it again, its supposed to do nothing, since it has changed ini to done. But it starts to run again, and THEN it change the file name to done.So even tough i say yes and run, it does not rename the file, as i told it to, at the bottom of the script. Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Valik Posted June 24, 2004 Share Posted June 24, 2004 Global variables should be declared outside of functions at the top of your script. Declaring them inside functions can lead to subtle, hard to find errors, sort of like what you're experiencing right now. Link to comment Share on other sites More sharing options...
Doxie Posted June 24, 2004 Share Posted June 24, 2004 ooh, i c Well i learn something new everyday But how can i then solve the problem i got, as you can see the $Action is part of a IF GuiRead... I tried to move the whole GuiRead between two functions, but i still got the same error message Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Doxie Posted June 28, 2004 Share Posted June 28, 2004 (edited) No one here who can help me? My kingdom and half the princess for anyone who can help me. I really need to get this working today, since Microsoft released a new patch that i need to roll out. Edited June 28, 2004 by Doxie Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Doxie Posted June 28, 2004 Share Posted June 28, 2004 No need anymore, i remade the whole script, and its even working better now Were ever i lay my script is my home... 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