ILLEGAL FUNCTION,error,My2nd program

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
GarryRicketson
Veteran
Posts: 90
Joined: Fri Jul 16, 2010 10:02 am
Location: Cuencame,Durango,Mexico
Contact:

ILLEGAL FUNCTION,error,My2nd program

Post by GarryRicketson »

:? Hello All,
I am baffled, this is going to be my final edition of this, but I want
to include a small game in it or "sortof a joke"...if and when I have a
real game, and know how to add it probely I will. The problem: every thing
loads and runs ok ,except when the user selects "J" for the game (it is not
really much of a game), the "game" runs ok, up to a point, I get a error:
LINE 171: illegal instruction, continue (yes), or (no)if I select continue it dose,
but step by step and of course no,exits..I cannot figure out why the illegal
function, the code that is in GAME: ran fine by itself,but when I added it
the problem started,....
Also or if anyone has a game they would like to give me, that I could put
in, that would be great!...I wanted to put in the LeapFrog, by Bob in the
samples folder,that came with QB64....but could not figure out how,and also
was concerned about permission....this program is for me,personal and anyone
who can use it....it will always be available free,at least on my website,
or from me,I cannot be responsible for what someone else might do, if anyone
should copy it and try to sell it, it is without my permision,but I kinda
doupt I need to worry about that, it is not that great,...
ok Thanks for any help,...and I am finding some great friends on this site!
Also note: In the introduction, I will be adding that I got the "Calculator",
of the samples,in QB64/samples/pete/calc...,and another friend ,anonymos(IOPNN), gave me the code for the multiplication tables,
and any other credit where its due,before I make the stand alone exe,
and put it on my site, or any other
From Garry

