Jump to content

inireadsection problem


Recommended Posts

Thats my code:

func Namenliste()
    $sectionnames = IniReadSectionNames("Datenbank.ini")
    local $Namenliste
    For $i = 1 To $sectionnames[0]
        $Namenliste = $Namenliste & "|" & $sectionnames[$i]
    Next
    GUICtrlSetData($shop, $Namenliste, $sectionnames[1])
EndFunc

func kleidungsliste()
    local $kleidungsliste
    $x = GUICtrlRead($shop)
    MsgBox(0,"",$x)
    $shopinhalt = IniReadSection("Datenbank.ini", "Shop")
    For $i = 1 To $shopinhalt[0][0]
        $kleidungsliste = $kleidungsliste & "|" & $shopinhalt[$i][0]
    Next
    GUICtrlSetData($kleidungsstuck, $kleidungsliste, $shopinhalt[$i][0])
EndFunc

I basicly want to read an .ini file to get all the sectionnames in the "Datenbank.ini" (which is at the same location as the script). These are given to a combobox... works fine.

Then I want - in that filled combobox, if something is selected - on event to start the second function, also working without problems. All variables are handed over correctly and so on. But when I want to read the .ini file one more time to get the keys from that section it crashes telling me

C:\Users\***\Desktop\app.au3 (64) : ==> Subscript used with non-Array variable.:

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

For $i = 1 To $shopinhalt^ ERROR

I can't find the problem. The .ini file stays where it is all the time. one time it works, the second time it is not...

Link to comment
Share on other sites

Looks like $shopinhalt is in the local scope in the function, which means when the function exits, the array goes away.

Try creating the array outside of the function.

Or you can do it the lazy way and change

$shopinhalt = IniReadSection("Datenbank.ini", "Shop")

To

Global $shopinhalt = IniReadSection("Datenbank.ini", "Shop")

Link to comment
Share on other sites

  • Moderators

Chaosmeister,

You read the combo with the names:

$x = GUICtrlRead($shop)

Why do you not use it to read from the inifile? :graduated:

Change:

$shopinhalt = IniReadSection("Datenbank.ini", "Shop")

to read

$shopinhalt = IniReadSection("Datenbank.ini", $x)

and see if that does the trick. :(

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

I tried the examplefunction on my .ini file and even that wont work

hotkey for "test" is "´"

func test()
$var = IniReadSection("C:\Datenbank.ini", "shop2")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf   

EndFunc

i copied my ini file to C:\ first before you ask hehe

it is called and then the error msgbox pops up

the .ini looks like this:

[shop]

nummer2, 2, 2, 0

nummer1, 1, 2, 0

[shop2]

nummer2, 2, 2, 0

nummer1, 2, 2, 0

[shop3]

nummer2, 2, 2, 0

nummer1, 1, 2, 0

global $shopinhalt had no result. same as dim $shopinhalt[10][10] in the beginning of the second function

Edited by Chaosmeister
Link to comment
Share on other sites

Chaosmeister,

You read the combo with the names:

$x = GUICtrlRead($shop)

Why do you not use it to read from the inifile? :graduated:

Change:

$shopinhalt = IniReadSection("Datenbank.ini", "Shop")

to read

$shopinhalt = IniReadSection("Datenbank.ini", $x)

and see if that does the trick. :(

M23

Thats what i had in mind in the beginning but that didn't work, so i took down the niveau and told him what section to take :D

with still no result

Link to comment
Share on other sites

I have an App that I wrote for our tech support. I work for a convenience store chain with 330+ stores.

I create a combo using an ini file like so

[18]
5GT=172.19.2.17
POS1=172.17.99.103
POS2=172.17.99.104
POS3=None
ATM=172.19.2.20
SysTech=None

$shopscfgfile = @ScriptDir & "\myini.ini"
$shopsarray = IniReadSectionNames($shopscfgfile)
$mainGUIShopCombo = GUICtrlCreateCombo("Shop #", 140, 36, 75, 200)
ArrayToComboBox($shopsarray, $mainGUIShopCombo)
If @error Then ErrorReport("Error occurred generating shop list.", "10.4.7:406") ; an error function - that basically returns a msgbox with an error code and exits.
$mainGUIOpenButton = GUICtrlCreateButton("Open", 220, 36, 50, 22)

Func ArrayToComboBox($iArray, $oControl, $arrayIndex = 1)
    If IsArray($iArray) Then
        For $i = $arrayIndex To $iArray[0]
            GUICtrlSetData($oControl, $iArray[$i])
        Next
        Return 0
    Else
        SetError(1)
    EndIf
EndFunc

In my GUI loop - for the button 'open' I do.

Switch ShopGUI(Int(GUICtrlRead($mainGUIShopCombo)))
                Case 1
                    MsgBox(8240, "Please Select a Shop", "No shop selected.  Please Select or Enter a Shop Number")
                Case 2
                    MsgBox(8240, "Please Select a Valid Shop", "Shop " & GUICtrlRead($mainGUIShopCombo) & " is not a valid shop.  Please Select or Enter the correct Shop Number")
            EndSwitch

ShopGUI is a function for another GUI window that opens with the shop number. I get the shop number from the combo box selection. Then I use ini read to pull in the vars for that shop.

Link to comment
Share on other sites

Looked at your INI file and noticed why.

[section]

Key=Value

Is proper ini file - but it appears yours doesn't not follow the Key=Value formatting.

Not sure what you need in the ini file

[shop]

nummer2, 2, 2, 0

Could be

[shop]

nummer=2,2,2,0

Then when you inireadsection you'll get a multidimensional array with with nummer in one field and 2,2,2,0 in the other. Then you could stringsplit that string.

Link to comment
Share on other sites

Looked at your INI file and noticed why.

[section]

Key=Value

Is proper ini file - but it appears yours doesn't not follow the Key=Value formatting.

Not sure what you need in the ini file

[shop]

nummer2, 2, 2, 0

Could be

[shop]

nummer=2,2,2,0

Then when you inireadsection you'll get a multidimensional array with with nummer in one field and 2,2,2,0 in the other. Then you could stringsplit that string.

i just found that myself :graduated: i'm gonna try this now - sometimes i'm just blind X_X - anyway thanks for your 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...