As an example, consider the following IDL union:
module TMod { union TUnion switch (long) { case 5: long lVal; case 9, 7: short sVal; default: double dVal; };};
The following Visual Basic code sets each member:
dim myUnion as TUnion set myUnion = new TUnion myUnion.lVal = 43000 myUnion.sVal = 43 myUnion.dVal = 43.43
The following code checks the discriminator and accesses the value if the lVal member is set:
if (myUnion.discriminator = 5) then print "Current value is " & myUnion.lVal endif