Code Below the error is al the way at the botton :LINE 171
'----------------------------------------------------------------------
SCREEN 0
WIDTH 80
PRINT "Program BY:Garry Ricketson."
PRINT "E-mail:GarryRicketson@yahoo.com, http://www.garryspages.webs.com"
PRINT "Note: this is not a game nor intended to be real fun,if you don't"
PRINT "get the right answer, you cannot move on,Alfonso dose not like to,"
PRINT "study his X tabels,but he loves to play the computer games(san"
PRINT "Andreas auto theft) is his favorite. So, the idea is the faster"
PRINT "he learns the tabels, the sooner he can play his game, when he"
PRINT " completes the whole program, I then let him play with the computer"
PRINT "I hope anyone else can also use it."
SLEEP 5
SCREEN 0
WIDTH 40
COLOR 10, 1
PRINT "?VAMOS a HACER TABLAS"; ""
PLAY "aaaa4bbb8<ggg4a2e8gggg>a4f8e2ccca4a4a4"
PRINT "tecla q para salir, intro para continuar"
PRINT "press q to exit tecla q para salir"
PRINT "Cualquire tecla para continuar"
INPUT "q", Q$
IF Q$ = "q" THEN END
SLEEP 5
PRINT "!Bienvenido!,WELCOME!... "
PRINT "Nada para decir ahora "
PRINT "ES una ejercisio de tablas, lo gue hizo para Alfonso,These are "
PRINT "multiplication tabels I made for Alfonso"
INPUT "ENTER YOUR NAME,escribe tu nombre:", name$
PRINT "?HOLA!,"; name$; ".?como estas,hoy?"
CLS
COLOR 17, 10, 2
PRINT "??????????????????????????????????"
PRINT "------------------------------------"
PRINT "???????????????????????????????????"
PRINT "? ?"
PRINT "? ? ? ?"
PRINT "? ? ?? ?"
PRINT "? ? ? OLA! ?"
PRINT "? Alfonso....... ?"
PRINT "? ?"
PRINT "? ?"
PRINT "???????????????????????????????????"
SLEEP 5
CLS
COLOR 10, 1, 2
PRINT "?HOLA!,Alfonso, vamos a hacer tablas"
PRINT "Ahora vamos acer Multiplicaciones(tablas)"
COLOR 14: PRINT "Buenos Dias"
FOR d = 600 TO 640
SOUND d, 1
NEXT
SLEEP 2
CLS
COLOR 14: PRINT "Buenos Dias"
FOR d = 600 TO 640
SOUND d, 1
NEXT
SLEEP 2
CLS
TOP:
COLOR 2: PRINT "puede ser este cosas "
PRINT
PRINT "(T)tablas"
PRINT "(C)alculator"
PRINT "(J)juego"
PRINT "(S)alir de programa"
ReHit: F$ = INPUT$(1) 'INPUT$ will wait for a keypress.
1 IF LCASE$(F$) = "t" THEN GOTO TABLAS
IF LCASE$(F$) = "c" THEN GOTO Calculater
IF LCASE$(F$) = "j" THEN GOTO GAME
IF LCASE$(F$) = "s" THEN END
GOTO ReHit
TABLAS: PRINT "Esos son los tablas"
RANDOMIZE TIMER
CLS
FOR i = 0 TO 100
x = INT(RND * 10) + 1 'if you want say only 9s or only 7s, change
'this to x=9 or x=7 ...
y = INT(RND * 10) + 1
PRINT x; "X"; y; "=";
INPUT "", n
IF x * y <> n THEN
PRINT "NOT CORRECT"
INPUT "Entra el primero numero: ", a
INPUT "Entra el segundo numero: ", b
PRINT "Respuesta corecto es: "; a * b 'now I am closer, on the
'previous that I sent 'you I had forgotten the b on this line.
ELSE
PRINT "CORRECT"
PRINT
END IF
NEXT
GOTO TOP:
Calculater:
PRINT "Eso es Calculador"
5 CLS
PRINT "1) ADD"
PRINT "2) MULTIPLY"
PRINT "3) DIVIDE"
PRINT "4) SQUARE ROOT"
PRINT "5) EXIT"
INPUT i
IF i = 1 GOTO 10
IF i = 2 GOTO 20
IF i = 3 GOTO 30
IF i = 4 GOTO 40
IF i = 5 GOTO TOP:
10 CLS: PRINT "INPUT NUMBER"
INPUT a
CLS
PRINT "INPUT NEXT NUMBER"
INPUT b
CLS
PRINT a + b
PRINT "PRESS SPACE TO RUN"
SLEEP 0
GOTO 5
20 CLS: PRINT "INPUT NUMBER"
INPUT C
CLS
PRINT "INPUT NEXT NUMBER"
INPUT d
CLS
PRINT C * d
PRINT "PRESS SPACE TO RUN"
SLEEP 0
GOTO 5
30 CLS: PRINT "INPUT NUMBER"
INPUT E
CLS
PRINT "INPUT NEXT NUMBER"
INPUT F
CLS
PRINT E / F
PRINT "PRESS SPACE TO RUN"
SLEEP 0
GOTO 5
40 CLS: PRINT "INPUT NUMBER"
INPUT G
CLS
PRINT SQR(G)
PRINT "PRESS SPACE TO RUN"
SLEEP 0
GOTO 5
GOTO TOP:

'----------------------------------insert calculator
GAME:
SCREEN 0
WIDTH 80
DEFINT A-Z 'By its self this worked ok, but when I added it...no
DECLARE SUB Align (Tclr, Trow, txt$)
Align 14, 5, "MIRA ,LO QUE HIZO"
Align 14, 8, " AQUI ES TU JUEGO"
Align 15, 10, "TECLA INTRO PARA SALIR " + Prt$ + "NO, PARA JUEGAR" + Qt$
DO: LOOP UNTIL INKEY$ <> ""
CLS
TOPB:
FOR i% = 2 TO 28
Align 13, i%, "El Cielo es Caiendo!"
Align 13, i% - 1, SPACE$(19)
SOUND 2000 / i%, 1
NEXT i%
Align 14, 5, "Alfonso, siempre quiere jugar"
Align 18, 15, "Dice Blinky blinky blinky, estoy abburido"
Align 15, 10, "Tecla el Q para salir"
IF INKEY$ = "Q" THEN END
GOTO TOPB:
SUB Align (Tclr, r0w, txt$)
c0l = 41 - (LEN(txt$) \ 2)
COLOR Tclr: LOCATE r0w, c0l: PRINT txt$; 'This is line 171 or where it says
'illegal instruction
END SUB
'________________________End of program___________
And thanks,
From Garry
p.s. I hope this is not too long
angros47
Veteran
Posts: 79
Joined: Mon Sep 08, 2008 12:52 pm
Contact:

