...

View Full Version : Multi dim arrays in multi dim arrays... is it safe?



jaywhy13
08-14-2005, 10:18 PM
I have good reason to do this... I figure it might b quite unconventional but it is safe?


folders(0,0) = folderId
folders(1,0) = typeData

typeData(0,0) = typeId
typeData(1,0) = typeName
typeData(2,0) = articleData

articleData(0,0) = aId
articleData(1,0) = aTitle
.
.
.
.
.
You get the idea... is it safe? Nested arrays? Is that even wot its called?

BaldEagle
08-14-2005, 11:02 PM
Yes, this is what is called nested arrays. An array within an array. I started my career as an xbase programmer (dbase and clipper, you may or may not have heard of them) but anyway, nested arrays were very common. Plus the arrays were always dynamic. I do not really understand your question about whether it is safe or not. Could you amplify.

BaldEagle

jaywhy13
08-14-2005, 11:14 PM
Yes, this is what is called nested arrays. An array within an array. I started my career as an xbase programmer (dbase and clipper, you may or may not have heard of them) but anyway, nested arrays were very common. Plus the arrays were always dynamic. I do not really understand your question about whether it is safe or not. Could you amplify.

BaldEagle

I infer from ur response that since they are common there's nothing unconventional or unsafe (programming wise) with them

BaldEagle
08-14-2005, 11:48 PM
Yes, that was my implication, but I was thinking that you may have some knowledge pertaining to their use in the environments that we discuss here that may make them less than desirable. If that is not the case then I would say they are certainly safe to use, however, they can be a little tricky if the programmer is not used to using them. What I mean is if everyone working on an application can easily manipulate them then they are certainly powerful indeed. For an inexperienced programmer they can be hell to figure out.

BaldEagle

jaywhy13
08-14-2005, 11:53 PM
Yes, that was my implication, but I was thinking that you may have some knowledge pertaining to their use in the environments that we discuss here that may make them less than desirable. If that is not the case then I would say they are certainly safe to use, however, they can be a little tricky if the programmer is not used to using them. What I mean is if everyone working on an application can easily manipulate them then they are certainly powerful indeed. For an inexperienced programmer they can be hell to figure out.

BaldEagle
I'm not an experienced coder in asp... i hav but little experience.. but the concept of multidimensional arrays is not new me.. :D
thanks

BaldEagle
08-15-2005, 12:14 AM
I apologize if you thought I was referring to your level of knowledge. I was only speaking in general terms. I work in shops with many people assigned to a particular application and all are not at the same level of expertise. Subsequently we have to eliminate some of the trickier aspects of the coding language to allow the less experienced to still function within the group. This is done only when other alternatives exist, otherwise the particular project is handled by only experienced people that can implement this code and the newbies are pressed to learn as quickly as possible.

Again, I was in no way referring to your particular situation or knowledge. If my words offended you I am very sorry. That was not my intent.

BaldEagle

oracleguy
08-15-2005, 06:26 AM
You mean multi-dimensional arrays? Yeah there isn't anything wrong with using them. However if you ever use more than 3 dimensions then you are probably doing something pretty funky.

jaywhy13
08-15-2005, 02:33 PM
whats the proper way to declare a multidimensional array? And then whats the proper way to obtain the number of rows and cols in the array... I've been getting alot of subscript out of range errors

neocool00
08-15-2005, 03:23 PM
<%
Dim aryData(cols, rows)
Dim iRow, iCol
Response.Write "<table>" & vbcrlf
For iRow = 0 To Ubound(aryData, 2)
Response.Write "<tr>" & vbcrlf
For iCol = 0 To Ubound(aryData, 1)
Response.Write "<td>" & aryData(iCol, iRow) & "</td>" & vbcrlf
Next
Response.Write "</tr>" & vbcrlf
Next
Response.Write "</table>" & vbcrlf
%>

jaywhy13
08-15-2005, 05:01 PM
I apologize if you thought I was referring to your level of knowledge. I was only speaking in general terms. I work in shops with many people assigned to a particular application and all are not at the same level of expertise. Subsequently we have to eliminate some of the trickier aspects of the coding language to allow the less experienced to still function within the group. This is done only when other alternatives exist, otherwise the particular project is handled by only experienced people that can implement this code and the newbies are pressed to learn as quickly as possible.

Again, I was in no way referring to your particular situation or knowledge. If my words offended you I am very sorry. That was not my intent.

BaldEagle
No need for apologies man... no harm done :D :thumbsup: thanks for ur help... I appreciate it

jaywhy13
08-16-2005, 06:08 AM
Alright... here are my questions:
How do I declare a multidimensional array without defining how many rows it will have? (I know the amount of columns it will have, thats fixed.)

How do I check back the array to see if data has been added to it?

How do I check the current index row of the array so i can know what index to place for "row" Redim Preserve myArray(cols,row+1)?

