Author Topic: Is this possible?  (Read 3442 times)

0 Members and 1 Guest are viewing this topic.

Shazane Koronova

  • Guest
Is this possible?
« on: August 28, 2007, 10:06:00 am »
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...

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Is this possible?
« Reply #1 on: August 28, 2007, 10:11:00 am »
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.
One of these days I'll get a sig I'm really proud of.

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Is this possible?
« Reply #2 on: August 28, 2007, 10:12:00 am »
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.
Omnimaga Admin

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Is this possible?
« Reply #3 on: August 28, 2007, 10:15:00 am »
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 :)smile.gif

Shazane Koronova

  • Guest
Is this possible?
« Reply #4 on: August 28, 2007, 10:48:00 am »
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 :)smile.gif

 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

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Is this possible?
« Reply #5 on: August 28, 2007, 10:59:00 am »
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

Shazane Koronova

  • Guest
Is this possible?
« Reply #6 on: August 28, 2007, 11:52:00 am »
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...

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Is this possible?
« Reply #7 on: August 28, 2007, 12:39:00 pm »
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.
One of these days I'll get a sig I'm really proud of.

Shazane Koronova

  • Guest
Is this possible?
« Reply #8 on: August 28, 2007, 12:54:00 pm »
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...

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Is this possible?
« Reply #9 on: August 28, 2007, 01:15:00 pm »
I don't; can you post the full code?
Switching variables would probably be the best thing to do.
One of these days I'll get a sig I'm really proud of.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Is this possible?
« Reply #10 on: August 28, 2007, 01:19:00 pm »
never ever use the y var in games, the graph screen operations keeps resetting it  

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Is this possible?
« Reply #11 on: August 28, 2007, 05:27:00 pm »
Don't use the 'X' var either.
Omnimaga Admin

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Is this possible?
« Reply #12 on: August 28, 2007, 05:49:00 pm »
i never got pb with X, but it is recommended that you dont use any vars used by graphs

Shazane Koronova

  • Guest
Is this possible?
« Reply #13 on: August 29, 2007, 04:01:00 am »
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.