Author Topic: Dim in sub/function, createvar()  (Read 2908 times)

0 Members and 1 Guest are viewing this topic.

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Dim in sub/function, createvar()
« 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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dim in sub/function, createvar()
« Reply #1 on: June 03, 2020, 11:57:28 am »
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.
« Last Edit: June 03, 2020, 12:02:21 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dim in sub/function, createvar()
« Reply #2 on: June 03, 2020, 12:36:01 pm »
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, ...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dim in sub/function, createvar()
« Reply #3 on: June 03, 2020, 12:46:00 pm »
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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dim in sub/function, createvar()
« Reply #4 on: June 03, 2020, 01:28:24 pm »
BTW
Quote
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:
Quote
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)
...
« Last Edit: June 03, 2020, 01:33:24 pm by bplus »