Jump to content

Read and combine multiple sections inifile


Wingens
 Share

Recommended Posts

Hi I am trying to read multiple sections from an ini file into an array and use the result to calculate how many records there are from the suppliers and this devided into the status records that belong to it. The problem I am having; I am able to use Ubound to calculate how many record there are in total to the option chosen from the combo box, but where I am getting stuck is the part to link the status and leverancier to each other and count them.

Hope some one can help me.

My code right now:

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <array.au3>

$Form1 = GUICreate("Form1", 615, 437, 569, 253)
$LEVCOMBO = GUICtrlCreateCombo("", 184, 112, 145, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))

    Global $aSections = IniReadSectionNames(@ScriptDir & "\leveranciers.ini")
    If (Not @Error) Then GUICtrlSetData($LEVCOMBO, _ArraytoString($aSections, "|", 1), $aSections[1])

    $LABEL              = GUICtrlCreateLabel("Totaal aantal RMA aanvragen: ", 48, 200, 250, 21)
    $TOTALCOUNT         = GUICtrlCreateLabel("", 200, 200, 100, 21)
    $LABEL2             = GUICtrlCreateLabel("Aantal aangevraagd: ", 48, 225, 250, 21)
    $TOTALAANGEVRAAGD   = GUICtrlCreateLabel("", 200, 225, 100, 21)
    $LABEL3             = GUICtrlCreateLabel("Aantal verzonden: ", 48, 250, 250, 21)
    $TOTALVERZONDEN     = GUICtrlCreateLabel("", 200, 250, 100, 21)
    $LABEL4             = GUICtrlCreateLabel("Aantal afgehandeld: ", 48, 275, 250, 21)
    $TOTALAFGEHANDELD   = GUICtrlCreateLabel("", 200, 275, 100, 21)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LEVCOMBO
            COMBO()
    EndSwitch
WEnd

Func COMBO()
    Local $hINI_FILENAME = @ScriptDir & "\ini.ini"
        $READAANGEVRAAGDRMA         = IniReadSection($hINI_FILENAME, 'LEVERANCIER')
        $READSTATUS                 = IniReadSection($hINI_FILENAME, 'STATUS')
        $VAR                        = GUICtrlRead($LEVCOMBO)
        $READAANGEVRAAGDRMACOUNT    = _ArrayFindAll($READAANGEVRAAGDRMA, $VAR, Default, Default, Default, Default, 1)
                                      GUICtrlSetData($TOTALCOUNT,UBound($READAANGEVRAAGDRMACOUNT))
        $nb = $READAANGEVRAAGDRMA[0][0]
            Local $res[$nb+1][3]
            $res[0][0] = $nb
                For $i = 1 to $nb
                    $res[$i][0] = $READAANGEVRAAGDRMA[$i][1]
                    $res[$i][1] = $READSTATUS[$i][1]
                Next
            _ArrayDisplay($res)
EndFunc

And the ini files that goes with it:

ini.ini:

[STATUS]
1=Afgehandeld
3=Verzonden
4=Aangevraagd
5=Aangevraagd
6=Aangevraagd
7=Aangevraagd
8=Verzonden
9=Aangevraagd
10=Aangevraagd
11=Aangevraagd
12=Aangevraagd
13=Aangevraagd
14=Aangevraagd
15=Aangevraagd
16=Aangevraagd
17=Aangevraagd
18=Aangevraagd
19=Aangevraagd
20=Aangevraagd
21=Aangevraagd
22=Aangevraagd

[LEVERANCIER]
9=Dobit B.V.
1=Dobit B.V.
10=Dobit B.V.
11=Dobit B.V.
12=Dobit B.V.
13=Dobit B.V.
14=Asus
15=Asus
16=Brother
17=Dobit B.V.
18=Dobit B.V.
19=Dobit B.V.
20=Dobit B.V.
21=Dobit B.V.
22=Asus

leveranciers.ini:

[Kies een leverancier...]

[Dobit B.V.]
URL =http://eline.dobit.be/eline/master.php
[TechData B.V.]
URL =   
[MaxICT B.V.]
URL =   
[Brother]
URL=
[Asus]
URL=https://eu-rma.asus.com/pickup_europe/pickup.aspx?country=nl
[HP]
URL=
[Lenovo]
URL=
[CCV]
URL=

 

test.au3

ini.ini

leveranciers.ini

Link to comment
Share on other sites

  • Moderators

Wingens,

I think this does what you want:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiComboBox.au3>

$Form1 = GUICreate("Form1", 615, 437, 569, 253)
$LEVCOMBO = GUICtrlCreateCombo("", 184, 112, 145, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
_GUICtrlComboBox_SetCueBanner($LEVCOMBO, "Kies een leverancier...") ; Remove this phrase from the ini file

Global $aSections = IniReadSectionNames(@ScriptDir & "\leveranciers.ini")
If (Not @error) Then GUICtrlSetData($LEVCOMBO, _ArrayToString($aSections, "|", 1), $aSections[1])

GUICtrlCreateLabel("Totaal aantal RMA aanvragen: ", 48, 200, 250, 21) ; Why store the ControlId if you are not going to use it again?
$TOTALCOUNT = GUICtrlCreateLabel("", 200, 200, 100, 21)
GUICtrlCreateLabel("Aantal aangevraagd: ", 48, 225, 250, 21)
$TOTALAANGEVRAAGD = GUICtrlCreateLabel("", 200, 225, 100, 21)
GUICtrlCreateLabel("Aantal verzonden: ", 48, 250, 250, 21)
$TOTALVERZONDEN = GUICtrlCreateLabel("", 200, 250, 100, 21)
GUICtrlCreateLabel("Aantal afgehandeld: ", 48, 275, 250, 21)
$TOTALAFGEHANDELD = GUICtrlCreateLabel("", 200, 275, 100, 21)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LEVCOMBO
            _COMBO(GUICtrlRead($LEVCOMBO))
    EndSwitch
WEnd

Func _COMBO($VAR)
    
    Local $hINI_FILENAME = @ScriptDir & "\ini.ini"
    $READAANGEVRAAGDRMA = IniReadSection($hINI_FILENAME, 'LEVERANCIER')
    $READSTATUS = IniReadSection($hINI_FILENAME, 'STATUS')
    $READAANGEVRAAGDRMACOUNT = _ArrayFindAll($READAANGEVRAAGDRMA, $VAR, Default, Default, Default, Default, 1)
    ; Varibales to hold counts
    Local $TOTALAANGEVRAAGD_Sel = 0, $TOTALVERZONDEN_Sel = 0, $TOTALAFGEHANDELD_Sel = 0
    ; For each found index
    For $i = 0 To UBound($READAANGEVRAAGDRMACOUNT) - 1
        ; Check value of that index
        Switch $READSTATUS[$READAANGEVRAAGDRMACOUNT[$i]][1]
            Case "Aangevraagd"
                ; And adjust counts
                $TOTALAANGEVRAAGD_Sel += 1
            Case "Verzonden"
                $TOTALVERZONDEN_Sel += 1
            Case "Afgehandeld"
                $TOTALAFGEHANDELD_Sel += 1
        EndSwitch
    Next
    ; Set data in the labels
    GUICtrlSetData($TOTALCOUNT, $i)
    GUICtrlSetData($TOTALAANGEVRAAGD, $TOTALAANGEVRAAGD_Sel)
    GUICtrlSetData($TOTALVERZONDEN, $TOTALVERZONDEN_Sel)
    GUICtrlSetData($TOTALAFGEHANDELD, $TOTALAFGEHANDELD_Sel)

EndFunc   ;==>_COMBO

Come back if not.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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