LurchMan Posted January 2, 2009 Share Posted January 2, 2009 (edited) All of the variables that are not defined in this func are defined else where in the script. For the first file, it appends "1" to it, for the second one it appends "002" to it, and then it wont even create and write to the file from then on. All help will be greatly appreciated expandcollapse popupFunc LogBug () $Prob = GUICtrlRead ($ProbIn) $Name = GUICtrlRead ($NameIn) $Script = GUICtrlRead ($ScriptIn) Global $BugCnt = 1 $File = (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") $FileTest = FileExists (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") If $FileTest = True Then Do $BugCnt = $BugCnt + 1 $NewFile = FileExists (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") Until $NewFile = False If $BugCnt < "010" Then $BugCnt = "00" & $BugCnt ElseIf $BugCnt < "100" Then $BugCnt = "0" & $BugCnt EndIf $NewFile = (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") _FileCreate (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") FileOpen ($NewFile , 2) FileWrite($NewFile, "***************************************************" _ & @CRLF & "Name: " & $Name _ & @CRLF & "Script: " & $Script _ & @CRLF & "Problems: " & $Prob _ & @CRLF & "***************************************************") FileClose ($NewFile) Else ;~ FileOpen ($File , 2) If $BugCnt < "010" Then $BugCnt = "00" & $BugCnt ElseIf $BugCnt < "100" Then $BugCnt = "0" & $BugCnt EndIf _FileCreate ($File) FileOpen ($File , 2) FileWrite($File, "***************************************************" _ & @CRLF & "Name: " & $Name _ & @CRLF & "Script: " & $Script _ & @CRLF & "Problems: " & $Prob _ & @CRLF & "***************************************************") FileClose ($File) EndIf Email () EndFunc Edited January 2, 2009 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 2, 2009 Share Posted January 2, 2009 All of the variables that are not defined in this func are defined else where in the script. For the first file, it appends "1" to it, for the second one it appends "002" to it, and then it wont even create and write to the file from then on. All help will be greatly appreciated expandcollapse popupFunc LogBug () $Prob = GUICtrlRead ($ProbIn) $Name = GUICtrlRead ($NameIn) $Script = GUICtrlRead ($ScriptIn) Global $BugCnt = 1 $File = (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") $FileTest = FileExists (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") If $FileTest = True Then Do $BugCnt = $BugCnt + 1 $NewFile = FileExists (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") Until $NewFile = False If $BugCnt < "010" Then $BugCnt = "00" & $BugCnt ElseIf $BugCnt < "100" Then $BugCnt = "0" & $BugCnt EndIf $NewFile = (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") _FileCreate (@ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $BugCnt & ".log") FileOpen ($NewFile , 2) FileWrite($NewFile, "***************************************************" _ & @CRLF & "Name: " & $Name _ & @CRLF & "Script: " & $Script _ & @CRLF & "Problems: " & $Prob _ & @CRLF & "***************************************************") FileClose ($NewFile) Else ;~ FileOpen ($File , 2) If $BugCnt < "010" Then $BugCnt = "00" & $BugCnt ElseIf $BugCnt < "100" Then $BugCnt = "0" & $BugCnt EndIf _FileCreate ($File) FileOpen ($File , 2) FileWrite($File, "***************************************************" _ & @CRLF & "Name: " & $Name _ & @CRLF & "Script: " & $Script _ & @CRLF & "Problems: " & $Prob _ & @CRLF & "***************************************************") FileClose ($File) EndIf Email () EndFunc I think you need to stop treating strings and integers as equivalent. Keep $BugCnt as a normal integer and use StringFormat() to produce the minimum three digit with leading zeroes that you want. At some point that is probably screwing up your process: For $iBugCnt = 1 To 16 $sBugCnt = StringFormat("%03d", $iBugCnt) ConsoleWrite("$iBugCnt = " & $iBugCnt & " $sBugCnt = " & $sBugCnt & @LF) Next For $iBugCnt = 91 To 106 $sBugCnt = StringFormat("%03d", $iBugCnt) ConsoleWrite("$iBugCnt = " & $iBugCnt & " $sBugCnt = " & $sBugCnt & @LF) Next For $iBugCnt = 991 To 1006 $sBugCnt = StringFormat("%03d", $iBugCnt) ConsoleWrite("$iBugCnt = " & $iBugCnt & " $sBugCnt = " & $sBugCnt & @LF) Next Note the convention for the variable naming, where $iBugCnt is an integer, and $sBugCnt is a string (never to be used in arithmetic compares). 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 More sharing options...
LurchMan Posted January 2, 2009 Author Share Posted January 2, 2009 Thanks for the help....I kinda understand how this works and what its doing, but I don't quite understand how to integrate it into my original code....(sorry for the newb question here) Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
LurchMan Posted January 2, 2009 Author Share Posted January 2, 2009 Never mind! I got it to work! Thank you so much for your help! I've been working on this function for about 2 hours trying to get it to work right..... Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 2, 2009 Share Posted January 2, 2009 (edited) Thanks for the help....I kinda understand how this works and what its doing, but I don't quite understand how to integrate it into my original code....(sorry for the newb question here) Something like this: Func LogBug () $Prob = GUICtrlRead ($ProbIn) $Name = GUICtrlRead ($NameIn) $Script = GUICtrlRead ($ScriptIn) Global $iBugCnt = 1 While 1 $sBugCnt = StringFormat("%03d", $iBugCnt) $sFile = @ScriptDir & "\Temp\Bugs\" & @MON & @MDAY & @YEAR & "_BugReport_" & $sBugCnt & ".log" If FileExists($sFile) Then $iBugCnt += 1 Else ExitLoop EndIf WEnd $hFile = FileOpen ($sFile , 1); Get file handle FileWrite($hFile, "***************************************************" & @CRLF & _ "Name: " & $Name & @CRLF & _ "Script: " & $Script & @CRLF & _ "Problems: " & $Prob & @CRLF & _ "***************************************************") FileClose ($hFile) Email () EndFunc Note $iBugCnt is an integer count. $sBugCnt is the formatted string of $iBugCnt. $sFile is the string file path, and $hFile is the handle to the opened file. Never use FileOpen() and then reference the file by path, use the handle returned by FileOpen(). Edit: Typo: "Never use FileOpen() and then reference..." Edited January 2, 2009 by PsaltyDS 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 More sharing options...
LurchMan Posted January 2, 2009 Author Share Posted January 2, 2009 (edited) Never use FileOpen() and the reference the file by path, use the handle returned by FileOpen(). Don't quite understand what your saying there? from what i understand your saying something like: FileOpen ($File) Correct? Edit: Sorry Didn't look very closely at your sample code...I had my original code set up in places like that because I was trying absolutly everything i knew to try and make it run correctly...I've already changed everything back Edited January 2, 2009 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
FireFox Posted January 2, 2009 Share Posted January 2, 2009 @PsaltyDS Ive never used FileOpen for after use FileWrite I only use FileWrite and it works great all the time Cheers, FireFox. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 2, 2009 Share Posted January 2, 2009 Don't quite understand what your saying there? from what i understand your saying something like: FileOpen ($File) Correct? No. Because you didn't save the handle that was returned from FileOpen(). That should be: $hFile = FileOpen ($File) Then you should use the handle ($hFile) for your FileWrite() and FileClose(). This is a confusing point for noobs with AutoIt (including me, a while back). You can avoid working with handles and use the string file path. Or, you can use handles. What you must not do is mix the two. If you want to stick with the string path, then never FileOpen()/FileClose(). You can just write to the file: $sFile = "C:\Temp\File.txt" FileWrite($sFile, "This is my file.") This has limitations, like not specifying the modes you can add to FileOpen(). If you choose to use a file handle, then use the handle and do not refer to the file again by the string path until after you have done FileClose(). It's just either/or. Use the path or use a handle, but don't mix them. 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 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