It seems like I cannot define my own data structures in OPO. I want to create an variable that actually consists of different underlying variables – a string followed by a number followed by a date. Is there any way I can create a variable with this type of structure?
You may be talking about the ability to define a data type in Visual Basic, and then instantiate new instances of the data type when you need them. You can get to the same functional place with Power Objects, but you have to take a slightly different route.
You cannot create a variable that is composed of other variables, but you can create a standalone recordset that contains different columns which represent the parts of data. You start by creating a standalone recordset with the NEW operator like:
DIM objRecSet AS ObjectobjRecSet = NEW RECORDSET
If you want to create the data structure mentioned in the question, you would add columns to the standalone recordset with code like this:
objRecSet.AddColumn(“StringCol”, RecDty_String) objRecSet.AddColumn(“NumberCol”, RecDty_Long) objRecSet.AddColumn(“DateCol”, RecDty_Date)
The first variable for the AddColumn() function is the name that will be given to the column. You can reference the column by either the name or the position number of the column. The RecDty_ constants identify the data types of the columns created.
The standalone recordset referenced by the variable objRecSet now contains the columns that you will need to hold the different parts of the data structure. Typically, you would use this code to create the recordset in a method that is executed once and early, such as the OnLoad() method of the form.
The recordset you create with this code will exist as long the object whose OnLoad() method is still in memory. The objRecSet variable, however, will disappear as soon as the method completes. You will have to add a user-defined property with a data type of “Object” and set the value of the variable to objRecSet variable before the method completes.
To add a new instance of the data structure, you use the InsertRow() method for the recordset. To get the values for the instance, you set the current row in the recordset with the SetCurRow() and reference the column with the GetColVal() method for the recordset.