Jump to content



Photo
- - - - -

How To Convert Getkey Value To Number


  • Please log in to reply
8 replies to this topic

#1 zerocool

zerocool

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 09 February 2005 - 01:56 AM

I need to figure out what number key was hit, by using getkey.

Would it be faster to use 10 if then statements, or would it be better to use a formula to convert it. and what is a formula that i can use?

so far i have

getkey->G
((G-(Int(G/10)*10)-2)*3)+(8-Int(G/10))->G

G is the number that is pressed. Only to slight problems:
1) its a bit slow, and i was wondering it it could be done quicker
2) it doesnt recognize 0, its return -2 for 0... :banghead:

any help would be apreciated :nod:

thanks,
Zerocool

#2 dscoshpe

dscoshpe

    Casio Freak

  • [Legends]
  • PipPipPipPip
  • 185 posts
  • Location:California, USA

  • Calculators:
    AFX 2.0 (v1.00), 9850Ga+, 9800, BE-300 other..

Posted 09 February 2005 - 07:04 AM

Oh man, I had this same problem a while back too!

I don't have the solution any more but I will have you know that there IS a mathematical one that isn't slow as hell. I seem to remember having made the getkey values negative for some reason... *shrug* if I remember any more I'll check in.

- dscoshpe -

#3 genesis

genesis

    UCF BASIC Programming Runner Up

  • Super Member
  • PipPipPipPip
  • 281 posts
  • Location:Perth, Australia
  • Interests:Speaking German, computers, defending CFX calculators...

  • Calculators:
    CFX 9850 GB+

Posted 09 February 2005 - 09:51 AM

Good maths practice... :D

3G-31Int (G/10)+2->G
G=-2=>0->G
Trust me, I used to think doing it all in one line was better, but it turns out to be slower. It would probably be even better to split up the above formula.

Have you tried my grouping technique? When you have a lot of statements, the calc has to go through all of them. If you split them up into other statements, its doesn't have to go through all of them. For example,

If A<3
Then A=1=>""
A=2=>""
Else A=3=>""
A=4=>""
IfEnd


#4 Andy.Davies

Andy.Davies

    Forum Ghost

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1547 posts
  • Gender:Male
  • Location:Dorset, England
  • Interests:Age: 18
    Studying: MEng in cybernetics at Reading uni
    Interests: Progaming (VB, VB.Net, C#, Casio Basic)
    Computers UBBD (Using, Building, Breaking &amp; Destroying)
    Gaming (FPS, RTS, RPG)
    Electronics
    Rock Music (Preferably Loud)
    Riley's (Pool &amp; Snooker Bar)
    Driving (Preferably fast)
    Aikedo (Martial Art)

  • Calculators:
    Algebra FX 2.0 ROM 1.01, FX9750G

Posted 09 February 2005 - 11:44 AM

Please dont use Genesis's code! there is a nice quick method:

Getkey  -> A
A=>71=>B=0
A=>72=>B=1
A=>62=>B=2
A=>52=>B=3
A=>73=>B=4
A=>63=>B=5
A=>53=>B=6
A=>74=>B=7
A=>64=>B=8
A=>54=>B=9

this is a much quicker method of using if statements.
the => symbol is under <span class=Shift' /> <span class=VARS' /> <span class=F3' /> <span class=F3' />
-> is above the [AC/on] key on the calc.

#5 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 09 February 2005 - 12:12 PM

but with that method, even if you press <span class=1' /> it will test for every other key...

#6 Marco

Marco

    Casio Freak

  • Members
  • PipPipPipPip
  • 185 posts
  • Location:Dresden, Germany

  • Calculators:
    Casio CFX 9850G (broken),
    Casio CFX 9850GB,
    Casio Algebra FX 2.0 Plus

Posted 09 February 2005 - 12:31 PM

I know the even quickest method B) (it needs 800B of RAM though):

Make a relocation list with indizes 1..80 where index = keycode+1 ( [80] corresponds key 79 (<span class=F1' />), [79] key 78 (<span class=Shift' />) and so on) Now the contents of this list can associate each value with each key you want (so you can use it for letters A..Z too).

For example make a List 1, where

List 1[72]=0
List 1[73]=1
List 1[63]=2
List 1[53]=3
List 1[74]=4
...

(set invalid values -1)
and type the following code:

List 1[Getkey+1]->A

(A=-1 means ignore key)
Surprise!

Note: if you really need keys "0".."9" only, lowest valid keycode is 53, meaning you can save 530 Bytes:

Getkey->A
if A>52 Then
List 1[A-52]->A
Else -1->A
Ifend


#7 Guest_Guest_*

Guest_Guest_*
  • Guests

Posted 09 February 2005 - 05:30 PM

thanks for the info, ill test through the different versions, to see which works best for me

thanks,
zerocool

#8 genesis

genesis

    UCF BASIC Programming Runner Up

  • Super Member
  • PipPipPipPip
  • 281 posts
  • Location:Perth, Australia
  • Interests:Speaking German, computers, defending CFX calculators...

  • Calculators:
    CFX 9850 GB+

Posted 11 February 2005 - 09:33 AM

Please dont use Genesis's code! there is a nice quick method:

<{POST_SNAPBACK}>


If you don't believe me, try it out for yourself. :P He wanted a quicker way than that, so I gave him two. ;)

#9 Andy.Davies

Andy.Davies

    Forum Ghost

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1547 posts
  • Gender:Male
  • Location:Dorset, England
  • Interests:Age: 18
    Studying: MEng in cybernetics at Reading uni
    Interests: Progaming (VB, VB.Net, C#, Casio Basic)
    Computers UBBD (Using, Building, Breaking &amp; Destroying)
    Gaming (FPS, RTS, RPG)
    Electronics
    Rock Music (Preferably Loud)
    Riley's (Pool &amp; Snooker Bar)
    Driving (Preferably fast)
    Aikedo (Martial Art)

  • Calculators:
    Algebra FX 2.0 ROM 1.01, FX9750G

Posted 11 February 2005 - 01:18 PM

If you don't believe me, try it out for yourself. :P He wanted a quicker way than that, so I gave him two. ;)

<{POST_SNAPBACK}>


i meant the second piece of code :)


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users