Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: Runer112 on October 15, 2012, 11:14:20 am

Title: Store a value to an arbitrary variable?
Post by: Runer112 on October 15, 2012, 11:14:20 am
Is it possible to store a value to an arbitrary real number variable? I tried expr("1"+Str0+"A") as a test (where Str0 contains a store arrow), but it throws an error. I suspect it may not be possible, but if you can think of any hackish way to do it, that would be great. I don't want to have to resort to a 27-branch conditional. :P
Title: Re: Store a value to an arbitrary variable?
Post by: Deep Toaster on October 15, 2012, 11:36:16 am
No, that's not possible—expr( can only handle functions that return a value (no storing or executing commands that start with a capital letter).

I don't know what you need to do, but would using a list work? With lists you can calculate the offset to store to.
Title: Re: Store a value to an arbitrary variable?
Post by: TIfanx1999 on October 15, 2012, 02:00:46 pm
You can read the value of an arbitrary real number, but I don't think you can store a value to an arbitrary real number. expr is limited in that in cannot store a value (or contain the -> character). As Deep Thought asked, is there any reason not to use a list instead of expr? Also, couldn't this be accomplished using ASM, (and accessing the BASIC variables) or is there a reason you want or need this to be in pure BASIC?
Title: Re: Store a value to an arbitrary variable?
Post by: Runer112 on October 15, 2012, 02:31:37 pm
Hmm, I guess I'll either have to think of some tricky find-and-replace way of doing this or suck it up and use the 27-branch conditional. The reason why I wanted this was to let the user input a function of arbitrary variables, which is then searched for any variables and the user is prompted for their values. To then evaluate the function (or a transformation of the function), I need some way of actually assigning those values to the variables.
Title: Re: Store a value to an arbitrary variable?
Post by: Rhombicuboctahedron on October 15, 2012, 03:31:41 pm
Why not just use Request?
Request “variable”, variable
That way variable is defined as the value. I can’t understand what you want to do.
Title: Re: Store a value to an arbitrary variable?
Post by: Hayleia on October 15, 2012, 03:37:04 pm
Why not just use Request?
Request “variable”, variable
That way variable is defined as the value. I can’t understand what you want to do.
We are talking about z80 Basic, not Nspire Basic.
And the equivalent to Request is Input, but that is not what he wants. He wants to put code that would store a value to a variable in a string and "execute the string" (if I understood correctly)
Title: Re: Store a value to an arbitrary variable?
Post by: Builderboy on October 15, 2012, 03:58:17 pm
My suggestion would be to do a simple find and replace of all the variables in the input function.  A would become L1(1), B would become L1(2), and so on.  I created something similar earlier for discreet mathematics and it worked like a charm :)
Title: Re: Store a value to an arbitrary variable?
Post by: Rhombicuboctahedron on October 15, 2012, 05:00:04 pm
Quote
Why not just use Request?
Request “variable”, variable
That way variable is defined as the value. I can’t understand what you want to do.

We are talking about z80 Basic, not Nspire Basic.
And the equivalent to Request is Input, but that is not what he wants. He wants to put code that would store a value to a variable in a string and "execute the string" (if I understood correctly)

Oh, wow
I don't know why I automatically assumed it was Nspire
Title: Re: Store a value to an arbitrary variable?
Post by: Xeda112358 on October 15, 2012, 08:36:06 pm
I know I made an asm program a while ago that stores a list of values to real vars. The real vars are named via a string. Other than that, it is not directly possible in TI-BASIC.
Title: Re: Store a value to an arbitrary variable?
Post by: Deep Toaster on October 15, 2012, 09:39:36 pm
Hmm, I guess I'll either have to think of some tricky find-and-replace way of doing this or suck it up and use the 27-branch conditional. The reason why I wanted this was to let the user input a function of arbitrary variables, which is then searched for any variables and the user is prompted for their values. To then evaluate the function (or a transformation of the function), I need some way of actually assigning those values to the variables.
You can do something like Input "F=?",L1(6) to make it look like you're prompting for the value of F.

I had a program once that accepted an expression of any letter variables. The program scanned through the expression, replacing every instance of the letter with an appropriate list element and prompting for its value in that way, and finally called expr( on the tweaked expression.
Title: Re: Store a value to an arbitrary variable?
Post by: TIfanx1999 on October 15, 2012, 11:52:50 pm
^Yea, this is what I was thinking too if it were to be done in pure BASIC.