Extract a row from a 2D array 
Author Message
 Extract a row from a 2D array

Hi all,

Is it possible in VBScript to return an array of column data as a 1D
array from a 2D array simply by specifing the current row.

In c, 2d arrays are stored as a single 1d array of pointers (the row
information), with each pointer pointing to another 1d array (the
column data). so to extract a row of column data, you only supply the
first index of the array. javascript seems to work in a very similar
way but I cannot do this with vbscript yet.

is this fundamentally possible in vbscript or not?

cheers,

d

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 28 Apr 2003 03:00:00 GMT  
 Extract a row from a 2D array
You're talking about an array of arrays (not the same as a 2D array), often referred to as "ragged
arrays" since each row is another array and each row array can have different dimensions.

dim ar(2)

ar(0) = array(1,2)
ar(1) = array("a","b","c")
ar(2) = array("abc","def","ghi","jkl")

msgbox ar(1)(1) '==> "b"

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Hi all,

> Is it possible in VBScript to return an array of column data as a 1D
> array from a 2D array simply by specifing the current row.

> In c, 2d arrays are stored as a single 1d array of pointers (the row
> information), with each pointer pointing to another 1d array (the
> column data). so to extract a row of column data, you only supply the
> first index of the array. javascript seems to work in a very similar
> way but I cannot do this with vbscript yet.

> is this fundamentally possible in vbscript or not?

> cheers,

> d

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Mon, 28 Apr 2003 03:00:00 GMT  
 Extract a row from a 2D array
Michael,

I did not expect vbscript to differentiate a 2d array from an array of
arrays - I can only assume that underneath vbscript, the 2d array is
actually managed as an array of arrays, but vbscript does not expose
this capability for some reason? I was half expecting and hoping that
VBScript would hold arrays in the same flexible manner that most other
languages do thereby allowing me to do what I need with a single
variable assignment instead of a for-loop running in linear time to the
size of the array!

I guess that if VBScript manages 2D arrays in a different manner to an
array of arrays then there's not much I can do(?) as I am actually
working with 2d arrays explicitly and would *really* like to pull out a
row without having to write a for-loop when it should be acheivable
with a single variable assignment.

Another disappointment with the vbscript language has once again
clouded my ability to write a sensible email - I'll get my coat...

Cheers anyway,

d



Quote:
> You're talking about an array of arrays (not the same as a 2D array),

often referred to as "ragged
Quote:
> arrays" since each row is another array and each row array can have

different dimensions.
Quote:

> dim ar(2)

> ar(0) = array(1,2)
> ar(1) = array("a","b","c")
> ar(2) = array("abc","def","ghi","jkl")

> msgbox ar(1)(1) '==> "b"

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --



Quote:
> > Hi all,

> > Is it possible in VBScript to return an array of column data as a 1D
> > array from a 2D array simply by specifing the current row.

> > In c, 2d arrays are stored as a single 1d array of pointers (the row
> > information), with each pointer pointing to another 1d array (the
> > column data). so to extract a row of column data, you only supply
the
> > first index of the array. javascript seems to work in a very similar
> > way but I cannot do this with vbscript yet.

> > is this fundamentally possible in vbscript or not?

> > cheers,

> > d

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 29 Apr 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. wsh/ jscript : BUG : array of array, 2D array

2. Array of Arrays and 2D array

3. Array Filter Function and 2D Array

4. 2D Array to 1D Array

5. Convert 2d array to 1d array

6. passing 2D array

7. dynamic 2d arrays

8. passing 2D array

9. recordset into 2d array using getrows()

10. Using a var in 2D-array

11. 2D Array Sort in VBScript?

12. Sorting 2D Arrays

 

 
Powered by phpBB® Forum Software