Register

Fun Tutorial for Casio Basic

Discuss issues related to the Casio Basic Language
Junior Member
Posts: 12
Joined: Fri May 11, 2012 1:25 am
Location: US
Calculators: Casio fx-9860 GII

Fun Tutorial for Casio Basic

Postby Xadiant » Fri May 11, 2012 3:12 am

Well, like some people out there I prefer to dive in head first.. with both feet. As a newcomer it tool me a long time to get started in even something as simple as Casio Basic, so I wish to make the first leap easier for another person. Read on and let your creative juices flow:

First off.. read and study this short tutorial. I cannot write it better myself so Ill link you to it: http://www.casiocalc.org/?showtopic=2448
(It is filled with a ton of helpful references to get you started)

Okay, welcome back! Im sure you can learn how to get user input with ?->A or calculate with variables yourself... lets get some key input to change a value!

(Here is your loop... it will just bounce off those 2 lines endlessly.)
Code: Select all
Lbl 1
Goto 1


(This endlessly sets A to the current key pressed and uses the Locate function to put it in the first section of the screen)
Code: Select all
Lbl 1
Getkey->A
Locate 1,1,A
Goto 1

(If you ask, why do the numbers do odd things when I let go of the button? Shouldnt it go to 0? Goodjob if you asked that... most buttons are 2 digits long the locate function allows for the characters to go into the next screen slots. But when you release the button and the value becomes 0... and 0 is written to the 1,1 spot, 1,2 is not touched. You can fix this by writing clearing the second spot right before you you write A to 1,1 or a variety of other ways...)

(This program simply puts the last pressed key on the screen (1,1) and leaves it there once the key is released. Im using the If function.... if Getkey is not 0 then it places the value of Getkey at 1,1)
Code: Select all
Lbl 1
If Getkey <>0
Then
Locate 1,1,Getkey
IfEnd
Goto 1

(Tada! Note: I called Getkey twice but as you can see im am expecting the value to be the same each time. This is a gamble and should not be done in serious programming... I am leaving this mistake here so I have an excuse to write about it. You can fix it by setting Getkey to a variable first and referencing the variable in those two instances. If your playing around you can expect the calculator processor will be so fast that the speed of your finger hitting the button will not mess it up regularly.)

===========================================================================
Enough stupid stuff, lets make a ball that can move around the screen by pressing the arrow keys :D
(You can use the above program as a reference to find out what number the arrow keys are)

So first lets talk about how we are going to do this. I believe the most simple way is to assign the position of some character to the variables X and Y and making a loop that will redraw the character in a new position based on those values. So here is my structure:

Assign default X&Y ------> Draw at new position -----> Loop waiting keypress -------> Erase original position -------> +/- from X/Y based on key pressed.
. . . . . . . . . . . . . . . . . . . . . . . . . . /\ --------------------------------Loop back to draw and then wait------------------------------------ \/

So lets put the frame of the program together: (Not a full program... this is like the foundation...)
Code: Select all
Lbl 1
While             [I](This is the keypress[/I]
WhileEnd        [I]wait loop)[/I]
Locate X,Y," "           [I](Puts an empty (space) in the spot before the move.  Lets not leave tracks behind out dot)[/I]
Getkey=27=>Isz X     [I](The => Arrow is a shorthand if statement.  If the key = 27 then do rest of the line.  Isz means +1 to value.  Dsz means -1.)[/I]
Goto 1

(see the program is just a loop inside of a loop. It waits inside the inner loop until a key is pressed, then changes X if the defines key is the one that is pressed (27). It then goes back to the beginning.)

(Complete program)
Code: Select all
10->X     [I](Sets the default position to[/I]
5->Y       [I]approximately the middle of the screen.  Out of bounds will crash the program)[/I]
Lbl 1
Locate X,Y,"@"    [I](Lets make the @ symbol our object... on the calc Id pick some character from the character menu)[/I]
While Getkey=0
WhileEnd
Locate X,Y," "
Getkey=27=>Isz X   [I](right)[/I]
Getkey=28=>Dsz Y   [I](up)[/I]
Getkey=37=>Isz Y   [I](Down)[/I]
Getkey=38=>Dsz X   [I](left)[/I]
Goto 1



