devxlogo

Initializing Array of UDT’s

Initializing Array of UDT’s

Question:
Here’s some simple code in Test.bas:

Public Type MY_RECORD    Field1 as String    Field1 as StringEnd Typein frmTest.frmGeneral DeclarationsPrivate mArrayOfRecords() as MY_RECORDForm_Load    'this line of code BOMBS    If IsEmpty(mArrayOfRecords) then        'dimension it    End IfEnd Sub

OK, Why can’t I check if an array of user defined types has been initialized? IsEmpty does not work, nor does TypeName, VarType or any other type checking function. I get errors when I attempt to check the state of an un-initialized array of UDT’s. Any explanations?

Answer:
Typically, UDT members are initialized the same way that regular variables of the same type are (i.e., strings are empty strings, numbers are zero, etc.).

The best way to check your UDT is to either check the individual members or to add an extra member that can hold a true/false value to indicate if the UDT has been initialized.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist