Structured variables

Question:
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?

Answer:
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.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a