Soon I will be adding my program that lets you solve a maze... with the maze saved in a matrix and the program being smart enough to not let you go out of bounds or go through maze walls. Happy programming :D

Member
User avatar
Posts: 33
Joined: Sat Apr 07, 2012 10:08 am
Location: France

Postby Purobaz » Fri May 11, 2012 1:43 pm

In my opinion, you shouldn't use (and teach) loop Lbl/Goto.

Basic is a hight level language which provides condition as If/IfEnd and loop as While/WhileEnd or Do/LpWhile.
It's easier and more understandable.

By example :
Code: Select all
Do
If Getkey#0
Then
Locate 1,1,Getkey
IfEnd
LpWhile Getkey#47

Junior Member
Posts: 12
Joined: Fri May 11, 2012 1:25 am
Location: US
Calculators: Casio fx-9860 GII

Postby Xadiant » Fri May 11, 2012 9:52 pm

Purobaz wrote:In my opinion, you shouldn't use (and teach) loop Lbl/Goto.

Basic is a hight level language which provides condition as If/IfEnd and loop as While/WhileEnd or Do/LpWhile.
It's easier and more understandable.

By example :
Code: Select all
Do
If Getkey#0
Then
Locate 1,1,Getkey
IfEnd
LpWhile Getkey#47


Im just putting information out there. No matter what you tell people they will prefer to make the mistakes and understand how things work themselves. I just encourage everybody to start typing into the calcs and find out how things work :D

(Plus I did incorporate while loops and if conditions)

Member
User avatar
Posts: 31
Joined: Wed Apr 18, 2012 4:48 pm

Postby Cartix » Sun May 13, 2012 2:51 pm

Sometimes, goto is realy useful, so I think you're right by teaching this (I hope my sentence has a meaning :D )

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

Postby aapman55 » Sun May 13, 2012 6:42 pm

you can use lbl and goto for loops, however in bigger programs you will encounter the problem that you will run out of labels.

Code: Select all
Do
Getkey
Locate 1,1,Ans
Do:LpWhile Getkey=Ans
ClrText
LpWhile 1

alternative code for getkey.

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 May 24, 2012 4:24 am

Hi everyone,

I'd like to know whether is it possible to display values in smaller font size like (Print mini) in Casio Basic.

Anyone please help.

Junior Member
Posts: 12
Joined: Fri May 11, 2012 1:25 am
Location: US
Calculators: Casio fx-9860 GII

Postby Xadiant » Fri May 25, 2012 1:50 am

nagarajan wrote:Hi everyone,

I'd like to know whether is it possible to display values in smaller font size like (Print mini) in Casio Basic.

Anyone please help.


You can if you enter the smaller letters from the character/symbols menu into quotes or a locate thing. If you want to store them in a variable then you are out of luck.... a string should work though :D

Member
Posts: 40
Joined: Tue Dec 17, 2013 12:56 pm
Calculators: Casio fx-9860 GII, Casio Classpad fx-cp400

Re: Fun Tutorial for Casio Basic

Postby PsySc0rpi0n » Sun Dec 22, 2013 8:10 pm

I'm trying some examples from this tutorial, but they are not working...

The 2nd example "Lbl1 Getkey->A Goto 1" gives an error when i try to save the program... Says invalid name and the cursor goes to the beggining of the word "Goto".

I'm trying this out in the Classpad software, not in the calculator it self.

Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860 GII SD, Casio Classpad 330, Casio fx-CG 20, Casio Classpad fx-cp400

Re: Fun Tutorial for Casio Basic

Postby helder7 » Mon Dec 23, 2013 12:41 pm

PsySc0rpi0n wrote:I'm trying this out in the Classpad software, not in the calculator it self.

This tutorial was written to the fx9860 (and fx-cg20). The classpad basic language is a bit different.

The second exemple in cp basic should be:
Code: Select all
Lbl ONE
GetKey A
Locate 1,1,A
Goto ONE


In classpad, the lbl parameter <name> is a text string, not a number, contrary to the fx9860g. Getkey must always be associated with a variable, using a parameter and not -> ...

Basically the logic is the same, only the names and arguments of some commands are different. The manual of the CP II has the syntax of the various commands.
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Return to Casio Basic Development

Who is online

Users browsing this forum: No registered users and 2 guests