Jump to content

Increment number in file


Klexur
 Share

Recommended Posts

First off I tried searching both the forums and the help file and I just know it's in one of them. If somebody could please help me find it I would be much grateful.

Simply put, I am trying to increment a number that is read from an ini file. The script is to read the initial value, add one to it, and save the new value. The area dealing with this is the last line of code below.

Here is my code:

#Include <Restart.au3>
 
Global $CommandIni = "DropRun.ini"
 
; Check that CommandIni exists, if not create file with default values.
If FileExists($CommandIni) Then
Global $Commands = IniReadSection($CommandIni, @ComputerName)
IniWrite($CommandIni, @ComputerName & "_Log", "Start", $CommandIni & " found and read.")
Else
Local $defCmds[2][2] = [ ["Completed", "1"], ["Command1", "cmd.exe"] ]
IniWriteSection($CommandIni, @ComputerName, $defCmds, 0)
IniWrite($CommandIni, @ComputerName & "_Log", "Error", $CommandIni & " not found. Attempted to create file.")
EndIf
 
; Check if already completed, if not run the commands.
If $Commands[1][1] = "0" Then
IniWrite($CommandIni, @ComputerName & "_Log", "Reading", "Entered Command section.")
For $i = 2 To $Commands[0][0]
  ; Check if line is commented out.
  If StringInStr($Commands[$i][0], ";") Then ContinueLoop
  Local $exitCode = RunWait($Commands[$i][1])
  IniWrite($CommandIni, @ComputerName & "_Log", "Command" & $i-1, $exitCode)
Next
IniWrite($CommandIni, @ComputerName, "Completed", "1")
EndIf
 
Sleep(300000)
; Log number of times script restarted.
$Restarts = IniRead($CommandIni, @ComputerName & "_Log", "Restarts", "0")
IniWrite($CommandIni, @ComputerName & "_Log", "Restarts", $Restarts+1)
_ScriptRestart()

The script uses the

Also, if anybody has suggestions on how to simplify this I'd also greatly appreciate it.

P.S. Sorry I couldn't get the code to paste pretty =S

Edited by Klexur
Quiet but very inquisitive
Link to comment
Share on other sites

You misspelled "restarts" on the INIWrite () portion of it. :mellow:

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

Might be an Idea to tell autoit its dealing with a number too.

$Restarts = Int(IniRead($CommandIni, @ComputerName & "_Log", "Restarts", "0"))
IniWrite($CommandIni, @ComputerName & "_Log", "Restarts", $Restarts+1)
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...