Platforms to show: All Mac Windows Linux Cross-Platform

GetVariantArrayValueMBS(v as Variant, index as Integer) as Variant
Type Topic Plugin Version macOS Windows Linux iOS Targets
global method XojoRuntime MBS Util Plugin 13.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Queries a variant from an array inside a variant.
// some part of app builds an array
dim a() as pair
a.Append 1:"Hello"
a.Append 2:"World"

// passes it as Variant somewhere else

dim v as Variant = a

// and later you may want to get values back without knowing the array type

// this raises TypeMismatchException
'dim o() as Object = v

// so use plugin to get objects:
dim v1 as Variant = GetVariantArrayValueMBS(v, 0)
dim v2 as Variant = GetVariantArrayValueMBS(v, 1)

// now you can check type and cast to the object type
dim p1 as pair = v1
dim p2 as pair = v2

MsgBox p1.Right+" "+p2.Right
This function is to allow getting objects from an array inside a variant without known the class used to declare array.
Returns nil on any error.

Updated in 13.5 plugins to raise exception is array is nil.

Also updated in v13.5 to work with object, variant, string, date, integer, double, single, boolean, Int64 arrays. Other array types will raise exception.

Some examples using this global method:

Blog Entries

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Util Plugin.

The biggest plugin in space...

MBS Xojo PDF Plugins

Start Chat