## Graphs and what not...

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

gurmeet
Newbie
Posts: 8
Joined: Sat Mar 29, 2008 2:54 pm

### Graphs and what not...

EDIT: I'm almost done.
Last edited by gurmeet on Thu Apr 03, 2008 5:19 pm, edited 1 time in total.

burger2227
Veteran
Posts: 2425
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

### Homework

We do not do homework, but if you post some of your code and have certain problems, we can help. To copy your code from QB, save the program code as text readable. Open the QB BAS file with Edit from the Right click mouse Menu. Should open in Notepad.

Copy and paste to the post using the

Code: Select all

`` Your code ``
button in the menu here. That should format the code properly.

Ted
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

Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

### Re: Homework

burger2227 wrote:We do not do homework
True, gurmeet, and don't bother going elsewhere. Nobody will
do your homework. QBasic programmers are honorable students.

Mac

gurmeet
Newbie
Posts: 8
Joined: Sat Mar 29, 2008 2:54 pm

### Sorry about that.

EDIT: ALMOST DONE!
Last edited by gurmeet on Thu Apr 03, 2008 5:19 pm, edited 1 time in total.

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas
Gurmeet:

You are only plotting the points with X = -10, -9, -8,...8, 9, 10, that is, only 21 points, each separated by a distance dX = 1. Make your FOR/TO using a STEP 0.01, so you'll get a whole lot of points plotted, making the result look like a continuous curve.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

burger2227
Veteran
Posts: 2425
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

### HUH?

You can plot decimal values all you want with PSET, but INTEGERs are the only ones shown. Grahics functions plot Integer pixel positions. There is no such thing as half a pixel!

Don't use STEP point anything for x. All you will see are the positive values anyhow! SIN may work for the y position, but it converts to only Integers also.

Ted
Last edited by burger2227 on Mon Mar 31, 2008 8:37 am, edited 1 time in total.
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

gurmeet
Newbie
Posts: 8
Joined: Sat Mar 29, 2008 2:54 pm
EDIT: ALMOST DONE!
Last edited by gurmeet on Thu Apr 03, 2008 5:20 pm, edited 1 time in total.

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas
Ted and gurmeet I apologize for posting wrong information!

Gurmeet: Thank you for posting your code. Here are some of the things that I find need fixing:

1. The first line your subtoutine keyboard will not work! One fix could be:
k\$="":WHILE k\$="": k\$=inkey\$:WEND
That line will first make sure the string variable k\$ starts out as a blank (""); then, it creates the WHILE/WEND loop, and it will stay looping until you press a key, which then allows k\$ to read from the inkey\$ function.

2. You should add a fourth line to your menu, instructing the user to press the Q key to quit. But, you must consider what will happen if the user presses the Q key without using the Shift key, which will give a lower case q.

3. Your code shows a respond to the UP key- but, your menu doesn't instruct the user what the upper key is supposed to do.

There are a few other things to comment on, but, I think you are going to first have to try to think through each move you want to make, then code that move, all one step at a time, before your program can do much more. So, try to use comments before each part of your code, to describe what you intend to have happen; then, if you can't seem to make the code work, at least we will know if your logic is correct.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm
Ralph wrote:Here are some of the things that I find need fixing:
Nice work, you guys! Now that is how to help. I would chime in, but things are working out without me just fine.

Mac

TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:
Optimization :

WHILE INP(&H60) > 127: blablablablabla : WEND

I have some code that graphs some equation... I'll look for it, maybe you find it useful.

EDIT : Seems I've lost the code...
Mida sa loed ? Nagunii aru ei saa

burger2227
Veteran
Posts: 2425
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
Change the keyboard routine to wait for a keypress. That can easily be done using an INKEY\$ loop.

Code: Select all

``````DO: k\$ = INKEY\$: LOOP UNTIL k\$ <> ""
``````
Using INP(60), all values over 128 are release codes only. INKEY\$ is usually a better choice for simple menus.

Ted
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

