Page 1 of 1

Structure questions

Posted: 07 February 2008, 7:09 AM
by victorf
Is it legit to do this:

Structure MyStruct
var1 as Single
var2 as Single
End Structure

Dim MyArray(1 to 3) of MyStruct

In other words can I have an array of structures?


Also, am I correct that I can do this? SysLib seems to say so:

"A variable that is a structure may be assigned to another variable that is the same type of structure using the standard assignment operator."

Dim A as MyStruct
Dim B as MyStruct

A.var1 = 0.0
A.var2 = 1.0

B = A '<==== CAN I DO THIS

Any enlightenment will be appreciated

Vic

Re: Structure questions

Posted: 07 February 2008, 7:35 AM
by dkinzer
victorf wrote:Is it legit to do this:

Code: Select all

Structure MyStruct
  var1 as Single
  var2 as Single
End Structure
Dim MyArray&#40;1 to 3&#41; of MyStruct
Yes. The structure members, however, need either Dim, Public or Private.

Code: Select all

Structure MyStruct
  Dim var1 as Single
  Dim var2 as Single
End Structure
victorf wrote:

Code: Select all

Dim A as MyStruct
Dim B as MyStruct

A.var1 = 0.0
A.var2 = 1.0

B = A       '<==== CAN I DO THIS
Yes. You can also check structure variables for equality/inequality using =/<> just like non-structure variables. One caveat, however, is that these operations on structures containing members that are allocated strings are either disallowed (for assignment) or result in a warning (comparison). Structure members that are bounded strings do not impose the same limitations.