Sign in to follow this  
Followers 0
Mast3rpyr0

Why is this not a 2D array?

8 posts in this topic

Do i have to initialize the variable as a 2d array or something? if so then how?

$INI = IniReadSectionNames(@ScriptDir & "\config.ini")
For $i = 1 To Ubound($INI) Step 1
    $INI2 = IniReadSection(@ScriptDir & "\config.ini", $i)
    Local $v = 70
    _ArrayDisplay($ini2)
    GUICtrlCreateLabel($INI2[1][1], 20, $v)
Next

C:\Documents and Settings\Admin\Desktop\AutoIT\Projects\new.au3 (23) : ==> Subscript used with non-Array variable.: 
GUICtrlCreateLabel($INI2[1][1], 20, $v) 
GUICtrlCreateLabel($INI2^ ERROR

Share this post


Link to post
Share on other sites



It looks like ... it could be ...but it is not.

It is a good practice to not try to create such arrays.

Indeed, you have first created an array ($INI) and in each element of it you have put another array but this is not making $INI to be a 2 dimension array.

You get this error because both $INI and $INI2 are 1 dimensional arrays as returned by IniReadSectionNames.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$INI is only needed for the Ubound part in the For loop, which works.

The one im concerned about is $INI2 why is it not a 2 array? In the array display it looks like it is.

EDIT: $INI2 is not connected to $INI at all.

Edited by Mast3rpyr0

Share this post


Link to post
Share on other sites

Sorry - been a little confused (heh - monday morning)

Your ini sections names are [1], [2] and so on? If this is the case then you shouldn't have any problems with your script. If the section names are different (and I guess they are) then IniReadSection will not return an array -> $INI2 won't be an array -> that error ... in this case you need to replace $i with the proper section name ($INI2 = IniReadSection(@ScriptDir & "\config.ini", $i)) and to modify the code accordingly.

Sorry about the confusion in my previous post


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yes thats what the names are.

heres a sample ini

[1]
Reminder=Write A Program
Time=11
Days=Every Day

[2]
Reminder=Write A Program
Time=15
Days=Monday-Friday

[3]
Reminder=Write A Program
Time=23
Days=Wednesday

The script works fine until i try to use the data in the array, _arraydisplay will go through each section as it loops until i try to use the array.

Edited by Mast3rpyr0

Share this post


Link to post
Share on other sites

I didn't look at it much, but this fixes the problem with it crashing:

#include <array.au3>
$INI = IniReadSectionNames(@ScriptDir & "\config.ini")
Local $v = 70; declare a variable outside of a loop, otherwise you will keep declaring it over and over which is extremely inefficient
For $i = 1 To Ubound($INI)-1 Step 1
    $INI2 = IniReadSection(@ScriptDir & "\config.ini", $i)
    _ArrayDisplay($ini2)
    GUICtrlCreateLabel($INI2[1][1], 20, $v)
Next

Remember, since arrays are zero based, you must do Ubound($INI)-1. This is because the array starts at zero, so the ubound will always be one larger. That is why you must subtract 1 from the ubound.

I hope that made sense.

-The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Great :P

I know about arrays being 0 based but ... I didn't think to look there for the trouble :)

... and that's why we need help sometime.

Cheers,


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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
Sign in to follow this  
Followers 0