gurmeet
Newbie
Posts: 8
Joined: Sat Mar 29, 2008 2:54 pm
EDIT: ALMOST DONE!
Last edited by gurmeet on Thu Apr 03, 2008 5:20 pm, edited 2 times in total.

gurmeet
Newbie
Posts: 8
Joined: Sat Mar 29, 2008 2:54 pm
Since my classmates have the same project to do, I heard some of them talking about stealing some info off of this site. They said they've found some info about the project and I'm sure they're talking about my post. Is there any way we can secure my posts from non-members? It'll be really helpful, because I'm afraid the students that get higher than me might copy and then when we present they will be the one that the teacher will believe.

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

### Gurmeet and "Stealing code"

I'm afraid that anyone can come to this and any other site and copy whatever is available. That is also one of the reasons that we don't like to try to completely solve homework; rather, we encourage collaborative efforts, and try to indicate the "how and why", rather than the solution.

You should have a headstart on the possible copiers, since you have writen your code. If you undestand what the code is doing, or is supposed to be doing, you should only post that part of code that is not working properly, and not all the code. In that manner, youwon't have to worry about others copying your finished work.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:
gurmeet wrote:Since my classmates have the same project to do, I heard some of them talking about stealing some info off of this site. They said they've found some info about the project and I'm sure they're talking about my post. Is there any way we can secure my posts from non-members? It'll be really helpful, because I'm afraid the students that get higher than me might copy and then when we present they will be the one that the teacher will believe.
well if your professor has questions about who knew what
direct him here...

burger2227
Veteran
Posts: 2425
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

### LOL

You went from a cheater to a hider pretty quick!

Don't worry about other's copying your code. If they do, then the teacher will suspect something. Also be sure to use code that fits your experience level in the class. Teachers often can spot code that is more expert than the pupil can normally do.

As for the division error check your domain variable <> 0. If it is, either exit the sub or find another way to correct it. Often it helps if you print the value when a program is running. Locate it somewhere visible at all times while troubleshooting. Debug does not work well in XP.

Ted
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

gurmeet
Newbie
Posts: 8
Joined: Sat Mar 29, 2008 2:54 pm
I'm trying to put another option on the menu, it lets me have it on the screen but when I scroll up and down with the Arrow Keys, I can only highlight the first three. I'm unsure of how since the code was given by our teacher.

Code: Select all

``````CLS
LOCATE 4, 10
COLOR 9
PRINT "What Would You Like To Do?"

LOCATE 5, 10
PRINT "Use The Arrow Keys To Move Up And Down On The Menu"

LOCATE 17, 10
COLOR 9
PRINT "Press q To Exit The Menu"
DIM a\$(5)
a\$(1) = "Watch A Malfunctioning Radar"
a\$(2) = "See The Function Of Sine On Peculiar Objects"
a\$(3) = "Go To Quadratic Function"
a\$(4) = "Go To Linear Function"
Y = 8
x = 10
C = 1

COLOR 15

REM COLOR OF CHOICE IS HIGHLITE

HIGHLITE = 9

FOR M = 1 TO 4
LOCATE Y, x
PRINT a\$(M)
Y = Y + 2
NEXT M

Y = 8
choice:
DO: k\$ = INKEY\$: LOOP UNTIL k\$ <> ""
IF k\$ = "q" THEN END
IF k\$ = CHR\$(0) + CHR\$(80) AND Y <12> 8 THEN
Y = Y - 2
C = C - 1
COLOR HIGHLITE
LOCATE Y, x
PRINT a\$(C)
COLOR 15
LOCATE Y + 2, x
PRINT a\$(C + 1)
END IF

IF k\$ = CHR\$(13) AND C = 1 THEN GOTO option1
IF k\$ = CHR\$(13) AND C = 2 THEN GOTO option2
IF k\$ = CHR\$(13) AND C = 3 THEN GOTO Drawquadratic
IF k\$ = CHR\$(13) AND C = 4 THEN GOTO option4
GOTO choice
END

KEYBOARD:
k\$ = INKEY\$
RETURN

option1:
CLS
SCREEN 13