BaldEagle
08-16-2005, 02:53 PM
Alright... here are my questions:
How do I declare a multidimensional array without defining how many rows it will have? (I know the amount of columns it will have, thats fixed.)

How do I check back the array to see if data has been added to it?

How do I check the current index row of the array so i can know what index to place for "row" Redim Preserve myArray(cols,row+1)?


1. Since you already know there will be at least one row you can just make the initial Dim contain one. Dim myArray(5,1) then ReDim Preserve from there.

2. If you want to do this strictly for peace of mind then you could create a sub or function to dump the contents of the array to the screen so you could observe it. Otherwise assigning values to the array is no different than any other variable assignment. (see neocool00 post)

3. You can use a variable to keep track or you can use the Ubound function.
next_row = Ubound(myArray,2) +1 ' 2 is for the second dimension
Redim Preserve myArray(cols,next_row)

BaldEagle

jaywhy13
08-18-2005, 02:22 AM
Is there a limit to the amount you can do? Coz I'm getting a subscript error now that only comes about when I try to go beyond column 5. If I try to access column 6 it spits an error. And I already dimmed it properly

BaldEagle
08-18-2005, 02:54 AM
There are limits but they are different for each machine because it is limited by memory. Certainly your first dimension being a 7 or greater should not be a problem unless your second dimension is very, very large. Post the code that is malfunctioning and we'll see how we can help.

BaldEagle

[edit] Also semantics are important when dealing with arrays. when you say column 6 do you mean the sixth column or the one numbered 6. The sixth column is actually numbered 5.

jaywhy13
08-18-2005, 04:11 AM
There are limits but they are different for each machine because it is limited by memory. Certainly your first dimension being a 7 or greater should not be a problem unless your second dimension is very, very large. Post the code that is malfunctioning and we'll see how we can help.

BaldEagle

[edit] Also semantics are important when dealing with arrays. when you say column 6 do you mean the sixth column or the one numbered 6. The sixth column is actually numbered 5.

The limit is 60. Did some searching. I fixed the afore-mentioned problem. I made a silly mistake in my coding.. referred to the wrong multidimensional array. I also learned that you there are no inbuilt functions to measure dimensions in vbscript... but it can be done in JScript.

BaldEagle
08-18-2005, 04:34 AM
The number you are referring to is the number of dimensions. Perhaps I misunderstood your question. I thought you were referring to the limits on the size of a dimension. At any rate if you have found the answers you are seeking then that is all that matters.

BaldEagle

jaywhy13
08-18-2005, 05:53 AM
You were right about the whole "trickiness" of these multi dim arrays... fortunately the jscript .dimensions() prop is really helpin out

jaywhy13
08-18-2005, 01:28 PM
Look at this algorithm to print out the cols and rows in a multi dim array...
I get "Type Mismatch" error for the line in red...


function printMultiDimArray(arr)
Dim cols, rows
if not isArray(arr) then
response.write "Not a multi dim array!"
else
cols = ubound(arr,1)
rows = ubound(arr,2)
Dim r, c
response.write "<table border=1>"
for r = 0 to rows
response.write "<tr><td colspan=2" & (cols+1) & ">row: " & r & "</td></tr>"
response.write "<tr>"
for c = 0 to cols
response.write "<td>" & arr(c,r) & "</td>"

next
response.write "</tr>"
next
response.write "</table>"
end if

end function

neocool00
08-18-2005, 06:26 PM
jaywhy13,
Sounds like the array you are passing in is not a multi-dimension array.

ghell
08-21-2005, 12:13 AM
i generlaly do all my 2d arrays as
arrOuter = ( _
array("1", "2"), _
array("3", "4") _
)

and then use arrOuter(0)(1) if i wanted to get the "2" out.. its just a nicer way of writing it than using an actual 2d array and declaring each value on a line (as most arrays will contain tens or hundreds of values.. also adding another line is just like a record in a database ;) )

you could do another array with this array in it if u wanted etc they are all pretty flexible.

i would suggest using lbound and ubound not 0 and ubound btw, this will help if there are no elements or it is not an array

jaywhy13
08-21-2005, 04:09 AM
i generlaly do all my 2d arrays as
arrOuter = ( _
array("1", "2"), _
array("3", "4") _
)

and then use arrOuter(0)(1) if i wanted to get the "2" out.. its just a nicer way of writing it than using an actual 2d array and declaring each value on a line (as most arrays will contain tens or hundreds of values.. also adding another line is just like a record in a database ;) )

you could do another array with this array in it if u wanted etc they are all pretty flexible.

i would suggest using lbound and ubound not 0 and ubound btw, this will help if there are no elements or it is not an array
Interesting u'd mentioned something I wasn't too clear about....
What the difference between array(0,0) and array(0)(0)????
My current understanding is that the first is a multidimensional array... but the second? The second is a nested array right?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum