Jump to content

Problem with inifile output


Recommended Posts

Hello everybody,

I’m new at scripting and I have a problem.

I want to see how many times a user is using a program. I thought the best way was to log it into a ini file.

The section name will be the program name

The key will be the users name

The value will be the using count

Every program will get it’s own section. No problem here.

When it comes to the first key in a section, there are no problems. It counts

But from the second key the value will not count. It strands on the Array

I get the message:

…… (32) : ==> Subscript used with non-Array variable.:

$Total = $Total[$i][0]

$Total = $Total^ ERROR

I cant figure out what the problem is

This is what I have:

$sIniFile = "log.ini"
$UserName = "user1"
$Naam = "Program1"

If Not FileExists($sIniFile) Then

IniWrite($sIniFile, $Naam , $UserName , "1")

Else

If IniRead($sIniFile, $Naam, $UserName, "") Then

    $Totaal = IniReadSection($sIniFile, $Naam)
    For $i = 1 To $Totaal[0][0]
        $Totaal = $Totaal[$i][1]
Next
IniWriteSection($sIniFile, $Naam, $UserName & "=" & $Totaal + 1)

Else
    IniWrite($sIniFile, $Naam , $UserName , "1")
EndIf

Endif

The output is:

[Program1]
User1=3523
User2=1
User3=1
[Program2]
User1=64
User2=1
User3=1
[Program3]
User1=12
User2=1
User3=1
User4=1

I hoop someone can help me out here

Link to comment
Share on other sites

$Totaal = IniReadSection($sIniFile, $Naam)

For $i = 1 To $Totaal[0][0]

$Totaal = $Totaal[$i][1]

Next

You are overwriting the array with the value of a single element.

:(

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

Why do you use IniReadSection and IniWriteSection at all?

In all cases, all you need is much simpler:

$sIniFile = "log.ini"
$UserName = "user1"
$Naam = "Program1"

IniWrite($sIniFile, $Naam , $UserName , IniRead($sIniFile, $Naam, $UserName, 0) + 1)

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

Hi,

@Edit: Because of post from jchd :(

In all cases, all you need is much simpler:

For sure...... :)

$sIniFile = "log.ini"
$UserName = "user1"
$Naam = "Program1"

If Not FileExists($sIniFile) Then
    IniWrite($sIniFile, $Naam , $UserName , "1")
Else
    If IniRead($sIniFile, $Naam, $UserName, "") Then
        $Totaal = IniReadSection($sIniFile, $Naam)
        For $i = 1 To $Totaal[0][0]
            If $Totaal [$i] [0] = $username Then IniWrite ($sIniFile, $Naam, $username, $Totaal [$i] [1] + 1)
        Next
    Else
        IniWrite($sIniFile, $Naam , $UserName , "1")
    EndIf
EndIf
ShellExecute ("notepad.exe", @ScriptDir & "\log.ini")

;-))

Stefan

Goosh, Second shot:

$sIniFile = "log.ini"
$UserName = "user1"
$Naam = "Program1"

If Not FileExists($sIniFile) Then
    IniWrite($sIniFile, $Naam , $UserName , "1")
Else
    If IniRead($sIniFile, $Naam, $UserName, "") Then 
        $Totaal = IniRead($sIniFile, $Naam, $UserName, "")
        IniWrite ($sIniFile, $Naam, $username, $Totaal + 1)
    Else
        IniWrite($sIniFile, $Naam , $UserName , "1")
    EndIf
EndIf
ShellExecute ("notepad.exe", @ScriptDir & "\log.ini")
Edited by 99ojo
Link to comment
Share on other sites

Geez, we might as well write a Cobol compiler in AutoIt and do it in Cobol. It's a one-liner, so why run circles around?

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

Why do you use IniReadSection and IniWriteSection at all?

In all cases, all you need is much simpler:

$sIniFile = "log.ini"
$UserName = "user1"
$Naam = "Program1"

IniWrite($sIniFile, $Naam , $UserName , IniRead($sIniFile, $Naam, $UserName, 0) + 1)

Hi,

@Edit: Because of post from jchd :(

For sure...... :)

$sIniFile = "log.ini"
$UserName = "user1"
$Naam = "Program1"

If Not FileExists($sIniFile) Then
    IniWrite($sIniFile, $Naam , $UserName , "1")
Else
    If IniRead($sIniFile, $Naam, $UserName, "") Then
        $Totaal = IniReadSection($sIniFile, $Naam)
        For $i = 1 To $Totaal[0][0]
            If $Totaal [$i] [0] = $username Then IniWrite ($sIniFile, $Naam, $username, $Totaal [$i] [1] + 1)
        Next
    Else
        IniWrite($sIniFile, $Naam , $UserName , "1")
    EndIf
EndIf
ShellExecute ("notepad.exe", @ScriptDir & "\log.ini")

;-))

Stefan

Goosh, Second shot:

$sIniFile = "log.ini"
$UserName = "user1"
$Naam = "Program1"

If Not FileExists($sIniFile) Then
    IniWrite($sIniFile, $Naam , $UserName , "1")
Else
    If IniRead($sIniFile, $Naam, $UserName, "") Then 
        $Totaal = IniRead($sIniFile, $Naam, $UserName, "")
        IniWrite ($sIniFile, $Naam, $username, $Totaal + 1)
    Else
        IniWrite($sIniFile, $Naam , $UserName , "1")
    EndIf
EndIf
ShellExecute ("notepad.exe", @ScriptDir & "\log.ini")

Whahahaha…

For weeks I’m trying to get this to work. I search the forum for answers and tried things.

Now I have three answers that work

I don’t know with is better but the results are the same.

I got much to learn

Thank’s “ jchd ” and “ 99ojo ” for the help

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...