Jump to content
Sign in to follow this  
Klexur

Increment number in file

Recommended Posts

Klexur

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

Share this post


Link to post
Share on other sites
LurchMan

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.

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
Klexur

@LurchMan: ha thanks for catching my spelling error =P

@JohnOne: are you also pointing out my spelling error?

EDIT

@JohnOne: oops okay i see what you did now :mellow:

Edited by Klexur

Quiet but very inquisitive

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • krasnoshtan
      By krasnoshtan
      Hello forum users!
      At some point I had a need to restart my script. Is it possible to do this with autoit or do I need to connect additional scripts like .cmd or .bat?
      For example: i have only script.au3 and it's running. Wich code shoud i use to exit from the script and start it again?
    • kartune
      By kartune
      Hi, i would like to know if there is a possible way to use subsections for ini files?
      For example, my ini file would look something like this:
       
      Clientname.ini
      [Info]
      Country=USA
      Type=Distributor
       
      [Costs]
      [[JAN]] <----- subsection
      cost1=----
      cost2=----
      [[FEB]]
      cost1=----
      cost2=----
       
      [Sales]
      [[JAN]] <----- subsection
      sale1=----
      sale2=----
      [[FEB]]
      sale1=----
      sale2=----
       
      [Profits]
      [[JAN]] <----- subsection
      prof1=----
      prof2=----
      [[FEB]]
      prof1=----
      prof2=----
       
      The sales would be inputed everyday by the script, and then whenever viewed, i would be using an array to view every sale/cost/profit under the subsection
       
       
      Thanks for your time!
    • ercicttech
      By ercicttech
      Hello, all..

      My AutoIT is pretty terrible - but I get by with trawling here
      I came across an issue where i had to parse a large key in a large ini file, and found that I was victim of inireadsection's limit of "Only the first 32767 chars are read for legacy reasons."
       
      I've attempted to put together some terrible code that parses an ini section.
      It's absolutely nowhere near good, but I figured I'd put it here so that folk who know what they're doing can laugh at improve it.
      $Ini = @ScriptDir & "\bigini.ini" Dim $IniArray[0][2] $KeyName = "Person" $R = FileOpen($Ini, 0) $IniStr = FileRead($R) FileClose($R) $Start = StringInStr($iniStr, "[" & $KeyName & "]") If $Start = 0 then Msgbox(16, "Error", "String not found") Exit EndIf $Stop = StringInStr($IniStr, @CRLF & "[", 0, 1, ($Start + 1)) If $Stop = 0 then $Stop = StringLen($IniStr) EndIf $String = StringMid($IniStr, $Start, ($Stop - $Start)) $Split = StringSplit($String, @CRLF, 1) $KeyCount = 0 Dim $IniArray[65535][2] For $Loop = 1 to $Split[0] $Add = "Y" $Str = $Split[$Loop] $EQBreak = StringInStr($Str, "=") Select Case StringMid($Str, 1, 1) = ";" $Add = "N" Case $EQBreak = 0 $Add = "N" Case Else $Add = "Y" EndSelect If $Add = "Y" then $KeyCount = $KeyCount + 1 $Key = StringMid($Str, 1, ($EQBreak - 1)) $Val = StringMid($Str, ($EQBreak + 1)) $IniArray[$KeyCount][0] = $Key $IniArray[$KeyCount][1] = $Val EndIf Next Redim $IniArray[$KeyCount +1][2] ; Add the number of hits to 00 to match inireadsection $IniArray[0][0] = $KeyCount _ArrayDisplay($IniArray) ; Do stuff with the Array like you would inireadsection  
    • RC86
      By RC86
      Afternoon, I could very well be doing this wrong so feel free to totally advise otherwise - I'm wanting to use a GUI to first display a key from within an INI file, then secondly change the INI file by using a FileSelectFolder command but then I want to see the GUI change to reflect the change I've just made.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Input1 = GUICtrlCreateInput(Iniread(@WorkingDir & "\test.ini","Path","FilePath",""), 64, 80, 121, 21) $Button1 = GUICtrlCreateButton("Change", 200, 80, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $selectedFolder = FileSelectFolder("Select Log Path Directory",@WorkingDir,0) If NOT $selectedFolder = "" Then $newLogPath = IniWrite(@WorkingDir & "\test.ini","Path","FilePath",$selectedFolder) EndIf EndSwitch WEnd So 2 part question really: (1) Should I be using GUICtrlCreateInput to display my INI read from within the GUI? (2) How can I refresh the GUI to update that to read the new information I've just written to the GUI?
      Thanks!

    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
      Autorun.inf
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.