Passing Structure Arrays

Just starting out? Need help? Post your questions and find answers here.
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Passing Structure Arrays

Post by coder14 »

I've been searching through this forum, but can't seem to find anything on this. There've been examples for arrays in structures, and even dimensioning structure arrays. But how would I pass a structure array to a procedure:

Code: Select all

Structure example
  a.l
  b.s
EndStructure

Dim test.example(3)

  test(1)\a = 123
  test(2)\b = "A B C"
  sample(test())

End

Procedure sample(pass.example())
  Debug pass(1)\a
  Debug pass(2)\b
  pass(2)\b = "D E F"
EndProcedure
This is just to illustrate the intended operation, and obviously doesn't work. Can anyone help please?

Cheers!
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Passing Structure Arrays

Post by tinman »

Edit: removed my post as it was incorrect and based on outdated information.
Last edited by tinman on Tue Jun 21, 2011 11:53 am, edited 1 time in total.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Passing Structure Arrays

Post by netmaestro »

Actually your sample code works with remarkably little modification. Simply pass the array as parameter:

Code: Select all

Structure example
  a.l
  b.s
EndStructure

Dim test.example(3)

  test(1)\a = 123
  test(2)\b = "A B C"


Procedure sample(Array pass.example(1))
  Debug pass(1)\a
  Debug pass(2)\b
  pass(2)\b = "D E F"
EndProcedure

sample(test())
sample(test())
BERESHEIT
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Passing Structure Arrays

Post by coder14 »

@netmaestro: Smply brilliant! You got it absolutely right. Thank you!

I tried variations of using the * and @ operators, and also using the Array keyword, but somehow didn't seem to get the right combination. Not very scientific, but that's the way I code.

Thanks to you too tinman. I didn't get a chance to try your code before you yanked it out, but I'm sure it was brilliant.

Back to my code!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Passing Structure Arrays

Post by c4s »

@coder14
Probably Procedure sample(Array pass.example(1)) confused you, at least for me it always was. Just take a look at the help for Procedure and Dim...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Passing Structure Arrays

Post by coder14 »

c4s wrote:@coder14
Probably Procedure sample(Array pass.example(1)) confused you, at least for me it always was. Just take a look at the help for Procedure and Dim...
WHOA! How did I miss that? I poured through the help file like crazy and I still missed that.

I probably need a break. Thanks for the heads up - you guys are great.
Post Reply