In a program using the xLIBc lib, I'm trying to basically make an input token, within the xLIBc half-res mode. I've tried (without success) to run a getkey loop, each time searching for the number keys, and once a key was pressed, it would take the getkey and change it back to the number it was (92 would become 1, 93 would become 2, etc.) then, if it isn't the first key pressed, it would multiply the original number by 10, and add the new number (so like to write the number 25, you would press 2, then when you press 5, it does 2*10+5, which is 25) and then basically once the period is pressed, it restarts the loop from the beginning, this time saving the number to a different var, and outputting that one (since the real(6,0,... only outputs the iPart of the number) and then, dividing the number after the decimal by 10^n where n is the number of digits, and then adding both the iPart and the fPart of the number together to carry on with the correct number in the rest of the program. Needless to say this was bound to fail due to the strange complexity of the process, I'd like to know if anyone else has done it (surely), and if so, how? because right now, my program exits half-res mode and runs a normal input, but that's just plain ugly Wink
http://tibasicdev.wikidot.com/key-code-to-letter may help (I wrote the 'alternate' routine, although I don't recommend you use it)
A question I've been pondering for a while: Why did you post the alternate routine when you knew it was worse than Weregoose's?

Furthermore, why are there multiple versions of many other routines on tibasicdev's routines page, often with notes that say that one is strictly better than the other?
To be honest, I don't really remember myself. It was originally because Weregoose's had to wait for input and mine was in a loop, but then I realized that Weregoose's could be easily adapted... I think it may have been just for future reference on my part, which I guess probably isn't what a wiki should be used for.

In regards to your edit, maybe others had the same thought process as me...? I dunno.
okay well I went to grab the code linked by M. I. Wright, and it works, but I would need it to be able to handle decimals and negative numbers, for now, it outputs the number and stores it to C, but will return a syntax error if the negative or decimal keys are pressed...

Code:
DelVar CDelVar B
1->A
Lbl A
Repeat Ans>71 and min(Ans!={45,75,81,85
getKey
End
sub("789  456  123  0.~",Ans-36-5int(.1Ans),1
expr(Ans->B
Output(1,A,Ans
If A=1:Then
B->C:A+1->A:Goto A
Else
10C+B->C
A+1->A
Goto A

edit:I worked on it a little today and managed to get the negative numbers and decimal numbers working in pure basic, but I used the position of the text as a variable in the code, which worries me for implementation into the actual hybrid program where instead of having a 26*10 screen, i would have the half res mode screen, but here is the code I came up with, surely there is room for optimisation Wink

Code:
DelVar CDelVar BDelVar F
1->A:1->D
Lbl A
Repeat Ans>71 and min(Ans!={45,75,81,85,91,95
getKey
End
If Ans=103:Then:C->E:DelVar C:2->F:A->G:Output(1,A,".":A+1->A:Goto A
Else:If Ans=105:Then:Goto B
Else:If Ans=104:Then:~1->D:A+1->A:Output(1,1,"~":Goto A
Else:If Ans!=104 and Ans!=105 and Ans!=103:Then
sub("789  456  123  0",Ans-36-5int(.1Ans),1
expr(Ans->B
Output(1,A,B
If not(A:Then
B->C:A+1->A:Goto A
Else
10C+B->C
A+1->A
Goto A
Lbl B
If F=2:Then:C/10^(A-G-1)->C
C+E->C
DC->C
Output(2,1,C
Pause
Else:If F!=2:Then:DC->C
Output(2,1,C

edit 2: worked on it some more, this time, got it into xLIBc, only thing is, can't have numbers over 9999, but thats always the case with xLIBc, and besides, noone needs big numbers like that lol anyways, it's nearing completion, will soon be putting it into the real program :3

Code:
1->I
"V1=V2= a= t= S=->Str2
Lbl C
10->H
real(0,1,1
real(0,3,4,8
sub(Str2,I,3->Str3
Str3
real(6,0,5,5,248
real(7,7,2,2,156,116,248
real(7,7,0,0,160,120,248,1
DelVar CDelVar BDelVar FDelVar J
1->A:1->D
Lbl A
Repeat Ans=45 or Ans>71 and min(Ans!={75,81,85,91,95
getKey
End
If Ans=103:Then:C->E:DelVar C:2->F:A->G:AH->H:2->J
A+1->A:Goto A
Else:If Ans=105:Then:Goto B
Else:If Ans=104:Then:~1->D
Goto A
Else:If Ans=45:Then:Goto C
Else:If Ans!=104 and Ans!=105 and Ans!=103:Then
sub("789  456  123  0",Ans-36-5int(.1Ans),1
expr(Ans->B
If not(A:Then
B->C:A+1->A:Goto A
Else
10C+B->C
A+1->A
real(0,3,4,8
real(7,7,2,2,156,116,248
real(7,7,0,0,160,120,248
Str3
real(6,0,5,5,248
If E and J=2:Then
",
real(6,0,H-6,15,248,0
End
If D=~1:Then
"-
real(6,0,3,15,248
End
If F=2:Then
real(6,1,10,15,248,E,0
End
real(6,1,H,15,248,C,1
Goto A
Lbl B
If F=2:Then:C/10^(A-G-1)->C
C+E->C
DC->C
Goto D
Else:If F!=2:Then:DC->C
Lbl D
I+3->I
Goto C
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement