Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Combining 2 vectors into one array

16 views
Skip to first unread message

avi

unread,
Mar 27, 2013, 2:37:06 PM3/27/13
to
I have 2 vectors of same size

Dim x()
Dim y()
x(1) = 2
x(2) = 11
x(3) = 31

y(1) = 4
y(2) = 5
y(3) = 3

I want a 2 dimensional array Arr()
2 4
11 5
31 3

Thanks
Avi


GS

unread,
Mar 27, 2013, 8:14:02 PM3/27/13
to
Dim x(1 to UBound(x), 1 to 1), n&
For n = 1 To UBound(z)
z(n) = x(n): z(n, 1) = y(n)
Next 'n

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


GS

unread,
Mar 27, 2013, 8:14:58 PM3/27/13
to
Oops.., typo...

Dim z(1 to UBound(x), 1 to 1), n&

Carlos Rocha

unread,
Mar 27, 2013, 9:39:25 PM3/27/13
to
> Dim x()
> Dim y()
>
> x(1) = 2
> x(2) = 11
> x(3) = 31
>
> y(1) = 4
> y(2) = 5
> y(3) = 3
>
> I want a 2 dimensional array Arr()
>
> 2 4
> 11 5
> 31 3

It's not possible to do something like this in VB6?

Dim Arr

Arr = {x, y}

I can do this in my IDE (not vb6)

GS

unread,
Mar 27, 2013, 10:22:19 PM3/27/13
to
Uh, the example I posted IS VB!

GS

unread,
Mar 27, 2013, 10:35:42 PM3/27/13
to
Duh.., I'll be alright if I just focus on what my intent is...

Dim z(1 To 3, 1 To 2), n&
For n = 1 To UBound(x)
z(n, 1) = x(n): z(n, 2) = y(n)

Carlos Rocha

unread,
Mar 27, 2013, 11:50:04 PM3/27/13
to
>
> Uh, the example I posted IS VB!
>

Yes, I know it's VB :)
I was meant if it's possible to assign a full array to another array element

Arr = {{2, 11, 31}, {4, 5, 3}}

ralph

unread,
Mar 28, 2013, 1:18:19 AM3/28/13
to
Not as a single declaration, but you can achieve something close to
this by declaring a Variant array of Variants and then assign an array
of constants, created by the Array() function, to each element.

Dim vArr(2) As Variant
vArr(0) = Array(2, 11, 31)
vArr(1) = Array(4, 5, 3)

SomeVal = vArr(x)(y)

-ralph

GS

unread,
Mar 28, 2013, 1:21:15 AM3/28/13
to
Ok, I see what you meant. Nope, can't do it that way (AFAIK). But you
can do this...

Dim v(2, 2), n&, i&
v(0, 0) = Array(1, 2, 3)
v(0, 1) = Array(4, 5, 6)
v(0, 2) = Array(7, 8, 9)
v(1, 0) = Array(10, 11, 12)
v(1, 1) = Array(13, 14, 15)
v(1, 2) = Array(16, 17, 18)
v(2, 0) = Array(19, 20, 21)
v(2, 1) = Array(22, 23, 24, 25)
v(2, 2) = Array(26, 27, 28, 29)

For n = LBound(v) To UBound(v)
For i = LBound(v, 2) To UBound(v, 2)
Debug.Print Join(v(n, i), ",")
Next 'i
Next 'n

..where arrays are assigned to individual elements. Hence, an array of
arrays!

Ulrich Korndoerfer

unread,
Mar 28, 2013, 6:06:29 PM3/28/13
to
Hi,

Carlos Rocha schrieb:
If literal array initialisers shall be used, Ralph and others already
showed you the way.

In general it is possible to assign whole arrays of any kind to
variables of type Variant. So

Dim A() As Long, B() As Long, V() As Variant

ReDim A(0 To 1): A(0) = 1: A(1) = 2
ReDim B(0 To 1): B(0) = 3: B(1) = 4
ReDim V(0 To 1): V(0) = A: V(1) = B

is perfectly legal. Access is a little bit unconventional: V(1)(0) would
adress the Long value 3 of B at index 0

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.prosource.de/Downloads/
MS Newsgruppen Alternativen -> http://www.prosource.de/ms-ng-umzug.html

Henning

unread,
Mar 28, 2013, 7:16:57 PM3/28/13
to

"Carlos Rocha" <jazzd...@gmail.com> skrev i meddelandet
news:dbdc6d87-dd9a-4950...@googlegroups.com...
And what is the point, if using VB6?? Not very helpful, would it in your
mind be some kind of show off?

/Henning



0 new messages