BBC BASIC for Windows
« Assigning values to Structure variables »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:10pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Assigning values to Structure variables  (Read 535 times)
Joe68
New Member
Image


member is offline

Avatar




PM


Posts: 19
xx Assigning values to Structure variables
« Thread started on: Sep 27th, 2015, 11:55am »

Hi All.

I wonder if anyone can help me with this - or tell me what I am doing wrong.
I can assign values to arrays as per the example below.
I thought I could do the same with a structure (I didn't find anything in other posts, Help file, Programmers' Wiki to say I couldn't).

Examples:
Code:
      DIM Env(2)
      Env(0)=5
      Env(1)=2
      Env(2)=8
      REM -- with an array I can also assign values like this...
      Env()=5,2,8 

Code:
      DIM Env{(2)min,setpoint,max}
      Env{(0)}.min=5
      Env{(1)}.min=2
      Env{(2)}.min=8
      REM -- but I can't do the same with a structure.

      Env{()}.min=5,2,8
      REM -- invokes 'Mistake' error message 


Any advice?
Or must I use Struct{(n)}.member=value ?

Thanks.
Joe.
User IP Logged

Joe
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Assigning values to Structure variables
« Reply #1 on: Sep 27th, 2015, 4:28pm »

Hi Joe,

To quote from the Mikado: "The fact appears to be as you've recited": I also get "mistake" if I try to allocate all the equivalent members of a structure array at the same time.

I'm not really surprised: the numbers in a simple array follow each other in memory, so it's a simple matter to write them consecutively, but I suspect that the whole STRUCTURE's worth of data is stored as a block, so the equivalent members of consecutive structures in an array will not be consecutive, making an equivalent function a lot more difficult.

Just because something is not explicitly forbidden it doesn't mean it will work ;-) I think you'll need to use the format you suggest at the end of your post - though you could "automate" it to some extent using a loop and a DATA statement.

Best wishes,

D
User IP Logged

Joe68
New Member
Image


member is offline

Avatar




PM


Posts: 19
xx Re: Assigning values to Structure variables
« Reply #2 on: Sep 27th, 2015, 7:06pm »

Thanks DDRM for your reply.

As an amateur / hobbyist I appreciate insights from more experienced programmers.

As you so correctly state, "just because its not explicitly forbidden doesn't mean it'll work". wink But I thought that maybe I just had the syntax wrong or a bracket in the wrong place.

I was hoping to avoid DATA statements and associated RESTOREs - I already have plenty data in my program, but loops, READ and DATA are the only way to go.

Cheers.
Joe
User IP Logged

Joe
Zaphod
Guest
xx Re: Assigning values to Structure variables
« Reply #3 on: Sep 27th, 2015, 10:55pm »

If you don't want more data statements you could assign the data to an array in one line as you hoped to do for the structure and then transfer it to the structure with a loop.
User IP Logged

Joe68
New Member
Image


member is offline

Avatar




PM


Posts: 19
xx Re: Assigning values to Structure variables
« Reply #4 on: Oct 10th, 2015, 11:57am »

Hi Zaphod.

Thanks for your reply.

I am assuming you mean something along the lines of the following:
Code:
      DIM envmin(2)
      envmin()=1,2,3

      DIM Env{(2)min,sp,max}
      FOR i=0 TO 2
        Env{(i)}.min=envmin(i)
        PRINT Env{(i)}.min
      NEXT 


That's an approach I had not considered, I'll see how it works in my program and if it will affect the consistency of it (as I said, I have a lot of other data statements for other parameters).

Cheers.
Joe
User IP Logged

Joe
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls