Queener

Need help with this loop

4 posts in this topic

#1 ·  Posted (edited)

For $x = 0 To 13
        
        If GUICtrlRead($InputStatus[$x]) = "Senior" Then
      IniWrite($xfile, "ChildMembers", $xfileSeniorKey & $x + 1, GUICtrlRead($inputname[$x]))
      IniWrite($xfile, "ChildMembers", $xfileSeniorDOB & $x + 1, GUICtrlRead($InputDate[$x]))
      EndIf
      Next

Correct me if I'm wrong, but doesn't this loop supposed to write each status field that contain the string "Senior" into the ini file? When I run this code; it picked the last row into the ini only which it ignores the rest. So for example:

Textbox 1 = Senior Name

Textbox 2 = Senior Name

DOB Text 1 = 12/12/1960

DOB Text 2 = 12/12/1950

Status Textbox 1= Senior

Status Textbox 2 = Senior

 

Outputs

[ChildMembers]
Senior2=Test
Senior_DOB2=Test

 

$xfileSeniorKey and $xfileDOB is only a variables of string to test.

$xfileSeniorKey = "Senior"

$xfileDOB = "Senior_DOB"

So when it writes to ini, it would look something like

[ChildMembers]

Senior1=Test

Senior_DOB=12/12/1960

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@Queener,

you are not making it easy for anyone to help you. if you take the 5 minutes it takes to post a simple runnable reproducer, you may find your issue very easily, because this one works for me flawlessly:

#include <GUIConstantsEx.au3>
Global $hGUI = GUICreate('Example', 300, 410)
GUISetBkColor(0xABCDEF)
GUICtrlCreateLabel('Name:', 10, 5, 80, 20)
GUICtrlCreateLabel('Date:', 110, 5, 80, 20)
GUICtrlCreateLabel('Type:', 210, 5, 80, 20)
Global $agName[14], $agDate[14], $agType[14]
For $i = 0 To 13
    $agName[$i] = GUICtrlCreateInput('Name#' & ($i + 1), 10, ($i + 1) * 25, 80, 20)
    $agDate[$i] = GUICtrlCreateInput(($i + 1) & '/12/1975', 110, ($i + 1) * 25, 80, 20)
    $agType[$i] = GUICtrlCreateInput('Senior', 210, ($i + 1) * 25, 80, 20)
Next
Global $gSave = GUICtrlCreateButton('Save to Ini', 10, 380, 280, 25)
GUISetState(@SW_SHOW, $hGUI)
While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $gSave
            FileDelete('senior.ini')
            For $i = 0 To 13
                If GUICtrlRead($agType[$i]) = 'Senior' Then
                    IniWrite('senior.ini', 'ChildMembers', 'Name' & ($i + 1), GUICtrlRead($agName[$i]))
                    IniWrite('senior.ini', 'ChildMembers', 'Date' & ($i + 1), GUICtrlRead($agDate[$i]))
                EndIf
            Next
    EndSwitch
WEnd
GUIDelete($hGUI)

 

Edited by orbs

Share this post


Link to post
Share on other sites

Exactly my thoughts, kinda hard to get the whole picture without the rest of it.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

Queener,

When using an INI file with incremental keys you need to find the highest key for the starting increment for successive runs.  Otherwise you will be writing over existing values.

If this is a frequently run or a high volume app you might consider SQLite.  It is not much harder than INI files for simple structures.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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