Jump to content

Read ini file and fill listview


Recommended Posts

Hi,

 

I am trying to create a list view wich shows the content of an ini file. There is a pulldown menu wich allows me to check a certain status in the ini file if the status is found it should read out the key and in every section the same key is located after that it should fill out the listview with all results found.

 

$OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1)

    GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0)
            GUICtrlSetState(-1, $GUI_DISABLE)

    GUICtrlCreateGroup("", 8, 16, 185, 89)
        GUICtrlCreateLabel("Status:", 32, 40, 37, 17)
            $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
                GUICtrlSetData($STATUS, "Aangevraagd|Verzonden|Afgehandeld", "")
    GUICtrlCreateGroup("", -99, -99, 1, 1)

    $View = GUICtrlCreateListView("RMANR|RMANRLEV|DEBITNR|KLANT|STATUS|MODEL|SERIENR|AANGEMELDDOOR|AANMELDDATUM|VERZENDDATUM|RETOURDATUM|KLACHT|OPLOSSING", 8, 120, 1218, 614)

    $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33)
        GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $EXIT
                $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?")
                    If $YesOrNo = 6 then
                        GUIDelete($OVERZICHTGUI)
                        MAINMENU()
                        ExitLoop
                    EndIf
            Case $STATUS
                $GO = 1
                $STATE = GUICtrlRead($STATUS)
                Local $aArray = IniReadSection(@ScriptDir & "\DB\rma.ini", "STATUS")
                            _ArrayDisplay($aArray, "Gevonden")
                            $FOUNDRMANR = _ArraySearch($aArray, $STATE)
                            MsgBox(4096, "", $FOUNDRMANR)
                            If $FOUNDRMANR = -1 Then
                                MsgBox(4096, "Not Found", "No RMA requests with this status found.")
                                $GO = 0
                            EndIf
                            If $GO = 1 Then
                                $VAR = IniRead(@ScriptDir & "\DB\rma.ini", "RMANR", $FOUNDRMANR, "Not found")
                                    MsgBox(4096, "", $VAR)
                            EndIf
        EndSwitch
    WEnd

 

rma-forum.ini

Link to comment
Share on other sites

Had the same issue as UR, however here is how I would do it:

#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

FNC_RMAGUI()

Func FNC_RMAGUI()
    Local $hINI_FILENAME = @ScriptDir & "\DB\rma.ini"
    Local $aINI_SECTIONS[13] = ['RMANR', 'RMANRLEV', 'DEBITNR', 'KLANT', 'STATUS', 'MODEL', 'SERIENR', 'AANGEMELDDOOR', 'AANMELDDATUM', 'VERZENDDATUM', 'RETOURDATUM', 'KLACHT', 'OPLOSSING'] ;~ Sections that should be read from Ini and added to ListView, also used as ListView Header
    Local $aOptions = IniReadSection($hINI_FILENAME, 'Options') ;~ Use the Options section to populate the ComboBox
    Local $NAAMMEDEWERKER = 'NAAMEDWERKER' ;~ Remove this

    $OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1)

        GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0)
                GUICtrlSetState(-1, $GUI_DISABLE)

        GUICtrlCreateGroup("", 8, 16, 185, 89)
            GUICtrlCreateLabel("Status:", 32, 40, 37, 17)
                $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData($STATUS, _ArrayToString($aOptions, '|', 1, -1, '|', 0, 0), "")
        GUICtrlCreateGroup("", -99, -99, 1, 1)

        $hGUI_LISTVIEW = GUICtrlCreateListView(_ArrayToString($aINI_SECTIONS), 8, 120, 1218, 614)

        $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33)
            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

        GUISetState(@SW_SHOW)

        While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                Case $GUI_EVENT_CLOSE
                Exit
                Case $EXIT
                    $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?")
                        If $YesOrNo = 6 then
                            GUIDelete($OVERZICHTGUI)
                           ; MAINMENU() ;~ Commented for test purposes
                            ExitLoop
                        EndIf
                Case $STATUS
                    $STATE = GUICtrlRead($STATUS)
                    Local $sSTATUS = IniRead($hINI_FILENAME, 'Options', $STATE, 'Not Found')
                    If $sSTATUS <> 'Not Found' Then
                        _GUICtrlListView_DeleteAllItems($hGUI_LISTVIEW) ;~ Remove this if you just want to append the data to the ListView without removing all items
                        $sListViewItem = ''
                        For $x = 0 To UBound($aINI_SECTIONS) - 1
                            If $x = UBound($aINI_SECTIONS) - 1 Then
                                $sListViewItem &= IniRead($hINI_FILENAME, $aINI_SECTIONS[$x], $sSTATUS, -1)
                                ExitLoop
                            EndIf
                            $sListViewItem &= IniRead($hINI_FILENAME, $aINI_SECTIONS[$x], $sSTATUS, -1) & '|'
                        Next
                        GUICtrlCreateListViewItem($sListViewItem, $hGUI_LISTVIEW)
                    EndIf
            EndSwitch
        WEnd
EndFunc

In your Ini file add the following:

[Options]
Afgehandeld=1
Verzonden=3
Aangevraagd=4

 

Link to comment
Share on other sites

Can you re-post the ini file with multiple entries, I'm not really sure what you mean by "when there are multiple entries in the ini file using the same status it only shows 1 result in the listview."

Currently how the script works is when you select an option for example: "Verzonden" in the ComboBox it gets the status id from [Options] - Verzonden so the result is "3", it then reads each section referenced in $aINI_SECTIONS with the Ini Key "3".  Ini Keys should be unique in each section, as IniRead will only pick up 1 key.  You could add multiple keys and use IniReadSection but I wouldn't recommend it as it will cause more problems especially if the keys are not written in the correct order.

Can you confirm that is what you're referring to or is it something else?

 

Link to comment
Share on other sites

Think I understand now, can you try this:

NB: You can remove Options Section from the Ini as its no longer required.

Func OVERZICHT()
    Local $hINI_FILENAME = @ScriptDir & "\DB\rma.ini"
    Local $aINI_SECTIONS[13] = ['RMANR', 'RMANRLEV', 'DEBITNR', 'KLANT', 'STATUS', 'MODEL', 'SERIENR', 'AANGEMELDDOOR', 'AANMELDDATUM', 'VERZENDDATUM', 'RETOURDATUM', 'KLACHT', 'OPLOSSING'] ;~ Sections that should be read from Ini and added to ListView, also used as ListView Header
    Local $aSTATUS_SECTION = IniReadSection($hINI_FILENAME, 'STATUS') ;~ Use the Options section to populate the ComboBox
    Local $aSTATUS_ITEMS[0]

    $OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1)

        GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0)
            GUICtrlSetState(-1, $GUI_DISABLE)

        GUICtrlCreateGroup("", 8, 16, 185, 89)
            GUICtrlCreateLabel("Status:", 32, 40, 37, 17)
                $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData($STATUS, _ArrayToString(_ArrayUnique($aSTATUS_SECTION, 1), '|', 1, -1, '|', 1, 1), "")
        GUICtrlCreateGroup("", -99, -99, 1, 1)

        $hGUI_LISTVIEW = GUICtrlCreateListView(_ArrayToString($aINI_SECTIONS), 8, 120, 1218, 614)

        $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33)
            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

        GUISetState(@SW_SHOW)

        While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                Case $GUI_EVENT_CLOSE
                Exit
                Case $EXIT
                    $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?")
                        If $YesOrNo = 6 then
                            GUIDelete($OVERZICHTGUI)
                           MAINMENU()
                            ExitLoop
                        EndIf
                Case $STATUS
                    $STATE = GUICtrlRead($STATUS)
                    $aSTATUS_INDEX = _ArrayFindAll($aSTATUS_SECTION, $STATE, 1, 0, 0, 0, 1)
                    ReDim $aSTATUS_ITEMS[UBound($aSTATUS_INDEX)]
                    For $i = 0 To UBound($aSTATUS_INDEX) - 1
                        $aSTATUS_ITEMS[$i] = $aSTATUS_SECTION[$aSTATUS_INDEX[$i]][0]
                    Next
                    If IsArray($aSTATUS_ITEMS) Then
                        _GUICtrlListView_DeleteAllItems($hGUI_LISTVIEW) ;~ Remove this if you just want to append the data to the ListView without removing all items
                        For $i = 0 To UBound($aSTATUS_ITEMS) - 1
                            $sListViewItem = ''
                            For $j = 0 To UBound($aINI_SECTIONS) - 1
                                If $j = UBound($aINI_SECTIONS) - 1 Then
                                    $sListViewItem &= IniRead($hINI_FILENAME, $aINI_SECTIONS[$j], $aSTATUS_ITEMS[$i], -1)
                                    ExitLoop
                                EndIf
                                $sListViewItem &= IniRead($hINI_FILENAME, $aINI_SECTIONS[$j], $aSTATUS_ITEMS[$i], -1) & '|'
                            Next
                            GUICtrlCreateListViewItem($sListViewItem, $hGUI_LISTVIEW)
                        Next
                    EndIf
            EndSwitch
        WEnd
