Tuesday, December 16, 2008

[vb6] Use variants for passing arrays to and from classes

An array can be packed in a single variable of type variant. This goes for arrays of any datatype except user-defined types and fixed-length strings. The variant can then be passed to and from functions and subs, e.g.
In a calling procedure:
    Dim B(20) as Byte
Dim V as Variant
V = B
'Call the sub "MySub"
MySub (V)
'-----------------
'In MySub:
Dim Bb() as Byte
Dim Vb as Variant
Bb = Vv
'The Bb array is redimensioned automatically.
Similarly, the variant can be passed back in the form of function result.

No comments:

Post a Comment