Register

Get Key Troubles

Discuss issues related to the Casio Basic Language
Member
Posts: 48
Joined: Mon Apr 23, 2012 3:58 am
Location: Chennai,India
Calculators: Casio fx-9750 G II, Casio fx-9860G Slim, Casio fx-9860 GII

Get Key Troubles

Postby nagarajan » Thu Apr 26, 2012 6:12 am

Hi,

Am having a trouble with getkey.

Here's my code:
"KM"?->K
Do:Getkey
LpWhile Not Ans
If Ans>=25
Then Ans=76=>K+0.01->K
Ans=66=>K+0.02->K
Ans=56=>K+0.05->K
Ans=46=>K+0.1->K
Ans=36=>K+0.2->K
Ans=26=>K+0.5->K
IfEnd.

I need this fuction to work while pressing the keys.
If I press the numbers it should ask for the "KM" value and then should display the result.
Pls help.

User avatar
Posts: 89
Joined: Thu Apr 05, 2012 3:16 pm
Location: Akron, OH, USA
Calculators: Casio fx-9750 G II, Casio fx-CG 10

Postby flyingfisch » Thu Apr 26, 2012 2:47 pm

nagarajan wrote:Hi,

Am having a trouble with getkey.

Here's my code:
"KM"?->K
Do:Getkey
LpWhile Not Ans
If Ans>=25
Then Ans=76=>K+0.01->K
Ans=66=>K+0.02->K
Ans=56=>K+0.05->K
Ans=46=>K+0.1->K
Ans=36=>K+0.2->K
Ans=26=>K+0.5->K
IfEnd.

I need this fuction to work while pressing the keys.
If I press the numbers it should ask for the "KM" value and then should display the result.
Pls help.


This is better, i think... but I don't think I really understand what you want to do

Code: Select all

Do
LpWhile not Getkey
If Ans>=25
 Then Ans=76=>K+0.01->K
 Ans=66=>K+0.02->K
 Ans=56=>K+0.05->K
 Ans=46=>K+0.1->K
 Ans=36=>K+0.2->K
 Ans=26=>K+0.5->K
 IfEnd.


"KM" -> K


Member
Posts: 48
Joined: Mon Apr 23, 2012 3:58 am
Location: Chennai,India
Calculators: Casio fx-9750 G II, Casio fx-9860G Slim, Casio fx-9860 GII

Postby nagarajan » Thu Apr 26, 2012 6:15 pm

flyingfisch wrote:This is better, i think... but I don't think I really understand what you want to do

Code: Select all

Do
LpWhile not Getkey
If Ans>=25
 Then Ans=76=>K+0.01->K
 Ans=66=>K+0.02->K
 Ans=56=>K+0.05->K
 Ans=46=>K+0.1->K
 Ans=36=>K+0.2->K
 Ans=26=>K+0.5->K
 IfEnd.


"KM" -> K



Thanks for the idea.
What i need is:
1.Inputting K value.
2.After the input it should keep on adding .01,.02,.05,.1,.2 etc while pressing the keys assigned to the function.
3.If the keys were not pressed it should return to asking the value of K.

Hope this 'll help you to solve my problem.

Senior Member
User avatar
Posts: 66
Joined: Sun Apr 15, 2012 4:00 pm
Calculators: Casio fx-9860G

Postby aapman55 » Thu Apr 26, 2012 6:21 pm

lbl 1
do
getkey
lpwhile ans=0
Ans=66=>blabla
Goto 1

Or you can make an infinite loop
do
getkey
ans=66=> blabla
ans=47=> Goto Q
lpwhile 1
lbl Q
Locate 1,1,"EXIT"

Member
User avatar
Posts: 27
Joined: Mon Apr 09, 2012 7:09 pm
Location: France

Postby PierrotLL » Fri Apr 27, 2012 1:05 am

nagarajan wrote:Hi,

Am having a trouble with getkey.

Here's my code:
"KM"?->K
Do:Getkey
LpWhile Not Ans
If Ans>=25
Then Ans=76=>K+0.01->K
Ans=66=>K+0.02->K
Ans=56=>K+0.05->K
Ans=46=>K+0.1->K
Ans=36=>K+0.2->K
Ans=26=>K+0.5->K
IfEnd.

I need this fuction to work while pressing the keys.
If I press the numbers it should ask for the "KM" value and then should display the result.
Pls help.


The user input "MK" value and press EXE to validate. So the GetKey juste after return obviously 31 (EXE).
You must wait until the button is released. (While Getkey:WhileEnd)

Member
Posts: 48
Joined: Mon Apr 23, 2012 3:58 am
Location: Chennai,India
Calculators: Casio fx-9750 G II, Casio fx-9860G Slim, Casio fx-9860 GII

Postby nagarajan » Fri Apr 27, 2012 11:10 am

PierrotLL wrote:The user input "MK" value and press EXE to validate. So the GetKey juste after return obviously 31 (EXE).
You must wait until the button is released. (While Getkey:WhileEnd)


Can you explain this with the sample code pls?

Senior Member
User avatar
Posts: 66
Joined: Sun Apr 15, 2012 4:00 pm
Calculators: Casio fx-9860G

Postby aapman55 » Fri Apr 27, 2012 11:44 am

Code: Select all
"KM"?->K
Lbl 1
Do
For 1->A To 75:Next
Getkey
LpWhile Ans=0
Clrtext
Locate 1,1,K
Ans=79=>K+0,02->K
Ans=47=>Goto Q
Goto 1
Lbl Q
ClrText
Locate 4,5,"Quit"


Play around with this working program.

Member
User avatar
Posts: 27
Joined: Mon Apr 09, 2012 7:09 pm
Location: France

Postby PierrotLL » Fri Apr 27, 2012 3:35 pm

Code: Select all
"KM"?->K
While GetKey:WhileEnd [color="#008000"]//wait while a key is pressed[/color]
Do:Getkey
LpWhile Not Ans
Ans=76=>K+0.01->K //your If statement was useless
Ans=66=>K+0.02->K
Ans=56=>K+0.05->K
Ans=46=>K+0.1->K
Ans=36=>K+0.2->K
Ans=26=>K+0.5->K


@aapman55 : your code will slow-down the program on old calcs, and the result will be wrong if the user press EXE a long time. A simple While is better.

Senior Member
User avatar
Posts: 66
Joined: Sun Apr 15, 2012 4:00 pm
Calculators: Casio fx-9860G

Postby aapman55 » Fri Apr 27, 2012 3:45 pm

thanks pierrot never thought of that wait till key is pressed part, because i thought it wouldnt work.

Return to Casio Basic Development

Who is online

Users browsing this forum: No registered users and 2 guests