CIRCLE (156, 95), 110, 4
CIRCLE (157, 95), 2, 4
PAINT (158, 95), 2, 4
FOR x = -6.28 TO 6.28 STEP .1
CIRCLE (156, 95), 110, 4, x, x + .01
GOSUB waiting
CIRCLE (156, 95), 110, 2, x, x + .01
NEXT x

LINE (160, 95)-(265, 95), 4

END

waiting:
FOR t = 1 TO 50000
NEXT t
RETURN

END
``````

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas
gurmeet: I don't know what version of qb you have, but, in my QuickBASIC Version 4.5, as soon as I try to run your code, it gives me an error message, "Label not defined", and stops on your line,

IF k\$ = CHR\$(13 AND C = 2 THEN GOTO option2

Note that GOTO option2 requires a label option2, which shold be at the beginning of some line, and all by itself, written as

option2:

Since your code lacks this label, the program in QuickBASIC, Version 4.5, will not run. And, if it runs in your version of QB, it should crash as soon as you choose option2.

Your code also lacks the labels Drawquadratic: and option4:, both supposed options for the user.

Once you have posted your corrected code, I will be happy to try to see if I can run it and, if I have a problem, report it to you, for further correction.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

burger2227
Veteran
Posts: 2425
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

### YOU ARE DONE?

Deleted all of his posts because he does not want any other CHEATERS in his class to see them..........

Did you ever consider that others read these threads so that we don't have to reply fifty times? Some people read these threads for tips and ideas.

Ted
Last edited by burger2227 on Sat Apr 05, 2008 12:44 pm, edited 3 times in total.
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

gurmeet
Newbie
Posts: 8
Joined: Sat Mar 29, 2008 2:54 pm
That was really friendly, Ted. Thanks.

Ralph, sorry about that I forgot to fix it =(

Code: Select all

``````
CLS
LOCATE 4, 10
COLOR 9
PRINT "What Would You Like To Do?"

LOCATE 5, 10
PRINT "Use The Arrow Keys To Move Up And Down On The Menu"

LOCATE 17, 10
COLOR 9
PRINT "Press q To Exit The Menu"
DIM a\$(5)
a\$(1) = "Watch A Malfunctioning Radar"
a\$(2) = "See The Function Of Sine On Peculiar Objects"
a\$(3) = "Go To Quadratic Function"
a\$(4) = "Go To Linear Function"
Y = 8
x = 10
C = 1

COLOR 15

REM COLOR OF CHOICE IS HIGHLITE

HIGHLITE = 9

FOR M = 1 TO 4
LOCATE Y, x
PRINT a\$(M)
Y = Y + 2
NEXT M

Y = 8
choice:
DO: k\$ = INKEY\$: LOOP UNTIL k\$ <> ""
IF k\$ = "q" THEN END
IF k\$ = CHR\$(0) + CHR\$(80) AND Y <12> 8 THEN
Y = Y - 2
C = C - 1
COLOR HIGHLITE
LOCATE Y, x
PRINT a\$(C)
COLOR 15
LOCATE Y + 2, x
PRINT a\$(C + 1)
END IF

IF k\$ = CHR\$(13) AND C = 1 THEN GOTO option1
IF k\$ = CHR\$(13) AND C = 2 THEN GOTO option2
IF k\$ = CHR\$(13) AND C = 3 THEN GOTO Drawquadratic
IF k\$ = CHR\$(13) AND C = 4 THEN GOTO option4
GOTO choice
END

KEYBOARD:
k\$ = INKEY\$
RETURN

option1:
CLS
SCREEN 13

CIRCLE (156, 95), 110, 4
CIRCLE (157, 95), 2, 4
PAINT (158, 95), 2, 4
FOR x = -6.28 TO 6.28 STEP .1
CIRCLE (156, 95), 110, 4, x, x + .01
GOSUB waiting
CIRCLE (156, 95), 110, 2, x, x + .01
NEXT x

LINE (160, 95)-(265, 95), 4

END

waiting:
FOR t = 1 TO 50000
NEXT t
RETURN

END

option 2:
cls
? "2"
end