QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: krovit on September 02, 2021, 07:44:43 am

Title: Associate TYPE variables with other in automatically (?)
Post by: krovit on September 02, 2021, 07:44:43 am
Hello

is there a way to automatically associate (with an algorithm) a series of variables defined with TYPE to others, for example a$() ?

for example, let's say that:
TYPE varx
 one AS STRING * 1
 two AS INTEGER
 ...
END TYPE

to avoid writing (think when there are many variables):
 varx.one = a$(1)
 varx.two = a$(2)
 ...


what do you say? there may be a system to do it automatically so you don't have to write ad hoc code every time?





Title: Re: Associate TYPE variables with other in automatically (?)
Post by: TempodiBasic on September 02, 2021, 08:05:01 am
Hi
indeed following your example I need to solve a dubt...
TYPE groups a set of variables of  different types among them
Array$ is a string array... so are you searching an alghorytm to translate digits (integer, single, double) into a string and viceversa for this kind of situation?
in your example varx.two is a digit integer while a$(2) is a string.
Title: Re: Associate TYPE variables with other in automatically (?)
Post by: krovit on September 02, 2021, 08:53:41 am
Ciao Tempodibasic

Obviously I left out the necessary steps for conversion between the various types of variable.

The TYPE structure is necessary and preparatory for the archives.

I built a system designed to work in any case study that relies - at the time of data entry - on indexed variables.

In practice, write and enter what you want - according to the pre-established forms and also generated automatically - and in the end everything is reduced to dealing with a single indexed variable.
If I dealt every time and from the beginning only the variables defined TYPE could not exist a universal system valid for any form!

However, it is obviously that when I have to deal with the archives those variables must be associated with precise variables defined with TYPE - END TYPE and the problem of assigning them arises.

Until today I am forced to write a piece of ad hoc code that associates the variables. so, for example, the var$(123) will correspond - in that archive and for that form - xxx.vartype, and var$(15) to yyy.vartype.

It would be nice and useful if there could be a system to do it within a procedure and maybe with a DO-LOOP or similar without writing the appropriate code every time.

I'm afraid it's not possible... but you never know...

___
who knows if the BING translator was useful...

Title: Re: Associate TYPE variables with other in automatically (?)
Post by: SMcNeill on September 02, 2021, 08:56:45 am
Can’t you use a SUB for this?

SUB AssignVarx (varx AS varx, a$, i%,…)
    varx.one = a$
    varx.two = i%
    … more assignments
END SUB

Then just call the sub.

AssignVarx varx, “foo”, 123, …
Title: Re: Associate TYPE variables with other in automatically (?)
Post by: krovit on September 02, 2021, 09:05:39 am
Hi SMcNeill

yes, of course!
You see, however, that you had to write a piece of code ad hoc.

I repeat, I do not think it is possible, but we need a system like:

FOR m=1 TO to n
    varx.??? = var-the type at this time is not important(m)
NEXT m

the problem is those ??? (and of course they are!)


Title: Re: Associate TYPE variables with other in automatically (?)
Post by: SpriggsySpriggs on September 02, 2021, 10:10:14 am
I'm with Steve on this. Just make a SUB and fill your TYPE there.