QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: qbkiller101 on June 02, 2020, 01:45:56 pm
-
hi,
is it possible to dim vars in subs and functions
and also
could someone give me a function/sub, if possible, that would be called like so : createvar("a") and would dim a var using that parameter or at least find the last var and add num 1 to it e.g. last var made:avariable, function would dim var called avariable1 then when called again avariable2
please help
-
Hi @qbkiller101,
You are requesting reply: https://www.qb64.org/forum/index.php?topic=2652.msg118729#msg118729
But did you understand Fellippe's reply here: https://www.qb64.org/forum/index.php?topic=2659.msg118684#msg118684
Which is just what I did here a month ago! here:
https://www.qb64.org/forum/index.php?topic=2553.msg117861#msg117861
Which got such a bad off topic response the rest of the thread is crap! :P
If you understand Fellippe's and my idea then it is piece of cake to make a sub as you request only question is:
What type value do you want variables to be?
Integer, float or string are main choices OR way more complicated sub to handle any of 3 (maybe) that is what complicates the UDT's (User Defined Type).
We need to know the data type when we make up variables, QB64 is that way you know.
Actually I bet you can do this yourself, if you understand UDT's?
If you don't, we should go over that first.
-
On the other hand you could skip UDT's and go with 2 arrays, vNames and vValues say, that would be synchronized by same index, but you still need to specify what type for values array and need a separate list of array names and values for each type value you want to track.
ie IntegerVarNames$() and Integers() as Integer, DoubleVarNames$() and Doubles() as Double, ...
-
Actually I found a great application for this and wrote it up in JB, another pre-Interpreter like program that reads formulas and variables from tables and saved to file. I could append it to PLOT program.
-
BTW
is it possible to dim vars in subs and functions
Yes, of course! In fact if you use OPTION _EXPLICIT you must.
You know this:could someone give me a function/sub, if possible, that would be called like so : createvar("a") and would dim a var using that parameter or at least find the last var and add num 1 to it e.g. last var made:avariable, function would dim var called avariable1 then when called again avariable2
please help
read another way, almost sounds like you want an array.
avariable(1)
avariable(2)
avariable(3)
...