But I get problems with the array since the number of secondary elements varies. I thought from there I'd be able to grab any combination , say $jobinclude[2][2] would give me "e"... and $jobinclude[3][1] would be "h". It doesn't work though, at least not as I've scripted it... no error... just gives me a blank value unless I check within the nested loop... then it will give me the proper value at the corresponding iteration of the loop - but it does not seem to remember the values outside of the loop. I can't figure out why this is the case.

So if I can't use a two-dimensional array, then I figured I could just use a bunch of variables, but I wouldn't know how many to declare or what syntax, if any, is appropriate. Eg.

Share this post

Link to post

Share on other sites

LondonNDIB 0

LondonNDIB 0

You mean answer should be $i, no "i" - right? From my sample ini it would be "d". Thanks - I didn't think about using the IniReadSectionNames function. However, that reads in ALL section names so I'd have to introduce some control statements to weed out the non "JobX" sections.

I also realized what I was doing wrong in my initial script. The line that read:

Global $jobinclude[$NumJobs+1][$NumIncludes+1]

of course was in side the For $i loop so it was constantly clearing the array... setting a value within it, and clearing it again, and so on. So I have to bring that outside of the for $i loop. Unfortunately, I would have no way of knowing what $NumIncludes was then (because it is generated within the loop) so instead I have to declare the variable like so:

Global $jobincludes[$NumJobs+1][99]

and do so before the For $i loop. I'd rather not do that, because I don't want to impose some artificial limit on the number of includes a job can have... Valuator's idea is pretty clean. So I'll either modify that (thank you!) or live with artificial limits.

Share this post

Link to post

Share on other sites

LondonNDIB 0

LondonNDIB 0

Still having problems. After working with your code Valuator, I'm not sure it really solves it... I'm still stuck not knowing how large to declare the two-dimensional array.

So can I declare the first dimension, and then the second dimension later? Probably not.

Basically, I can tell how big $i will be - but I have no idea how big $j will be for each $i until after the fact... and unfortunately, the array[$i][$j] needs to be declared first with the number of elements in each.

This now works because before I was re-declaring the $jobinclude array and it was wiping out its contents on each iteration... with "Redim" (which keeps the "Global" scope, btw) it changes the size of the dimension without wiping out the contents! I add that last If statement because there's no reason to Redim unless the array is getting larger in the current iteration - if it is the same size (ie same number of includes as the previous job) then it doesn't have to be re-declared at all.

I haven't fully tested this yet, but it seems to work.

LD

*edit* I also realized I was thinking of $NumIncludes as a scalar originally, when it is an array itself.... ie. $NumIncludes[1] = 3, $NumIncludes[2] = 4, $NumIncludes[3] = 2 (from the sample INI at the top)

Share this post

Link to post

Share on other sites

LondonNDIB 0

LondonNDIB 0

1) I appreciate that! But in my particular case, I need the JOBS section any way for a bunch more info outside of this "includes" business. So for my purposes, its there anyway and was handy to use... but I agree it is not necessary to solve my problem as described.

2) Not really. Your method still has the distinct problem of not being valid outside of the loop. The include[j] values aren't persistent. In other words, add

MsgBox ( 0, "", $includes[1][1] )

immediately before your "return" in the loop and you will see that it returns whatever the first value for that particular job is instead of the proper constant value of "a" (at least in the example INI posted at the top of this thread). Try to get $includes[2][2] and you get a fault in the code because the second dimension can never be higher than "1" in your code... thereby effectively making it a single-dimensional array. To make it truely multi-dimensional (instead of a single dimensional that constantly over-writes itself - the same problem I was struggling with to begin with) you need to either know/declare its size ahead of time, or use the Redim function as I "discovered"

Share this post

Link to post

Share on other sites

LondonNDIB 0

LondonNDIB 0

Both, I suppose. As a multi-dimensional array, the data can be called up and used/modified whenever and wherever I want later on in the script.

I feel its the better method for solving the problem of "variable variables"... your solution definately solves the specific example I posed. What I probably didn't clarify enough was that the example ini was really stripped down for this post - it doesn't resemble my actual situation at all - and it was the overall concept I needed help with - that of multidimensional arrays. Recall that from my first post, I wrote:

But I get problems with the array since the number of secondary elements varies. I thought from there I'd be able to grab any combination , say $jobinclude[2][2] would give me "e"... and $jobinclude[3][1] would be "h". It doesn't work though, at least not as I've scripted it... no error... just gives me a blank value unless I check within the nested loop... then it will give me the proper value at the corresponding iteration of the loop - but it does not seem to remember the values outside of the loop. I can't figure out why this is the case.

So I thought it was clear I would require a method for grabbing a specific $jobinclude[x][y] value. Redim, as it turns out, was the key to making that possible.

Share this post

Link to post

Share on other sites

LondonNDIB 0

LondonNDIB 0

Thank you. And seriously.... thank you for your help! I didn't mean to belittle your efforts at all and I hope I didn't - I just think that my self-discovered solution worked better in my particular situation... but it was your original suggestion that led me in that direction anyway!