Jump to content

Read ini file use as Menuitem


Recommended Posts

Hello, I am trying to change a script to take menu items from an ini file and having some issues

$aArray = IniReadSection("test.ini","test")
 
 If not @error Then
   For $i = 1 To $aArray[0][0]
      MsgBox("Test","", "Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1])
   Next
   EndIf

And I am trying to use the read ini file in the array but getting error

 

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

 

Here is where I am trying to use the array in GUI

$Item1 = GUICtrlCreateMenuItem($aArray[$i][1],$Menu)

$item1 is later used in an while loop to check what is selected from the menu.

Edited by Jat421
Link to comment
Share on other sites

  • Moderators

possy_99,

From the Help file for IniReadSection:

 

Return Value

Success: a 2 dimensional array

So your suggestion to use 1D array syntax is completely nonsensical. :wacko:


Jat421,

Can you post an example of the ini file you are using, as I can see nothing wrong with the code as posted. :huh:

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

Here is the ini file. 

[test]
key1=value1
key2=value2
key3=value3

Also the -1 actually did the trick but I am trying to hold more keys into the array and would like to call them later in the script. How can the expand the array to hold more data I tried $aArray[2][2] but that throws an error?

 Thanks guys for all the help!

$Item2 = GUICtrlCreateMenuItem($aArray[$i][3],$Menu)
Link to comment
Share on other sites

  • Moderators

Jat421m,

Using the "- 1" will leave you one key/value short - try it and see:

$aArray = IniReadSection("test.ini", "test")

If Not @error Then
    For $i = 1 To $aArray[0][0] - 1
        ConsoleWrite("Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1] & @CRLF)
    Next
    ConsoleWrite(@CRLF)
    For $i = 1 To $aArray[0][0]
        ConsoleWrite("Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1] & @CRLF)
    Next
EndIf
You only need the "- 1" if you use UBound to get the count - here the function returns the count in the [0][0] element. ;)

To expand the array, use ReDim to resize it like this:

#include <Array.au3> ; only to see the result

$aArray = IniReadSection("test.ini", "test")
; Add a column
ReDim $aArray[$aArray[0][0] + 1][3] ; [same number of rows][add a column]
; And see the result
_ArrayDisplay($aArray, "", Default, 8)
All clear? :)

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

sincere apologies for the mis-information.. I didn't really have my brain in gear and just did a quick google search, which lead me to the autoitwiki with example scripts as shown.. guess I should have looked harder :D

post-7476-0-19109300-1401216593_thumb.jp

Edited by possy_99
Link to comment
Share on other sites

  • Moderators

possy_99,

No problem - can happen to us all. ;)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...