Posts: 1,769
Threads: 410
Joined: Feb 2003
I have a sql query that is pulling 6 different fields and is being captured into a string ARRAY. when I trid to get out the info I need, I tried to step through the Array with ndim and it said there were 2 dimentions but I'm able to step through all 6 fields.
Am I using this wrong somehow?
Function MGMT_Query
out oConn.QueryArr(qry MGMT)
out MGMT.ndim
out MGMT.len
int dim
for _i 0 MGMT.len
,;out "%s" MGMT[0 _i]
,rep 25
,,out "%s" MGMT[dim _i]
,,;err
,,,;out dim
,,dim=dim+1
,,out dim
here's the output
1
2
1
foobar
1
@foobar
2
foobar
3
4
5
6
Posts: 12,147
Threads: 143
Joined: Dec 2002
I think it is correct. What did you expect?
Posts: 1,769
Threads: 410
Joined: Feb 2003
I was thinking I would get 6 dimentions.
a length of 1 (row)
dimention of 6 (columns)
am I misunderstanding Arrays or the Array that this query is outputting?
Posts: 12,147
Threads: 143
Joined: Dec 2002
The array has 2 dimensions: dim 1 for columns, dim 2 for rows.
dim 1 has 6 elements, dim 2 has 1 element.
Variable 'dim' should be named 'col' or 'field'.
Number of columns is MMT.len(1).
Number of rows is MMT.len(2). The same MMT.len.
Posts: 1,769
Threads: 410
Joined: Feb 2003
what am I doing wrong here? If it has two dimentions, the second dimention with only one row then why would I get an error on this (invalid index)?
Function MGMT_Query
Posts: 12,147
Threads: 143
Joined: Dec 2002
To debug use this:
out MGMT.len(1) ;;corrected, was 0
out MGMT.len(2) ;;corrected, was 1
Posts: 1,769
Threads: 410
Joined: Feb 2003
I keep getting an error on dim(0)
Function MGMT_Query
out oConn.QueryArr(qry MGMT)
out MGMT.len(0)
out MGMT.len(1)
out MGMT.lbound(0)
out MGMT.lbound(1)
output
1
Error (RT) in MGMT_Query: invalid dimension
Posts: 1,769
Threads: 410
Joined: Feb 2003
isn't dim(0) being referred to by MGMT.len(0)?
NEAHHHHHH!!!
look what I get with this!
Function MGMT_Query
out oConn.QueryArr(qry MGMT)
out MGMT.ndim
out MGMT.len(2)
out MGMT.len(1)
out MGMT.lbound(2)
out MGMT.lbound(1)
Output
Posts: 12,147
Threads: 143
Joined: Dec 2002
My debugging code was incorrect. Must be len(1), len(2), not len(0).
Posts: 1,769
Threads: 410
Joined: Feb 2003
oh, going back and forth between zero-index and one-index gets me everytime. but shouldn't this give me the value of the first element in the second dimention? it errors out with invalid index each time.
Function MGMT_Query
Posts: 12,147
Threads: 143
Joined: Dec 2002
Macro Macro1369
ARRAY(str) MGMT.create(6 1) ;;6 columns, 1 row
out MGMT.ndim ;;2
out MGMT.len(1) ;;6 columns in dimension 1
out MGMT.len(2) ;;1 row in dimension 2
MGMT[0 0]="test" ;;first column, first row
out MGMT[0 0]
out MGMT[0 1] ;;error invalid index because there is only 1 row (index 0)
Posts: 1,769
Threads: 410
Joined: Feb 2003
boy, just when I think I've gotten Array figured out...
so, this has two dimentions (I'll think of them as columns on a spreadsheet (columns A and B)). the first column (A) has 6 elements (I'll think of them as rows in a speadsheet (rows 1-6)). the second column (B) has 1 row.
why wont "out MGMT[0 1]" just return "" or 'null'? I can't even set anything to that place with "MGMT[0 1]="test2""
Posts: 12,147
Threads: 143
Joined: Dec 2002
Quote:(I'll think of them as columns on a spreadsheet (columns A and B)). the first column (A) has 6 elements (I'll think of them as rows in a speadsheet (rows 1-6)). the second column (B) has 1 row.
everything incorrect
I think you confuse dimensions and columns.
Dimensions are like in this example:
1-dim is line.
2-dim is plane (x, y) or table (columns, rows).
3-dim is space (x, y, z).
4-dim is spacetime (x, y, z, t).
So in 2 dim array len(1) is number of columns, and len(2) is number of rows.
Posts: 12,147
Threads: 143
Joined: Dec 2002
ken gray Wrote:I can't even set anything to that place with "MGMT[0 1]="test2""
now you can
Macro Macro1369
ARRAY(str) MGMT.create(6 2) ;;6 columns, 2 rows
out MGMT.ndim ;;2
out MGMT.len(1) ;;6
out MGMT.len(2) ;;2
MGMT[0 0]="a" ;;first column, first row
MGMT[0 1]="b" ;;first column, second row
out MGMT[0 0]
out MGMT[0 1]
Posts: 1,769
Threads: 410
Joined: Feb 2003
Quote:everything incorrect
AND HOW!!!.....sigh....so, where do elements come in? Is that the name we give to 'cell' (from spreadsheet lingo)?
thanks for hanging in there with me! :?
Posts: 12,147
Threads: 143
Joined: Dec 2002
Example:
2-dim array, 3-columns, 2 rows
----------------------------------
| a[0 0] | a[1 0] | a[2 0] |
----------------------------------
| a[0 1] | a[1 1] | a[2 1] |
----------------------------------
Your query results has 1 row, therefore a[0 1] does not exist.
|