Title: Is this possible?
Shazane Koronova - August 28, 2007 09:06 PM (GMT)
I would like a program to run a program based on the value of a variable... what I mean is I have something like
| CODE |
If A=3 "S3 If A=4 "S4 Real(10,0,0 prgmXTEMP000 Real(10,1,0
|
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...
Radical Pi - August 28, 2007 09:11 PM (GMT)
Yes, possible. I've wondered about doing the exact same thing.
Number to string:
| CODE |
{Ans,Ans→L2 {0,1→L1 LinReg(a+bx) Y1 Equ►String(Y1,Str1 sub(Str1,1,length(Str1)-3 |
Straight from Weregoose's routine page.
Netham45 - August 28, 2007 09:12 PM (GMT)
you can't avoid this, unless you like do this:
| CODE |
while a=3 prgmFILE1 0->a end while a=2 prgmFILE2 0->a end
|
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.
DJ Omnimaga - August 28, 2007 09:15 PM (GMT)
assuming you want to run a program based on a prefix then numbers, I generally do something like
| CODE |
"S"+sub("0123456789",A,1 Real(10,0,0 prgmXTEMP000 Real(10,1,0
|
Thats what you want to do, right? Basically my version would be replacement for 10 if statements
If u want more than 10 programs:
| CODE |
"S"+sub("0123456789",int(.1A),1)+sub("0123456789",10fpart(.1A),1 Real(10,0,0 prgmXTEMP000 Real(10,1,0
|
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 :)
Shazane Koronova - August 28, 2007 09:48 PM (GMT)
| 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 | CODE | "S"+sub("0123456789",A,1 Real(10,0,0 prgmXTEMP000 Real(10,1,0
|
Thats what you want to do, right? Basically my version would be replacement for 10 if statements
If u want more than 10 programs:
| CODE | "S"+sub("0123456789",int(.1A),1)+sub("0123456789",10fpart(.1A),1 Real(10,0,0 prgmXTEMP000 Real(10,1,0
|
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
DJ Omnimaga - August 28, 2007 09:59 PM (GMT)
then you're stuck you need an if to do this:
| CODE |
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 End |
I didnt tested this one tho so you may need to check to make sure it works fine
Shazane Koronova - August 28, 2007 10:52 PM (GMT)
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...
Radical Pi - August 28, 2007 11:39 PM (GMT)
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.
Shazane Koronova - August 28, 2007 11:54 PM (GMT)
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...
Radical Pi - August 29, 2007 12:15 AM (GMT)
I don't; can you post the full code?
Switching variables would probably be the best thing to do.
DJ Omnimaga - August 29, 2007 12:19 AM (GMT)
never ever use the y var in games, the graph screen operations keeps resetting it
Netham45 - August 29, 2007 04:27 AM (GMT)
Don't use the 'X' var either.
DJ Omnimaga - August 29, 2007 04:49 AM (GMT)
i never got pb with X, but it is recommended that you dont use any vars used by graphs
Shazane Koronova - August 29, 2007 03:01 PM (GMT)
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.