Structure questions

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
victorf
Posts: 342
Joined: 01 January 2006, 4:08 AM
Location: Schenectady, New York

Structure questions

Post 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
Vic Fraenckel
KC2GUI
windswaytoo ATSIGN gmail DOT com
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Structure questions

Post 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.
- Don Kinzer
Post Reply