Jump to content

INI File?


Vegar
 Share

Recommended Posts

Hello :P

I've have made a script that records how long the script have been running...

but i want it to start from where it ended last time, even if i restart the computer...

and i wanted to start learning to use INI files, and i think the explainasion in the help file was not to much of help..

so could someone explain to me how i use .INI files.. (How i make one, read one, and so on....) :unsure:

Link to comment
Share on other sites

just because..

Global $ini_File = @ScriptDir & "\My.ini"
Global $Time_Keep = ""

$Wait = 5 ; seconds

If not FileExists($ini_File) Then
    IniWrite($ini_File, "History", "Timer", "")
Else
    $Time_Keep = IniRead($ini_File, "History", "Timer", "")
EndIf

$begin = TimerInit()

While 1
    
    Sleep(500)
    
    $Test_Time = Int(TimerDiff($begin) / 1000)
    
    ToolTip( $Test_Time + $Time_Keep , 20, 20)

    If $Test_Time >= $Wait Then
        IniWrite($ini_File, "History", "Timer", $Test_Time + $Time_Keep )
        Exit
    EndIf
    
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

When your script ends, this fragment should run:

$IniFile =  StringRegExpReplace(@ScriptName, "\.au3|\.exe$", '') & '.Ini'
; Build your own time fragment
$LastTime =  @YEAR & @MON & @MDAY & "|" & @HOUR  & ":" &  @MIN & ":" & @SEC
IniWrite($IniFile, "LastRunEnd", @UserName, $LastTime)

When your script starts, this can be read back:

$LastTime =  IniRead($IniFile, "LastRunEnd", @UserName, "")
If StringLen($LastTime) > 0 Then
  ; You have Saved Run End Date/Time
  ; Do whatever...
EndIf
This is presuming $IniFile has been defined (as in first code fragment)

I notice Valuater has posted more relevant code. Your call :P

Link to comment
Share on other sites

and this one will do it too:

GreenCan

; startup with a new Timer.ini with some stuff in it
If Not FileExists(@ScriptDir & "\Timer.ini") Then Create_ini()

; read the ini file
$Timer = IniRead (@ScriptDir & "\Timer.ini", "Global", "Timer_seconds", 0)
ConsoleWrite("Timer on start : " & $Timer & @cr)

$begin = TimerInit() ; initiate the stopwatch

; do your stuff here
msgbox(0,"","press ok to stop")

$Accumulated_time = (TimerDiff($begin)/1000) + $Timer ; stopwatch

ConsoleWrite("Accumulated time: " & $Accumulated_time & @CR)

$result = IniWrite(@ScriptDir & "\Timer.ini", "Global", "Timer_seconds", $Accumulated_time )
If $result = 0 Then
    msgbox(0,"Error","INI File not accessible")
EndIf


; new content
$Timer = IniRead (@ScriptDir & "\Timer.ini", "Global", "Timer_seconds", 0)
ConsoleWrite("new ini content: " & $Timer & @CR)


Func Create_ini()
    IniWrite(@ScriptDir & "\Timer.ini", "Global", "Timer_seconds", 0)
    Return
EndFunc  ;==>Create_ini

Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...