QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Pete on February 01, 2020, 02:03:54 pm
-
Well, every couple of decades I like to try new things. The most recent has been to pass variables to subs almost exclusively of using global variables. Bill would be so proud! Anyway, that's great if I'm making small aps that do not reply on a lot of variables passed to a lot of subs. Right now, I'm in the middle of making a large app, with lots of subs, and I can see it is quickly going to be a PITA to have 20+ variables listed in a sub call! Now I know one way around this would be to use an array, where x$(1) = file_name$, x$(2) = "directory_location$, etc. but is ther anyway this could be done with TYPE, instead? Something like...
mytype.a$ = "Pete"
mytype.b$ = "Steve"
mytype.c = 5
mytype = 123
PRINT mytype.a$
, mytype.b$
, mytype.c
, mytype
I've tried (mytype AS TYPE) - rejected and (mytype AS mytype), also rejected.
Of course I could pass them as (mytype.a$, mytype.b$, mytype.c) but that doesn't save on the number of variables written to the sub call one bit... or byte.
Anyway, I'm either not using TYPE correctly for this, or it just isn't a "feature" of the language. I could go to the WIKI, but it's just not nearly as much as getting your wonderful replies like: "Look you stupid son of a %^&*#, it's done this way!!! Oh I forgot, Clippy doesn't show up around here anymore. Oh well.
Pete
-
DIM variable AS mytype
SUB test (subvariable AS mytype)
^Don’t forget to DIM your variables as your type.
-
fixed
this.a = "Pete"
this.b = "Steve"
this.c = 5
'mytype = 123 'no
test this
PS remember can use string for TYPE but can't file it, need fixed string for that.
-
Way cool!!! That will cut down on all those nasty sub passes I didn't look forward to making.
Thanks guys... I didn't even get to say. "Sorry, you're not mytype!"
Now I'm left wondering what I'll be trying to do differently 20 years from now. Oh yeah, I know, a lid opening app... with hopes that battery life has improved immensely in the future. Hey, can caskets come equipped with LED lighting?
Pete