Post by angros47 »

I haven't tested your program, but I believe the error is in section:

Code: Select all

FOR i% = 2 TO 28
Align 13, i%, "El Cielo es Caiendo!"
Align 13, i% - 1, SPACE$(19) 
...
In fact, Align should print "El Cielo es Caiendo" at row I%, using color 13. And, in your loop, I% goes from 2 to 28; the problem is.... there is no screen row 28, neither 27... you have only 25 rows on the standard text screen (unless you set otherwise, using for example WIDTH 80,50 to get 80 columns and 50 rows).

When your program run, first (when I% is less than 25) it works well, then, when I% is equal to 26, 27 or 28, Align function is called, and the value of I% is stored in the r0w variable; when you try to use the LOCATE r0w command to access line 26, the program halts with an error: and, since the LOCATE command is at line 171, an error in line 171 is reported: actually, the real error is in the FOR i% = 2 TO 28 line (it should be FOR i% = 2 TO 24)
User avatar
GarryRicketson
Veteran
Posts: 90
Joined: Fri Jul 16, 2010 10:02 am
Location: Cuencame,Durango,Mexico
Contact:

Thanks for reply,

Post by GarryRicketson »

To, Angros47,
Ok thank you, that makes sense,...now I understand, (I Think),
so even if the numbers are not correct, I should be able to make the
adjustment; it is because I cut the code out of the QBASICS tutorial program, I guess thats obvious, and since mine dose not have the same
numbers of lines.....
Kind of a joke,but this is true, in another tutorial,
the writer gives an example of code to do a count,print routine 1 thru
10. and he comments, If you cannot understand this you really are in
trouble.....well I guess I am kins in trouble,...I am still studieng that also,
all though I sort of understand it, it is takeing me a while....anyway it
good to know where I can go, to get out of trouble!...thanks a bunch.
P.S. Is this the correct way to acknowlege a reply?
from Garry
PPS: I changed the 28 to 24, that simple,...as you said...so ok
that is solved...great! thanks a whole bunch! :D
josh24
Newbie
Posts: 1
Joined: Wed Aug 04, 2010 1:47 am

ggkk

Post by josh24 »

How this will be extended into another function?
how to get a girl to like you
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Nice to see you using my Align SUB code there Garry.

I recognize it by the zeroes used in the variables.

If you want 28 rows use SCREEN 12.

29 and 30 will roll the screen PRINTs unless you use a semicolon after the PRINT text, but the SUB does that for you.

A note about the SUB. You can only print TEXT with it! Number values can be printed AFTER the call as the semicolon will grab the next un-located print. USE string addition(concatenation) and STR$ function to add numeric values, like so:

Align 10, 20, "He said he is" + STR$(age%) + " years old"

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
GarryRicketson
Veteran
Posts: 90
Joined: Fri Jul 16, 2010 10:02 am
Location: Cuencame,Durango,Mexico
Contact:

Just to let you know,

Post by GarryRicketson »

That I read the reply, ..and I did, also Thank you,more for makeing the tutorial
available I really like it,hopefully in awhile I will understand enough, to
write my own SUBs, and other code, I am going put in the links to
your QB64 download, and site, on my web page,if it is ok ?.....ok guess
that is about it for now...thanks again for the reply, and also makeing all of this available.
from Garry
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Well, I don't have a site, but you can put my link anywhere you please. I appreciate it!

I still add updates to the Q-Basics Demo when I find something useful. Thanks for your support.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
GarryRicketson
Veteran
Posts: 90
Joined: Fri Jul 16, 2010 10:02 am
Location: Cuencame,Durango,Mexico
Contact:

LINKS,

Post by GarryRicketson »

Ok, I misinterpreted, anyway the links you have in your signature, for
the QB64 site, ...I misinterpreted, and thought that is your site....guess
thats all right now,
from Garry
Post Reply