Assign to array in structure?

Just starting out? Need help? Post your questions and find answers here.
Smetad_Anarkist
New User
New User
Posts: 8
Joined: Wed Jul 19, 2017 5:50 am

Assign to array in structure?

Post by Smetad_Anarkist »

I'm want to create a structure where one of the fields is an array so I did this

Code: Select all

Structure MyState
   Array statedata.l()
EndStructure
Then I want to assign an array to that field, and everything fell down. I can't figure out how to do that. It appears that I can create a loop to assign individual elements to an array in a structure, but not the entire array. I get syntax error when I try.

Code: Select all

state\statedata() = temp()
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Assign to array in structure?

Post by wilbert »

You can copy the array content with CopyArray.

Code: Select all

Structure MyState
   Array statedata.l(5)
EndStructure

Define state.MyState

Dim MyArray.l(5)
MyArray(4) = 5

CopyArray(MyArray(), state\statedata())

Debug state\statedata(4)
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply