Jump to content

iniwrite()


Recommended Posts

im writing to an ini in a function and it's in a for loop. at first i though it was the for loop causing data to be lost then i figured out it was the way i was writing to my .ini file. (then again it could be the for loop, i need some serious help :) )

here is what my ini looks like before written to:

[section1]

Key1=value1;value2

here's how i am writing to my ini:

IniWrite(@ScriptDir & "\temp.ini", "section1", "Key1", IniRead(@ScriptDir & "\temp.ini", "section1", $name, "") & $name & "|" & _NowDate())

it is "supposed" to take value1 and value2 and input them in an external app (it does this fine) then i want each of them to be written back into the ini file with the date next to each. so it would look like this:

[section1]

Key1=value1|date;value2|date

this is what my for loop looks like:

For $a = 0 To $count - 1
    $var = _GUICtrlListBox_GetText($externapp, $a); Gets the tables/items
    If $var = -1 Then
        $var = "No"
    Else
    EndIf
    $getcount = _GUICtrlListBox_GetCount($externapp)
    If $getcount > 0 Then
        IniWrite(@ScriptDir & "\temp.ini", "section1", "Key1", IniRead(@ScriptDir & "\temp.ini", "section1", $name, "") & $name & "|" & _NowDate())
        _GUICtrlListView_SetItemText($ListView, $a, $var)
        $date = GUICtrlSetData($Img, "||" & _NowDate())
    Else
    EndIf
Next

i dont know if showing you the for loop will make a difference but its either that or the way im writing to the ini that keeps screwing my ini file up.

im pretty sure its the way i write to the ini...

help?

Edited by nowagain
Link to comment
Share on other sites

i tried the code and it still doesnt write to it properly

the ini looks like this now:

[section1]

Key1=value1;value2value1|6/11/2008value1|6/11/2008value2|6/11/2008

:)

Edit: Would it be the position the iniwrite() is in in the for loop? just a thought that the data could be overwritten in the loop

Edited by nowagain
Link to comment
Share on other sites

i tried the code and it still doesnt write to it properly

the ini looks like this now:

[section1]

Key1=value1;value2value1|6/11/2008value1|6/11/2008value2|6/11/2008

:)

Edit: Would it be the position the iniwrite() is in in the for loop? just a thought that the data could be overwritten in the loop

Maybe this will do it, but not tested.

$ddate = _NowDate();no need to keep calculating the same thing
For $a = 0 To $count - 1
    $var = _GUICtrlListBox_GetText ($externapp, $a); Gets the tables/items
    If $var = -1 Then
        $var = "No"
    Else
    EndIf
    $getcount = _GUICtrlListBox_GetCount ($externapp)
    
    If $getcount > 0 Then
        $keydat = IniRead(@ScriptDir & "\temp.ini", "section1", $name, "")
        If $keydat <> "" Then
            $keydat = StringReplace($keydat, ";", "|" & $ddate & ";") & "|" & $ddate
            IniWrite(@ScriptDir & "\temp.ini", "section1", "Key1", $keydat)
        EndIf
        _GUICtrlListView_SetItemText ($ListView, $a, $var)
        $date = GUICtrlSetData($Img, "||" & $ddate)
    Else
    EndIf
Next
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

ok this is the closest its ever been but not quite finished

the ini looks like this now:

[section1]

Key1=value1|6/11/2008|6/11/2008|6/11/2008|6/11/2008|6/11/2008|6/11/2008;value2|

6/11/2008|6/11/2008|6/11/2008|6/11/2008|6/11/2008|6/11/2008

the only problem is instead of putting the date once like its supposed to it puts it 6 times for both buddies... :)

Edited by nowagain
Link to comment
Share on other sites

$keydat = StringReplace($keydat, ";", "|" & $ddate & ";") & "|" & $ddate

maybe this is part of the problem, the bolded section i cannot see why it is needed at all?

it seems like all that was needed to be done was in the stringreplace() and i dont see why the bolded is needed.

please correct me if im wrong.

Edited by nowagain
Link to comment
Share on other sites

$keydat = StringReplace($keydat, ";", "|" & $ddate & ";") & "|" & $ddate

maybe this is part of the problem, the bolded section i cannot see why it is needed at all?

it seems like all that was needed to be done was in the stringreplace() and i dont see why the bolded is needed.

please correct me if im wrong.

The bold part is there because, as I understood your first post, you asked for it to be there.

[section1]

Key1=value1;value2

here's how i am writing to my ini:

CODE

IniWrite(@ScriptDir & "\temp.ini", "section1", "Key1", IniRead(@ScriptDir & "\temp.ini", "section1", $name, "") & $name & "|" & _NowDate())

it is "supposed" to take value1 and value2 and input them in an external app (it does this fine) then i want each of them to be written back into the ini file with the date next to each. so it would look like this:

[section1]

Key1=value1|date;value2|date

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@martin:

your method i implemented into my program works fine the first time. but somehow it increments the date in the ini the second time so there is two dates and then everything messes up from there.

here's what it looks like:

value1|6/12/2008|6/12/2008;value2|6/12/2008|6/12/2008

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