Author Topic: Associate TYPE variables with other in automatically (?)  (Read 3417 times)

0 Members and 1 Guest are viewing this topic.

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Associate TYPE variables with other in automatically (?)
« 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?





Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Associate TYPE variables with other in automatically (?)
« Reply #1 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.
Programming isn't difficult, only it's  consuming time and coffee

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: Associate TYPE variables with other in automatically (?)
« Reply #2 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...

« Last Edit: September 02, 2021, 08:59:14 am by krovit »
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Associate TYPE variables with other in automatically (?)
« Reply #3 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, …
« Last Edit: September 02, 2021, 08:58:46 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: Associate TYPE variables with other in automatically (?)
« Reply #4 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!)


Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Associate TYPE variables with other in automatically (?)
« Reply #5 on: September 02, 2021, 10:10:14 am »
I'm with Steve on this. Just make a SUB and fill your TYPE there.
Shuwatch!