Jump to content

IniReadSectionNames not working correctly

Recommended Posts

Hi guys,

#include <Date.au3>
Global $YYMMDD = StringMid(@YEAR & @MON & @MDAY, 3)
Global $inifile = @ScriptDir & "\settings.ini"
Global $mfile = @ScriptDir & "\monitor" & "_" & $YYMMDD & ".ini"
Dim $i
$Count2 = IniRead($inifile, "Alert", "Count", "Count2NotFound")
$var = IniReadSectionNames($mfile)
If @error Then
MsgBox(4096, "", "Error occurred, probably no INI file.")
For $i = 1 To $var[0]
  $Start3 = IniRead($mfile, $var[$i], "Start", "Start3NotFound")
  $End3 = IniRead($mfile, $var[$i], "End", "End3NotFound")
  $Count3 = IniRead($mfile, $var[$i], "Count", "Count3NotFound")
  $iDateCalc = _DateDiff('n', $Start3, $End3)
  If $Count3 > $Count2 Then
   MsgBox(0, "Alert", "Source : " & $var[$i] & @CRLF & "Duration : " & $iDateCalc & " mins" & @CRLF & "Count : " & $Count3)

When I run the above codes for the attached file, it only displays the last result. Why is it so?

Can someone kindly guide me?

Thank you!



Link to comment
Share on other sites

Hello steelsking,

The problem is in your filename extensions. In your code your looking for '.ini' however the file you provide is a '.txt'.

Either change your code to look for file extension .txt, or change your file to an actual ini file by saving it with the extension .ini

This will through a file not found error.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

You're reading text, right?

In particular, when you read $count3, you're reading text, OK?

Hence $count3 is a string containing a number. If you want to compare that to a variable holding a number, you have to wrap it into Number()

Change the line into:

$Count3 = Number(IniRead($mfile, $var[$i], "Count", "Count3NotFound"))

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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

  • Recently Browsing   0 members

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