-
I would like a program to run a program based on the value of a variable... what I mean is I have something like
c1-->CODE |
ec1 If A=3 "S3 If A=4 "S4 Real(10,0,0 prgmXTEMP000 Real(10,1,0 c2 |
ec2
I want to do it without the if process because it gets long and wastes alot of code.
What I need is a way to turn a numeric variable into a string or else another way around this problem...
-
Yes, possible. I've wondered about doing the exact same thing.
Number to string:
c1-->CODE |
ec1{Ans,Ans→L2 {0,1→L1 LinReg(a+bx) Y1 Equ?String(Y1,Str1 sub(Str1,1,length(Str1)-3c2 |
ec2
Straight from Weregoose's routine page.
-
you can't avoid this, unless you like do this:
c1-->CODE |
ec1 while a=3 prgmFILE1 ->a end while a=2 prgmFILE2 ->a end c2 |
ec2
which is even uglier and more pointless.
Edit: Actually on second thought, I think there might be an ASM utility to do this, but it's impossible from pure BASIC.
-
assuming you want to run a program based on a prefix then numbers, I generally do something like c1-->
CODE |
ec1 "S"+sub("0123456789",A,1 Real(10,0,0 prgmXTEMP000 Real(10,1,0 c2 |
ec2Thats what you want to do, right? Basically my version would be replacement for 10 if statements
If u want more than 10 programs:
c1
-->CODE |
ec1 "S"+sub("0123456789",int(.1A),1)+sub("0123456789",10fpart(.1A),1 Real(10,0,0 prgmXTEMP000 Real(10,1,0 c2 |
ec2
basically if A=56 the program will check for prgmS56. However MAKE sure your program has two digits, else it may cause bad things to happen. Like don't do S1 instead of S10 for example
I hope this help out :)

-
QuoteBegin-DJ Omnimaga+28 Aug, 2007, 16:15-->
QUOTE (DJ Omnimaga @ 28 Aug, 2007, 16:15) |
assuming you want to run a program based on a prefix then numbers, I generally do something like c1-->CODE | ec1 "S"+sub("0123456789",A,1 Real(10,0,0 prgmXTEMP000 Real(10,1,0 c2 |
ec2Thats what you want to do, right? Basically my version would be replacement for 10 if statements
If u want more than 10 programs: c1 -->CODE | ec1 "S"+sub("0123456789",int(.1A),1)+sub("0123456789",10fpart(.1A),1 Real(10,0,0 prgmXTEMP000 Real(10,1,0 c2 |
ec2 basically if A=56 the program will check for prgmS56. However MAKE sure your program has two digits, else it may cause bad things to happen. Like don't do S1 instead of S10 for example I hope this help out :)  |
I wrote it all out with Radical Pi's solution while you were writing this.... but this is definitely alot more efficient
However... what if I have single and double digits? S8, S9, S10, S11 and so on
-
then you're stuck you need an if to do this:
c1-->CODE |
ec1 If A>9 Then "S"+sub("0123456789",int(.1A),1)+sub("0123456789",10fpart(.1A),1 Real(10,0,0 prgmXTEMP000 Real(10,1,0 Else "S"+sub("0123456789",A,1 Real(10,0,0 prgmXTEMP000 Real(10,1,0 Endc2 |
ec2I didnt tested this one tho so you may need to check to make sure it works fine
-
Well, the current code is more efficient than that... So Radical Pi's worked just fine.
Except for a phenomenon that cant possibly be caused by this new code...
I have an important variable Y that gets deleted for no reason.... that code doesn't even execute for it to happen but I haven't changed anything else at all. I couldnt even post the code until I can manage to isolate the problem, I cant tell where it happens...
-
Do you do anything with the graphscreen? That could wipe the Y variable at times. It does for X I know...
Also, that wasn't my code. I even said it up there.
But, it works for single digit numbers, and all digit numbers (within reason), which was the point.
-
Oh yeah, I just meant the code you posted.
I constantly use the graph screen, and it has NEVER done this. Actually, I remember a long time ago I had this problem on someone's 83+...
any way you know of to make it not do this without changing the varialbe, because I'd have to change it in alot of places...
-
I don't; can you post the full code?
Switching variables would probably be the best thing to do.
-
never ever use the y var in games, the graph screen operations keeps resetting it
-
Don't use the 'X' var either.
-
i never got pb with X, but it is recommended that you dont use any vars used by graphs
-
I solved it simply by doing something meaningless with Y after using the Y1 variable, because I figured out that it only erases Y the first time you use it afterwords and then it doesnt happen.