Variable Created At Runtime

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Post Reply
MattC
Posts: 49
Joined: Mon 16 Apr 2018, 06:17

Variable Created At Runtime

Post by MattC » Fri 19 Apr 2019, 07:05

Hi,

I (re)found this under "Procedures and functions" in the help and don't follow the way it works. Could someone please explain the processes behind it so I can understand it more fully.

Code: Select all

INPUT "Enter a variable name: " name$
INPUT "Enter a numeric value for the variable: " value$
dummy% = EVAL("FNassign("+name$+","+value$+")")
PRINT "The variable "name$" has the value ";EVAL(name$)
END
DEF FNassign(RETURN n, v) : n = v : = 0
Thanks

Matt

DDRM
Administrator
Posts: 133
Joined: Mon 02 Apr 2018, 18:04

Re: Variable Created At Runtime

Post by DDRM » Fri 19 Apr 2019, 09:40

Hi Matt,

I'm open to correction here, but my understanding is:

In Fnassign, the variable to which the value is to be assigned is passed by reference (because of the RETURN): that is to say, the variable passed in will be directly affected by what happens in the function.

When you call FNassign (using EVAL to construct the call from the desired name string), it creates a variable with the specified name (since it doesn't already exist), and passes it to the function, which fills in the value.

Hope that's helpful (and something like true - I dare say Richard will let me know if not...)

Best wishes,

D

MattC
Posts: 49
Joined: Mon 16 Apr 2018, 06:17

Re: Variable Created At Runtime

Post by MattC » Fri 19 Apr 2019, 10:32

Still not sure, but thanks anyway.

I think the problem is I don't fully understand the way EVAL works. But that's OK at the moment. The question was just out of curiosity, rather than practicality.

Thanks again.

Matt

Post Reply