Access 2D array, Stumped

Muddling my way through this and hit a wall.
I have a small 2D array of constants. I put it in a Method called SetupArray. There are no parameters and its triggered on the open window event. Seemed straight forward. Now for the life of me I can’t figure out how to access it. The array is 9x11 and in the method I manually assigned all the values.
I have another method that (based on the value passed to it) returns an integer (‘Selection’ in this case) of the row to look up. I need to go through the array one column at a time and pull the value out based on Selection. So basically this.
S=Modifier(0,Selection) if it was 3 then S=8
T=Modifier(1,Selection) if it was 7 then T=26

Hope I explained it well enough.
Thanks in advance

Can you show a little of your setup code? Make sure you are not Dim’ing Modifier as a local variable in that code. Modifier must be a property of the window or part of a module. And no, you haven’t explained enough.

What is going wrong?
Do you get a compile error?
Do you get a runtime error?
Do you get the wrong value?

A little more info would help.

Bill, is the array local to the method or is it global to the window (or app)? If it is defined (Dim’d) in the method, nothing outside of the method can see it.

sounds like a job for a dictionary to me.

[code]
Dim d As New Dictionary
d.Value(3) = 8
d.Value(7) = 16

MsgBox(cstr(d.Value(7))) // Displays “16”[/code]

Thanks for the replies so far. I’ll try and be a little more forthcoming with the information. That was a before bed post.
A little back ground. I’m going to eventually be setting up a number of 2D arrays ( charts ) that need to be globally available. I thought the best way to do it would be to have the app open event assign them ( they are static and won’t change, Its just the values I need access to. The window open event triggers the SetupArray method. I have the scope of the method set to public, no parameters since its just plugging the values in the array. I set a breakpoint and it steps through the list of assignments fine. It looks like this.

// Assign Attribute chart to an array
dim Attribs(8,10) As String

Attribs(0,0)="-2"
Attribs(0,1)="-1"
Attribs(0,2)=“0”
Attribs(0,3)=“0”
Attribs(0,4)="+1"
Attribs(0,5)="+2"
Attribs(0,6)="+3"
Attribs(0,7)="+4"
Attribs(0,8)="+5"
Attribs(0,9)="+6"
Attribs(0,10)="+7"

It makes it through that fine. When I try and pull a value out of it I get a compile error.

This item does not exist : tempHolder=[b]Attribs/b
Attribs is what its complaining about. I thought I could do something like this to get the value and put it on screen.

selection=ColSelect(stren) // This method works fine and returns the correct row number
tempHolder=Attribs(0,selection) // Go get the Modifier from the array
stren.Text=Str(tempHolder) // put the value on screen.

So… basically what I’m looking to do is have the open event trigger the SetupArray method where I can assign all the values to the arrays ( There will be about 12 different arrays when I’m done ) and then I need to be able to look at the info in them from the main window of the app. I’m open to anyway to get this done but please be gentle. I’ve only been using xojo for 3 days now

Because of the DIM line the array only exists IN that method where you set it up

So you have a problem with the SCOPE (see user guide etc for references on this)

I can’t help but think that I’m going about this the wrong way but for the life of me don’t and can’t figure out how to initialize the arrays as global and pull some information out of it. I double checked the scope of the method and it is set to public. I should add that there is only one window in my little app. All this is triggered on a pushbutton. I could put all the arrays set up in the action trigger for the button. That would negate the global call but the amount crammed under that button push is getting long already.

@Dale Arends. How would I dim an array on the window/app? That sounds like it has potential. If I can figure out how to put the dim on window1, then I could use the method to populate it ( like I want to ) And access the info as needed.

@Jeff Tullin I haven’t seen anything showing ( so far anyway ) that dictionaries can be 2D. Will continue looking.

OK… got the strange idea to put the array assignments IN the open event. … That didn’t work either still get the compile error that attribs does not exist. I’ll keep banging on it. I’m stubborn that way

sounds like a dictionary of a custom class would be easier than indexed columns

If I understand you’re question correctly, try this.

define a property on the window of a type string, set the scope depending on your need.
call it Attribs(8,10)

then in your open event assign the value’s to the array
Attribs(0,0) = “-2”

then in any control you can use (access or assign) the array.

SCOPE … very important concept… if you define it on a window, only that window knows about it.
If you define it inside a function or method, only that function or method knows about it.

Best to define it in a MODULE, and make it PUBLIC, then EVERY window, module, method or function can reference it as required.

@Paul Ross. You just beat me to it. Sorry @Tim Hare. I didn’t read your reply closely enough, you gave me the answer way up there. That’s what I ended up doing Paul and it works exactly the way I want it to.

@Dave S. For this little thing I don’t “think” it will come into more than one Window, But I didn’t think I would ever get back into programming either. ( Hint…When I graduated university, Windows were something you looked out ). I took a quick look at modules So I would insert Module1,
Set the scope to Global.
Add a property to the Module to make the array Global?