EndFunc

 

Link to comment
Share on other sites

The scripts crashed with this in the console:

 

"C:\Program Files (x86)\AutoIt3\Include\Array.au3" (2297) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If IsInt($aArray[$iBase]) Then
If IsInt(^ ERROR

Link to comment
Share on other sites

Sorry still can't get it to crash, however looking at Array.au3 line 2297 indicates it's related to _ArrayUnique not sure if the issue is because it's used within _ArrayToString so split it up, can you try:

Func OVERZICHT()
    Local $hINI_FILENAME = @ScriptDir & "\DB\rma.ini"
    Local $aINI_SECTIONS[13] = ['RMANR', 'RMANRLEV', 'DEBITNR', 'KLANT', 'STATUS', 'MODEL', 'SERIENR', 'AANGEMELDDOOR', 'AANMELDDATUM', 'VERZENDDATUM', 'RETOURDATUM', 'KLACHT', 'OPLOSSING'] ;~ Sections that should be read from Ini and added to ListView, also used as ListView Header
    Local $aSTATUS_SECTION = IniReadSection($hINI_FILENAME, 'STATUS') ;~ Use the Options section to populate the ComboBox
    Local $sSTATUS_SECTION = _ArrayUnique($aSTATUS_SECTION, 1)
        $sSTATUS_SECTION = _ArrayToString($sSTATUS_SECTION, '|', 1, -1, '|', 1, 1)
    Local $aSTATUS_ITEMS[0]

    $OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1)

        GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0)
            GUICtrlSetState(-1, $GUI_DISABLE)

        GUICtrlCreateGroup("", 8, 16, 185, 89)
            GUICtrlCreateLabel("Status:", 32, 40, 37, 17)
                $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData($STATUS, $sSTATUS_SECTION, "")
        GUICtrlCreateGroup("", -99, -99, 1, 1)

        $hGUI_LISTVIEW = GUICtrlCreateListView(_ArrayToString($aINI_SECTIONS), 8, 120, 1218, 614)

        $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33)
            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

        GUISetState(@SW_SHOW)

        While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                Case $GUI_EVENT_CLOSE
                Exit
                Case $EXIT
                    $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?")
                        If $YesOrNo = 6 then
                            GUIDelete($OVERZICHTGUI)
                           MAINMENU()
                            ExitLoop
                        EndIf
                Case $STATUS
                    $STATE = GUICtrlRead($STATUS)
                    $aSTATUS_INDEX = _ArrayFindAll($aSTATUS_SECTION, $STATE, 1, 0, 0, 0, 1)
                    ReDim $aSTATUS_ITEMS[UBound($aSTATUS_INDEX)]
                    For $i = 0 To UBound($aSTATUS_INDEX) - 1
                        $aSTATUS_ITEMS[$i] = $aSTATUS_SECTION[$aSTATUS_INDEX[$i]][0]
                    Next
                    If IsArray($aSTATUS_ITEMS) Then
                        _GUICtrlListView_DeleteAllItems($hGUI_LISTVIEW) ;~ Remove this if you just want to append the data to the ListView without removing all items
                        For $i = 0 To UBound($aSTATUS_ITEMS) - 1
                            $sListViewItem = ''
                            For $j = 0 To UBound($aINI_SECTIONS) - 1
                                If $j = UBound($aINI_SECTIONS) - 1 Then
                                    $sListViewItem &= IniRead($hINI_FILENAME, $aINI_SECTIONS[$j], $aSTATUS_ITEMS[$i], -1)
                                    ExitLoop
                                EndIf
                                $sListViewItem &= IniRead($hINI_FILENAME, $aINI_SECTIONS[$j], $aSTATUS_ITEMS[$i], -1) & '|'
                            Next
                            GUICtrlCreateListViewItem($sListViewItem, $hGUI_LISTVIEW)
                        Next
                    EndIf
            EndSwitch
        WEnd
EndFunc

 

Link to comment
Share on other sites

@Wingens,

Hope you've tried using an Array with _FileReadToArray() and then loop it though the ini file to add them as line at the time with GUICtrlCreateListViewItem().

You can use $GUI_HIDE and $GUI_SHOW to filter GUICtrlCreateListViewItem()

GUICtrlSetState($listview1, $GUI_HIDE) - ;to hide ID's
 GUICtrlSetState($listview2, $GUI_SHOW) - ;to show desired ID

Just trying if it make sense. :)

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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

×
×
  • Create New...