Hello Guest it is April 19, 2024, 12:33:59 PM

Author Topic: array question  (Read 3783 times)

0 Members and 1 Guest are viewing this topic.

array question
« on: December 10, 2010, 01:35:26 PM »
Is there are way of expressing the assignment "d = c(1)" that works in VB?

"d = a" works and MsgBox(d(0)) returns 11.

a = Array(11, 12, 13)
b = Array(14, 15, 16)
c = Array(a, b)
MsgBox(IsArray(c))  'True
d = c(1)             'Error on line:5 - Type mismatch

Thanks in advance.
Re: array question
« Reply #1 on: December 10, 2010, 04:14:49 PM »
a = Array(11, 12, 13)
b = Array(20, 21, 22)
c = Array(a(1), b(1))
MsgBox(c(0))
MsgBox(c(1))

For x = 0 To 2
  For y = 0 To 2
    d = a(x)
    e = b(y)
    MsgBox(d*e)
  Next y
Next x
« Last Edit: December 10, 2010, 04:19:31 PM by Ya-Nvr-No »
Re: array question
« Reply #2 on: December 10, 2010, 09:44:20 PM »
Thanks for the reply, but it isn't what I want to do.   I want to create an array of references to arrays.

Using my example, here's what I want to do.

a = Array(11, 12, 13)
b = Array(14, 15, 16)
ar = a              'this works in Mach VB, ar is a reference to the array a
MsgBox(ar(1))   'this works in Mach VB, prints 12
c = Array(a, b)  'this compiles in Mach, VB, presumably c contains references to the arrays a and b
d = c(1)           ' this doesn't work, if it did, d would contain a reference to the array b
MsgBox(d(1))    'and it would print 15

The intriguing thing about all of this is IsArray(c(1)) returns true, but I can't figure out a syntax for getting at the elements of the array at c(1).


Re: array question
« Reply #3 on: December 11, 2010, 09:55:52 PM »
gettype=VarType(c)
MsgBox(gettype)
'comes back a 12, Sorry I dont know what a 12 is
'0 thru 8 is all I find.
Guess it cant be done using this version of VB

Re: array question
« Reply #4 on: December 12, 2010, 11:05:59 AM »
Arrays are type 12

a = Array(1,2)
b = Array(3,4)
c = Array(a,b)
MsgBox(VarType(a))         'returns 12
MsgBox(VarType(a(0)))     'returns 2
MsgBox(VarType(c))         'returns 12
MsgBox(VarType(c(0)))     'returns 8204

At
http://www.chennaiiq.com/developers/reference/visual_basic/functions/vartype.asp
I discovered 8204 is an array of variants

According to information found other places using the search "vartype 8204", to It should be possible to do either:
     MsgBox(c(0)(0) )
or
    ar=c(0)
    MsgBox(ar(0))
to get the the first element of the array a.

Guess this is a bug in the version of Cypress Enable that Mach uses.



Re: array question
« Reply #5 on: December 12, 2010, 05:57:36 PM »
Maybe the powers to be, will take notice and solve the issue, thanks for the lesson.