QBasic Forum BASIC Discussion Board

[QB FAQ] [QB Archives, Links and Downloads] [Subforums and Chat Room] [Search]

Run QBasic Code on Modern Systems:  QB64   Post Code or Ask for Help:  Post Code   Homework Policy



Data... Read

by (no login)

Hi,

I'm not familiar with this command, but it's nice, if it's well implemented. In Qbasic, datas must be integers, longs, strings ?.. but you can't use the name of a variable. But if you could, you would get access to an array, hence it replace a DIM command. This is the case on my cheap Citizen SRP 350 calculator.

L

Posted on May 26, 2014, 8:58 AM

Respond to this message   

Return to Index


READ / DATA

by Donald Foster (no login)

DATA is just that data; number and strings and so forth. You use READ to assign the DATA to your variables.

Posted on Jul 16, 2014, 7:29 PM

Respond to this message   

Return to Index


Adapting .bas files? Question from a beginner

by Andrea (no login)

I'm trying to adapt an old .bat file that used QBASIC to run .bas files.

Here is the code in the old file:
c:slotxqbasic /run ev2_1.bas
c:slotxqbasic /run ev2_2.bas
c:slotxqbasic /run ev2_60.bas
c:slotxqbasic /run ev2_61.bas
c:slotxqbasic /run ev2_30.bas
c:slotxqbasic /run ev2_31.bas
c:slotxqbasic /run ev2_5.bas
c:slotxqbasic /run ev2_6.bas
c:slotxqbasic /run ev2_36.bas
c:slotxqbasic /run ev2_35.bas
c:slotxqbasic /run ev2_66.bas
c:slotxqbasic /run ev2_65.bas
PAUSE


It's my understanding that QB64 does not run .bas files? How should I rename/modify the .bas files so that qb64 can run them? I've already tried saving them as .exe files (i.e., the first line now reads c:slotzqb64 /run ev2_1.exe), but that didn't seem to work.

I apologize for my question's lack of specificity-- I'm quite new to this! Any suggestions would be much appreciated, and I'll do my best to elaborate if I didn't provide enough information.

For some reason, in the preview, the code isn't showing up correctly. There should be a backslash between 'slotx' and 'qbasic' in the old code, and between 'slotz' and 'qb64' in the new code.

Posted on May 22, 2014, 10:53 AM

Respond to this message   

Return to Index


Re: Adapting .bas files? Question from a beginner

by SMcNeill (no login)

Save the files in text format, and then QB64 shouldn't have a problem with them. It's only when you save files as BINARY BAS files that QB64 can't work with them.

There's a page on converting old binary BAS files to text over on the QB64 wiki. http://www.qb64.net/wiki/index.php/Tokenized_Code Maybe it can help you convert, if you can't open the programs anymore and simply save them in text format. :)

Posted on May 24, 2014, 8:02 AM

Respond to this message   

Return to Index


Re: Adapting .bas files? Question from a beginner

by Andrea (no login)

Thanks for your response!

I converted all of the files in text format, but now I'm getting an error message from qb64 saying that the path I specified wasn't found. I tried making the path as specific as possible and even put copies of my text files into the qb64 directory, but it does't seem to be working.

Here is some background that might help. I'm trying to process psychophysiological data for analysis, and our lab has several scripts and batch files in place to streamline the process. In the past, our batch file would call QBASIC to run .BAS files that organize the data in a particular way. Now, I'm trying to adapt everything for Windows 7, and figuring out how to get qb64 to do what QBASIC used to do is giving me some trouble. Once again, here's the old and new codes (Note: the change from slotx to slotz is intentional). Could it be a problem with the run command? Or maybe a problem with the text file itself?

Old:
c:\slotx\qbasic /run ev2_1.bas

New:
c:\slotz\qb64 /run c:slotz\ev2_1.txt

Any ideas? Thank you!

Posted on Jun 9, 2014, 2:01 PM

Respond to this message   

Return to Index


Re: Adapting .bas files? Question from a beginner

by (Login MCalkins)
Moderator

The backslash problem is a known problem with this forum. To get them to display, you need to double them.

I assume that you were able to use QB64 to successfully compile the programs, but that you feel that they are not running correctly?

What sort of programs are they?

QB64 programs usually write their output to a separate window which they create, not to the actual console window. To write to the actual console window, you would need to put:

$CONSOLE
_SOURCE _CONSOLE
_DEST _CONSOLE

in each program, but QB64 hasn't implemented COLOR or LOCATE for consoles yet.

How big are those programs? Is there some reason why they couldn't be combined?

Regards,
Michael

Posted on May 24, 2014, 8:26 AM

Respond to this message   

Return to Index


Re: Adapting .bas files? Question from a beginner

by Andrea (no login)

Thanks for the tip about the backslash problem.

I actually didn't use QB64 to compile the programs. Here is some background that might help. I'm trying to process psychophysiological data for analysis, and our lab has several scripts and batch files in place to streamline the process. In the past, our batch file would call QBASIC to run .BAS files that organize the data in a particular way. Now, I'm trying to adapt everything for Windows 7, and figuring out how to get QB64 to do what QBASIC used to do is giving me some trouble. Specifically, when I run the batch file, QB64 opens, but an error message pops up telling me that the path I specified isn't found. I've tried changing the path a few times, and even tried moving copies of the text files to the QB64 directory, but that hasn't helped so far.

Once again, here's the old and new code (Note: the change from slotx to slotz is intentional). Could it be a problem with the run command? Or maybe a problem with the text file itself?

Old:
c:\slotx\qbasic /run ev2_1.bas

New:
c:\slotz\qb64 /run c:\slotz\ev2_1.txt

Any ideas? Thank you!
Andrea

Posted on Jun 9, 2014, 2:09 PM

Respond to this message   

Return to Index


Re: Adapting .bas files? Question from a beginner

by SMcNeill (no login)

QB64 doesn't have a command line run parameter like qbasic did. Instead you'd need to compile the BAS program to an EXE first and then simply run the EXE.

A command line compile example would be:

c:\slotz\qb64 -c c:\slotz\ev2_1.bas

(Or maybe c:\slotz\qb64 c:\slotz\ev2_1.bas -c I'm not certain off the top of my head if the -c has to go before or after the file name, or if it even matters.)

This would then produce an ev2_1.exe in the c:\slotz\ folder (where qb64.exe was located), which you then would run with a simple:

c:\slotz\ev2_1


The advantage to doing things like this is that you'd actually only need to compile the program ONCE, and from thereafter you'd be able to run ev2_1.exe without having to worry with that first step any more (unless you change the code inside the ev2_1.bas file of course. You'd have to recompile it then to take advantages of any changes to the source.)

Posted on Jun 9, 2014, 2:49 PM

Respond to this message   

Return to Index


You can make a batch file that can run in Open With

by (Login burger2227)
R

Posted on Jun 10, 2014, 4:18 AM

Respond to this message   

Return to Index


OT : statistics

by (no login)

Hi all,

Since there are most knowledgeable people here, i still have a doubt about following question :

What are the chances to get at least 2 right numbers in a lottery consisting of 5 draws, 49 numbers ?

To get 2 numbers in 2 draws : (1/49 x 1/48) /2! = A

Then the third would be :

1 - A => Probability the 2 nb are still in the remaining pool

(1 - A) x 2/47 => probability of available matching numbers

(1 - A) x 2/47 would be the chances to get the third number, but it contributes only to half of the result consisting of 2 draws, so remains 1/47 ?

So getting 2 matches with 3 draws would be (1 - A) x (2/47) / 2 = 0.02127

Anyway i can't explain why A is so small, and drawing a 3 nb will leap to x100 times better... ant help appreciated, Thanks, L

Posted on May 21, 2014, 2:42 AM

Respond to this message   

Return to Index


Breaking the fence

by (no login)

in mind.

Solution is rather like

1/49 x (1/48 + 1/47) x 2!

L

Posted on May 22, 2014, 4:06 AM

Respond to this message   

Return to Index


Approx solution

by David (no login)

To get 2 numbers in from 5 picks with 49 total numbers.

(5/49)*(4/48)*(44/47)*(43/46)*(42/45) =.00695
but there are 10 possible ways of doing this 1,2 1,3 1,4 1,5 2,3 2,4 2,5 3,4 3,5 4,5(I have just shown the 1,2 ball draw).
Okay so each has a slight different probability, but lets fudge over that.
so probability is 0.0695 or about 7%
Just to check all possibilities should add to 100%

0 correct 57%
1 correct 37%
2 correct 7%
3 correct 0.5%
4&5 correct zero within experimental error
Total 101.5% (error due to rounding)

Posted on May 22, 2014, 6:45 AM

Respond to this message   

Return to Index


formula ?

by (no login)

It sounds interesting, but i don't get the formula ? why 42

I found something like :

0.003513

Which seems not much, intuitively... but i understand why, even if the result is disturbing :

1/49 x (1/48 + 1/47 + 1/46 + 1/45) x 2!

Posted on May 22, 2014, 7:56 AM

Respond to this message   

Return to Index


Probabilities

by David (no login)

On drawing the first number you have 5 chances in 49 that is is one you picked and 44 chances that it is not.
so for the first number drawn 5/49 or 44/49 (note it again has to add to 1.
So the chances of missing - not getting one number is

44/49 * 43/48 *42/47 *41/46 *40/45 = 0.57

Chances of getting one correct (let's say the middle one)

44/49 * 43/48 * 5/47 *42/46 *41/45 (and the one correct could have been in 1 of 5 positions) so *5 = 0.37

If you want a formula ((N-n)!-(N-n+k)!*n!-(n-k)!)/(n!-(N-n+1)! (I think) N=49 n=5 k=2
and this further needs to be multiplied by the binomial coeff. n!/(k!(n-k)!)

Posted on May 22, 2014, 8:39 AM

Respond to this message   

Return to Index


What is not clear to me his how many time you draw

by (no login)

5/49 to get the first, 44/49 to miss it. Then you have drawn 5 times, so end of the story. I don't follow what you do next while incrementing/decrementing fractions...

Don't miss that multiplying probabilities is a thing that doesn't give you permutations, but arrangements. You have ordered stuff when you multiply.

I think your algorithm is waay to complex...for my brain at least :)

L

Posted on May 22, 2014, 11:19 AM

Respond to this message   

Return to Index


Basic program

by David (no login)

denom = 49 * 48 * 47 * 46 * 45
numer = 44 * 43 * 42 * 41 * 40
PRINT "zero correct ";: PRINT USING ".#######"; numer / denom
FOR k = 1 TO 5
IF k = 1 THEN numer = numer / 40 * 5: PRINT "one correct ";: PRINT USING ".#######"; numer / denom * 5
IF k = 2 THEN numer = numer / 41 * 4: PRINT "two correct ";: PRINT USING ".#######"; numer / denom * 10
IF k = 3 THEN numer = numer / 42 * 3: PRINT "three correct ";: PRINT USING ".#######"; numer / denom * 10
IF k = 4 THEN numer = numer / 43 * 2: PRINT "four correct ";: PRINT USING ".#######"; numer / denom * 5
IF k = 5 THEN numer = numer / 44 * 1: PRINT "five correct ";: PRINT USING ".#######"; numer / denom * 1
NEXT k

Posted on May 23, 2014, 4:53 AM

Respond to this message   

Return to Index


A formula

by lawgin (no login)

Let's say (n,k) means the number of ways to pick k things from a total of n things when order is not important. Then (n,k) = n!/(k!(n-k)!)
The answer to your problem is then (5,2) x (44,3)/(49,5)
or 10 x 13244/1906884 = .069453621

Posted on May 23, 2014, 3:14 PM

Respond to this message   

Return to Index


*Yes but wasn't exactly my problem...

by (no login)

*

Posted on May 23, 2014, 3:29 PM

Respond to this message   

Return to Index


"get at least 2 right numbers"...

by lawgin (no login)

then 3,4,or 5 right will also meet conditions of problem. In this case we can add the probabilities for each since we don't care which occurs. I think it comes out to .07453

Posted on May 23, 2014, 5:13 PM

Respond to this message   

Return to Index


remember

by (no login)

Get at least 2 matching numbers, 5 draws from 49, this is the lottery in France.

You draw 5 times. At 2 matches you win fee, maybe 6,5 euro. Any formula should process 3 parameters, 2, 5 and 49... imho ; but i think i have the solution, only it took me 3 days to figure it out !

L

Posted on May 24, 2014, 12:13 AM

Respond to this message   

Return to Index


Re: OT : statistics

by SMcNeill (no login)

Seems to me that you're looking at it backwards.

You want to get 2 numbers right out of 49...

That means on the first draw you'd have a 2 in 49 of picking a number. Or 47 in 49 of NOT picking a number.

For the second draw, let's assume you didn't get one of those numbers. You now have a 46 in 48 chance of NOT picking one of your numbers.

3rd draw is 45 in 47. 4th draw is 44 in 46. 5th draw is 43 in 45.

(47 * 46 * 45 * 44 * 43) / (49 * 48 * 47 * 46 * 45) is the chance you didn't draw either number. Which gives a puny chance that you even drew 1 of them....

Which is why I don't play the lotto. ;)

Posted on May 23, 2014, 4:39 AM

Respond to this message   

Return to Index


The problem

by (no login)

I can't explain it right now, but your idea will not discriminate between arrangements and permutations...

The first draw will give you 1 right/false number. You have in fact 2/49 chances to get a right number, but you want only 1 of 49 for 1 draw, and 1 for the second, so you want a couple of draws. How to get a couple, in 2 draw. The fist you choose 1/49, then 1/48. The chance this matches the wanted couple is in fact 1/49 x 1/48 arrangements, and 2! times more if permutations are wanted. later...

L

Posted on May 23, 2014, 3:16 PM

Respond to this message   

Return to Index


Re: The problem

by SMcNeill (no login)

Aye. I was looking at the chance that neither number ever came up earlier.

Let's work this out logically. See if this doesn't make sense.

The chance you guess the first ball correctly is 2 in 49. (For example you want a 1 or a 2 to appear out of those 49 balls.)
The chance you guess the second ball correctly is 1 in 48. (1 fewer ball remains to be drawn, since you got the ball correct on the first guess.)

So the chance of getting your two numbers to appear in a row would be (2/49 * 1/48 = 2 /2352) or 1 in 1176. = 0.0850%

Now, if we add a 3rd ball in there:
We have a 2 in 49 to get the first ball. And a 1 in 48 to get the second ball. (1/1176 chance of this occurring)
PLUS the 2 in 49 to get the first ball. And a 1 in 47 to get the 3rd ball (we missed the second). (1/2303 chance of this occurring)
PLUS the 2 in 48 chance we got the second ball (we missed the first one). And a 1 in 47 chance we got the 3rd. (2/2303 chance of this occurring)

So the chance of getting 2 balls out of 3 draws would be (1/1176 + 1/2303 + 2/2303) = .215%



For 5 balls, we apply the same logic:
ball 1 and 2. 2/49 * 1/48 PLUS
ball 1 and 3. 2/49 * 1/47 PLUS
ball 1 and 4. 2/49 * 1/46 PLUS
ball 1 and 5. 2/49 * 1/45 PLUS
ball 2 and 3. 2/48 * 1/47 PLUS
ball 2 and 4. 2/48 * 1/46 PLUS
ball 2 and 5. 2/48 * 1/45 PLUS
ball 3 and 4. 2/47 * 1/46 PLUS
ball 3 and 5. 2/47 * 1/45 PLUS
ball 4 and 5. 2/46 * 1/45 ......

And the total of the above gives you the chance of getting 2 balls correct out of 5 draws, with numbers from 1 to 49.

Which if I entered all that right into my calculator, seems to give a .907% chance.

Which is just a smidgen more than 9 in 1000 chance.


****************
Does my logic seem faulty here? The best I can tell, that should have it all sorted out. ;)

Posted on May 23, 2014, 11:30 PM

Respond to this message   

Return to Index


Input statement

by (no login)

In GWBasic I have code that runs perfectly, but which I cannot transfer to QB64.

I wish to change data which I have in one line on the screen. In GWBasic line 7520 positions the cursor at the correct place and line 7530 allows movement from the keyboard across the screen line, accepting arrow keys to advance. The Enter key moves to line 7540 which collects up the new data as I$. The program also runs if I replace 'Input' with 'Line Input'.

However, when this compiles into QB64 the 'Input' statement does not collect arrow keys, so I cannot advance across the line except by slow typing. How can I modify the code so that 'Input' accepts arrow keys and advances the cursor appropriately?

Thanks for any advice.



7520 LOCATE J + 1, 5
7530 INPUT "",J$
7540 Y = CSRLIN - 1: I$ = "": FOR X = 5 TO 79: Z = SCREEN(Y, X): I$ = I$ + CHR$(Z): NEXT

Posted on May 10, 2014, 7:17 PM

Respond to this message   

Return to Index


Why not use space?

by Dave (no login)

It seems like your program would interpret three right-arrow-key presses followed by a "d" as three spaces followed by a d.
So why not use the space bar in place of the right arrow key?
Otherwise, you could write a custom input function. Would be simple enough, depending on how much functionality you want.

Posted on May 10, 2014, 9:04 PM

Respond to this message   

Return to Index


Collecting input

by (no login)

Thanks Dave,

But using the space bar obliterates whatever is already there.

For instance, I have '123456789' on the screen, and I wish to change it to '123456780'.
In GWBasic, with the cursor hovering on the '1', by using the right arrow eight times I can then overtype the '9' with '0'. In QB64 the right arrow doesn't move the cursor, and the space bar obliterates the '1 - 8'.

Line input works, in that it accepts the arrow keys, but it provides no cursor and so you don't know where on the line you are. If I knew how to customise line input so that it provided a cursor, I would be happy.

Posted on May 11, 2014, 5:09 PM

Respond to this message   

Return to Index


custom input function?

by Dave (no login)

It wouldn't be that hard to come up with a custom input function. Would need to know what screen mode you were in, though. Could do a cursor more easily in graphics mode, otherwise could use a different background color to "highlight" the letter where the cursor is.

Posted on May 11, 2014, 8:22 PM

Respond to this message   

Return to Index


screen for input

by (no login)

I did have the screen at 'Screen 0'; which is presumably text only.

'Screen 9' also runs my program alright in GWBasic. When compiled in QB64, 'Line Input' gives highlighted text as the cursor, but still will not accept the right arrow key, so that if I want to change "123" to "124" I have to type 1,2,4. Not as nice as GWBasic, where I can use the right arrow key and then simply overtype '3' with '4'.

I thought that 'Line Input' was supposed to accept all keys (Other than 'Enter' and a very few others), but that doesn't seem to be the case in QB64.

Posted on May 11, 2014, 11:51 PM

Respond to this message   

Return to Index


Re: screen for input

by Dave (no login)

Here's a function you can call using:
J$ = inputfunc$
rather than input "", J$.

so your code could look like this:
7520 LOCATE J + 1, 5
7530 J$ = inputfunc$
7540 Y = CSRLIN - 1: I$ = "": FOR X = 5 TO 79: Z = SCREEN(Y, X): I$ = I$ + CHR$(Z): NEXT

Just insert the following code into the end of your program:

FUNCTION inputfunc$
y = CSRLIN
xstart = POS(0)
x = xstart
temp$ = ""
COLOR 0, 7
LOCATE y, x: PRINT CHR$(SCREEN(y, x))
DO
y$ = INKEY$
IF y$ = CHR$(0) + "K" AND x > xstart THEN
'left-arrow
COLOR 7, 0
LOCATE y, x: PRINT CHR$(SCREEN(y, x))
x = x - 1
COLOR 0, 7
LOCATE y, x: PRINT CHR$(SCREEN(y, x))
END IF

IF y$ = CHR$(0) + "M" AND x < 80 THEN
'right-arrow
COLOR 7, 0
IF x - xstart = LEN(temp$) THEN temp$ = temp$ + " "
LOCATE y, x: PRINT MID$(temp$, x - xstart + 1, 1)
x = x + 1
COLOR 0, 7
LOCATE y, x: PRINT CHR$(SCREEN(y, x))
END IF

IF y$ >= CHR$(32) AND y$ <= CHR$(126) THEN
'all basic characters
COLOR 7, 0
LOCATE y, x: PRINT y$
IF x - xstart < LEN(temp$) THEN MID$(temp$, x - xstart + 1, 1) = y$
IF x - xstart = LEN(temp$) THEN temp$ = temp$ + y$
x = x + 1
COLOR 0, 7
LOCATE y, x: PRINT CHR$(SCREEN(y, x))
END IF

IF y$ = CHR$(8) AND x > xstart THEN
'bksp
COLOR 7, 0
LOCATE y, x: PRINT CHR$(SCREEN(y, x))
x = x - 1
temp$ = LEFT$(temp$, x - xstart) + RIGHT$(temp$, LEN(temp$) - (x - xstart) - 1)
LOCATE y, xstart: PRINT temp$ + " "
COLOR 0, 7
LOCATE y, x: PRINT CHR$(SCREEN(y, x))
END IF
IF y$ = CHR$(13) THEN EXIT DO
LOOP
inputfunc$ = temp$
END FUNCTION


Notice this only uses basic characters, as well as left and right arrow keys, backspace, and enter. I could add other keys if you wanted. Let me know if it works or if there's any trouble with it.

Dave

Posted on May 12, 2014, 7:41 PM

Respond to this message   

Return to Index


Thanks

by kanga85 (no login)

Thanks Dave; I'll have a play with your code. Now that I see how you do it, I think that I will be able to make any required modifications myself. This may take some time as other duties call; and my modem has just packed up.

Your help is impressive. Thanks

Posted on May 12, 2014, 9:56 PM

Respond to this message   

Return to Index


usb port programming

by Leon Schrecengsot (no login)

I have a usb to parallel converter piece of hardware (Numato Labs usb gpio module). It came with a set of drivers and command set. Has anyone used this type of hardware? I think I should be able to use the open com port but I am not famillar enought to get it to work. Any help would be greatly appreciated.

Posted on May 1, 2014, 4:14 PM

Respond to this message   

Return to Index


We have am application that converts QBasic programs to USB devices.

by Pete (Login The-Universe)
Admin

Download QB64 athttp://www.QB64.net.

Pete

Posted on May 2, 2014, 12:46 PM

Respond to this message   

Return to Index


usb ports

by Leon Schrecengost (no login)

Pete, Where can I find these programs and can they be downloaded?

Posted on May 5, 2014, 7:50 AM

Respond to this message   

Return to Index


Re: usb ports

by Pete (Login The-Universe)
Admin

Posted on May 5, 2014, 2:43 PM

Respond to this message   

Return to Index


Parallel like LPT? That's not a COM port

by (Login burger2227)
R

That is probably for a LPT printer. Have you used it yet? What works on it?

Posted on May 2, 2014, 1:58 PM

Respond to this message   

Return to Index


com port

by Leon Schrecengost (no login)

The device I have is a usb/parallel piece of hardware. It's made be Numato labs and it's called usb gpio module.

Posted on May 5, 2014, 7:48 AM

Respond to this message   

Return to Index


Call a Word.doc file from QB64?

by (no login)

In QB64 I have written out to the hard drive a text file Text.doc which I would like to open, using Microsoft Word, from within QB. Is there a command which allows me to call a Word document from within QB. Alternatively, I could live with a command within QB64 which closed QB while opening Word.exe at the same time.

Any suggestions?

Thanks

Posted on Apr 28, 2014, 8:52 PM

Respond to this message   

Return to Index


Use SHELL

by (Login burger2227)
R

SHELL _HIDE _DONTWAIT "C:Program FilesMicrosoft OfficeOffice12Winword.exe"

I found that _DONTWAIT is required to run both at once even if QB64 will close.

In the path, my version has an Office12 folder. Check for your path in Program Files.

Command line switches and files are listed here for Office 2007:

http://office.microsoft.com/en-us/word-help/command-line-switches-for-microsoft-office-word-2007-HP010164010.aspx

Posted on Apr 29, 2014, 7:52 AM

Respond to this message   

Return to Index


Thanks

by kanga85 (no login)

Thanks Clippy, I'll play around with it.

Posted on Apr 29, 2014, 12:19 PM

Respond to this message   

Return to Index


drawing program

by (no login)


DEFINT A-Z
DECLARE SUB mouse (ax AS INTEGER, mb AS INTEGER, mx AS INTEGER, my AS INTEGER)
DECLARE SUB redraw ()

CONST pi! = 3.141593

TYPE ccttype
node1 AS INTEGER
node2 AS INTEGER
t AS INTEGER
v AS SINGLE
END TYPE

DIM SHARED m(7) AS LONG
m(0) = &H8BE58955
m(1) = &H48B0C76
m(2) = &H768B33CD
m(3) = &H8B1C890A
m(4) = &HC890876
m(5) = &H8906768B
m(6) = &H8CA5D14

DIM SHARED mb AS INTEGER, mx AS INTEGER, my AS INTEGER

DIM SHARED cct(500) AS ccttype
DIM SHARED n AS INTEGER
DIM SHARED sx AS INTEGER, sy AS INTEGER
DIM SHARED sx0 AS INTEGER, sy0 AS INTEGER
sx0 = -1
sy0 = -1
sx = -1
sy = -1

DIM SHARED del AS INTEGER
del = 0

SCREEN 12

mouse 0, mb, mx, my
redraw
mouse 1, mb, mx, my

n = 0
ct = 1

DO
mouse 3, mb, mx, my
key$ = INKEY$

SELECT CASE key$
CASE CHR$(0) + "S"
LOCATE 1, 1: PRINT "delete"
del = -1
redraw
CASE "z"
IF n > 0 THEN n = n - 1
redraw
CASE "s"
ct = 0
LOCATE 1, 1: PRINT "select"
CASE "w"
ct = 1
LOCATE 1, 1: PRINT "wire"
CASE "r"
IF ct = 2 THEN ct = 3 ELSE ct = 2
LOCATE 1, 1: PRINT "resistor"; ct
CASE "i"
IF ct >= 4 AND ct <= 6 THEN ct = ct + 1 ELSE ct = 4
LOCATE 1, 1: PRINT "current src"; ct
CASE "v"
IF ct >= 8 AND ct <= 10 THEN ct = ct + 1 ELSE ct = 8
LOCATE 1, 1: PRINT "voltage src"; ct
CASE "g"
ct = 12
LOCATE 1, 1: PRINT "ground"
END SELECT

SELECT CASE ct
CASE 0
IF mb = 1 THEN
DO WHILE mb = 1
mouse 3, mb, mx, my
LOOP

ax = (mx 8) * 8
IF mx - ax > 4 THEN ax = ax + 8
ay = (my 8) * 8
IF my - ay > 4 THEN ay = ay + 8

DO WHILE mb = 0
mouse 3, mb, mx, my

bx = (mx 8) * 8
IF mx - bx > 4 THEN bx = bx + 8
by = (my 8) * 8
IF my - by > 4 THEN by = by + 8

LINE (ax, ay)-(bx, by), 4, B
LOOP
DO WHILE mb = 1
mouse 3, mb, mx, my
LOOP

sx0 = ax
sy0 = ay
sx = bx
sy = by
IF sx0 > sx THEN SWAP sx0, sx
IF sy0 > sy THEN SWAP sy0, sy

redraw
END IF
CASE 1
IF mb = 1 THEN
DO WHILE mb = 1
mouse 3, mb, mx, my
LOOP

ax = (mx 8) * 8
IF mx - ax > 4 THEN ax = ax + 8
ay = (my 8) * 8
IF my - ay > 4 THEN ay = ay + 8

DO WHILE mb = 0
mouse 3, mb, mx, my

bx = (mx 8) * 8
IF mx - bx > 4 THEN bx = bx + 8
by = (my 8) * 8
IF my - by > 4 THEN by = by + 8

LINE (ax, ay)-(bx, by), 8
LOOP
DO WHILE mb = 1
mouse 3, mb, mx, my
LOOP

n = n + 1
cct(n).node1 = (ay 8) * 80 + ax 8
cct(n).node2 = (by 8) * 80 + bx 8
cct(n).t = ct

redraw
END IF
CASE 2, 4, 6, 8, 10
ax = (mx 8) * 8
IF mx - ax > 4 THEN ax = ax + 8
ay = (my 8) * 8
IF my - ay > 4 THEN ay = ay + 8

LINE (ax, ay - 8)-STEP(56, 16), 8, B

IF mb = 1 THEN
DO WHILE mb = 1
mouse 3, mb, mx, my
LOOP

n = n + 1
cct(n).node1 = (ay 8) * 80 + ax 8
cct(n).node2 = (ay 8) * 80 + (ax + 56) 8
cct(n).t = ct

redraw
END IF
CASE 3, 5, 7, 9, 11, 12
ax = (mx 8) * 8
IF mx - ax > 4 THEN ax = ax + 8
ay = (my 8) * 8
IF my - ay > 4 THEN ay = ay + 8

LINE (ax - 8, ay)-STEP(16, 56), 8, B

IF mb = 1 THEN
DO WHILE mb = 1
mouse 3, mb, mx, my
LOOP

n = n + 1
cct(n).node1 = (ay 8) * 80 + ax 8
cct(n).node2 = ((ay + 56) 8) * 80 + ax 8
cct(n).t = ct

redraw
END IF
END SELECT
'LOCATE 1, 1: PRINT mb, mx, my
LOOP UNTIL INP(&H60) = 1
SYSTEM

SUB mouse (ax, mb, mx, my)
DEF SEG = VARSEG(m(0))
CALL absolute(ax, mb, mx, my, VARPTR(m(0)))
END SUB

SUB redraw
DIM t AS SINGLE

CLS
FOR y = 0 TO 480 STEP 8
LINE (0, y)-(640, y), 8, , 1 + 2 ^ 7
NEXT

FOR i = 1 TO n
x0 = (cct(i).node1 MOD 80) * 8
y0 = (cct(i).node1 80) * 8
x = (cct(i).node2 MOD 80) * 8
y = (cct(i).node2 80) * 8

IF x0 >= sx0 AND y0 >= sy0 AND x0 <= sx AND y0 <= sy THEN
c = 10
ELSE
IF x >= sx0 AND y >= sy0 AND x <= sx AND y <= sy THEN
c = 10
ELSE
c = 15
END IF
END IF

SELECT CASE cct(i).t
CASE 1
LINE (x0, y0)-(x, y), c
CIRCLE (x0, y0), 2, c
CIRCLE (x, y), 2, c
CASE 2, 3
CIRCLE (x0, y0), 2, c
IF cct(i).t = 2 THEN
LINE -(x0 + 10, y0), c
ELSE
LINE -(x0, y0 + 10), c
END IF

FOR t = 15 TO 40 STEP 5
f = 5 * COS(.2 * pi! * t)
IF cct(i).t = 2 THEN
LINE -(t + x0, f + y0), c
ELSE
LINE -(f + x0, t + y0), c
END IF
NEXT
IF cct(i).t = 2 THEN
LINE -STEP(5, -5), c
ELSE
LINE -STEP(-5, 5), c
END IF

LINE -(x, y), c
CIRCLE (x, y), 2, c

CASE 4, 5, 6, 7
CIRCLE (x0, y0), 2, c
IF cct(i).t AND 1 THEN
LINE -STEP(0, 15), c
CIRCLE (x, y), 2, c
LINE -STEP(0, -15), c
LINE (x0, y0 + 20)-STEP(0, 16), c
IF cct(i).t = 5 THEN
LINE -STEP(-3, -3), c
LINE -STEP(6, 0), c
LINE -STEP(-3, 3), c
ELSE
LINE (x0, y0 + 20)-STEP(3, 3), c
LINE -STEP(-6, 0), c
LINE -STEP(3, -3), c
END IF

ELSE
LINE -STEP(15, 0), c
CIRCLE (x, y), 2, c
LINE -STEP(-15, 0), c
LINE (x0 + 20, y0)-STEP(16, 0), c
IF cct(i).t = 4 THEN
LINE -STEP(-3, -3), c
LINE -STEP(0, 6), c
LINE -STEP(3, -3), c
ELSE
LINE (x0 + 20, y0)-STEP(3, -3), c
LINE -STEP(0, 6), c
LINE -STEP(-3, -3), c
END IF
END IF

xm = (x + x0) / 2
ym = (y + y0) / 2
CIRCLE (xm, ym), 13, c
CASE 8, 9, 10, 11
CIRCLE (x0, y0), 2, c
IF cct(i).t AND 1 THEN
LINE -STEP(0, 15), c
CIRCLE (x, y), 2, c
LINE -STEP(0, -15), c

IF cct(i).t = 9 THEN
LINE (x0, y0 + 20)-STEP(0, 5), c
LINE (x0 - 2, y0 + 33)-STEP(4, 0), c
LINE (x0 - 2, y0 + 23)-STEP(4, 0), c
ELSE
LINE (x0 - 2, y0 + 22)-STEP(4, 0), c
LINE (x0, y0 + 30)-STEP(0, 5), c
LINE (x0 - 2, y0 + 33)-STEP(4, 0), c
END IF
ELSE
LINE -STEP(15, 0), c
CIRCLE (x, y), 2, c
LINE -STEP(-15, 0), c

IF cct(i).t = 8 THEN
LINE (x0 + 20, y0)-STEP(5, 0), c
LINE (x0 + 31, y0)-STEP(5, 0), c
LINE (x0 + 33, y0 - 2)-STEP(0, 4), c
ELSE
LINE (x0 + 20, y0)-STEP(5, 0), c
LINE (x0 + 31, y0)-STEP(5, 0), c
LINE (x0 + 23, y0 - 2)-STEP(0, 4), c
END IF
END IF

xm = (x + x0) / 2
ym = (y + y0) / 2
CIRCLE (xm, ym), 13, c
CASE 12
CIRCLE (x0, y0), 2, c
LINE -STEP(0, 16), c
LINE -STEP(-16, 0), c
LINE -STEP(32, 0), c
LINE (x0 - 10, y0 + 20)-STEP(20, 0), c
LINE (x0 - 4, y0 + 24)-STEP(8, 0), c
END SELECT
NEXT
END SUB

Posted on Apr 26, 2014, 6:44 PM

Respond to this message   

Return to Index


Error with ax = (mx 8) * 8 and similar lines...

by (Login qb432l)
Mod

What should they have been?

We have problems posting code here at the forum - certain code characters are confused with HTML tags and things get zapped.

-Bob

Posted on Apr 26, 2014, 7:03 PM

Respond to this message   

Return to Index


Re: Error with ax = (mx 8) * 8 and similar lines...

by Jim (no login)

Here's a screeshot:
http://i.imgur.com/NNfasv7.png

It's a very basic circuit schematic drawing that I came up with in a few hours but I'm really liking the interface. It's a lot more comfortable for me to use than some of the programs available for this purpose which can be very tedious. I think most people just use general CAD programs for schematic drawing anyway.

I'm probably going to rewrite it in C and go with it as a serious project I can personally use with various simulation and signal processing algorithms. I've learned that it's very easy conceptually to implement basic voltage bias node analysis, just requires some tedious linear algebra to implement.

I hope you're doing well, Bob, and still drawing and programming.

Posted on Apr 28, 2014, 12:08 AM

Respond to this message   

Return to Index


*Nice work - I love the precision of computer drawings. I'm fine, thanks.

by (Login qb432l)
Mod

*

Posted on Apr 28, 2014, 1:05 AM

Respond to this message   

Return to Index


integer division sign is missing everywhere

by Keith (no login)

**** this forum ****ING *****
******
******





Note from Solitaire: There is no need to curse for the limitations of this forum. It's been around for a long time and we've all learned to put up with it.

Posted on Apr 26, 2014, 7:04 PM

Respond to this message   

Return to Index


Re: integer division sign is missing everywhere

by (Login MCalkins)
Moderator

The problem has been around since at least October of last year. All backslashes have to be doubled.

So, 1 backslash disappears:


2 backslashes turn into 1:
\

4 backslashes turn into 2:
\\

etc...

Regards,
Michael

Posted on May 1, 2014, 5:32 PM

Respond to this message   

Return to Index


Code doesn't return correctly in QB64. Do I have double precision ok?

by (no login)

This code, opening a data file in line 9010, returning to the main program to get a record # R, and then collecting data in line 9020, works perfectly in GWBasic but not in QB64. The values C,S,SG,DY returned are all zero in QB64.

I have change the open statement to:

OPEN "Moneyrec.dat" for random as #1 Len=32
but no improvement.

Any help is appreciated. Thanks
----------------------------------------------

9010 OPEN "R", #1, "MONEYREC.DAT", 32: FIELD #1, 8 AS C$, 8 AS S$, 8 AS SG$, 8 AS DY$: LOR = LOF(1) / 32: RETURN

9020 GET #1, R: C = CVD(C$): S = CVD(S$): SG = CVD(SG$): DY = CVD(DY$): RETURN

Posted on Apr 23, 2014, 4:37 PM

Respond to this message   

Return to Index


CVD in GWBasic and QB64

by (no login)

Further exploration of CVD.

In GWBasic, x=CVD(x$) returns the expected value of 32 (x$ is stored in my GWBasic datafile).

In QB64, x=CVD(x$)returns a value of -1.322163849510373D-279 (using the same datafile as above).

How can I read my GWBasic data files with QB64. Is there a command that will convert GWBasic double precision into QB64 double precision?

Thanks for any advice.

Posted on Apr 24, 2014, 8:36 PM

Respond to this message   

Return to Index


* Try changing CVD to CVDMBF. I don't know if it is implemented.

by (Login MCalkins)
Moderator

Posted on Apr 25, 2014, 8:40 AM

Respond to this message   

Return to Index


Thanks, but...

by (no login)

Thanks Michael,

After changing CVD to CVDMBF, the program seemed to compile alright, but when run gave a 'Unhandled Error' in that line. I'll play around further.

Posted on Apr 25, 2014, 8:48 PM

Respond to this message   

Return to Index


* It might not be properly implemented. I'll try it in a day or two.

by (Login MCalkins)
Moderator

Posted on Apr 26, 2014, 1:12 PM

Respond to this message   

Return to Index


Work around

by kanga85 (no login)

Don't try too hard Michael.

I have by-passed the problem by, in GWBasic (which I have running on an old machine), getting all the DBL precision data (8 bytes) from my old data file and LSET'ing them as double precision numbers of 12 bytes length into a new data file. Then changed my running program accordingly and compiled it in QB64. Runs well. It means the data file is now 1.5 times bigger, but that is trivial with the amount of storage available these days.

The data are various financial records dating back to to 1961, which I first stored in 1975 on a Hitachi Peach (<34K bytes for program and storage, unless you read it out to an old floppy - or tape!)and which I have subsequently moved onto later machines: DOS - Windows of various values - XP and now Win7/Win8.

I've learned a lot, mostly useless, but the logic stays with you.

Thanks

Posted on Apr 28, 2014, 1:07 AM

Respond to this message   

Return to Index


Re: Work around

by (Login MCalkins)
Moderator

Well, I tried MKDMBF$ and CVDMBF in QB64 0.980, and both seem to match QBASIC 1.1.

MKDMBF$ and CVDMBF in QBASIC / QB64 should be the same, I would think, as MKD$ and CVD in GW-BASIC.

I don't understand how changing to 12 bytes makes a difference.

I suggest that floating point types are unsuitable for currency, and that LONG integers representing pennies would be more suitable. Floating point is subject to rounding.

The IEEE DOUBLE type has more range, but less precision, than the MBF DOUBLE type.

Regards,
Michael

Posted on Apr 30, 2014, 4:57 PM

Respond to this message   

Return to Index


How many files open at once in QB64

by (Login Kanga85)

I have a Basic program running perfectly in GWBasic on an XP machine. It has 4 files open at any one time. (GWBasic /F:4). I have compiled it in QB64, but it now doesn't find the data in an opened file. How many open files can I have in QB64, and do I need to specify the number to be opened before I compile the program?

Thanks for any help.

Posted on Apr 22, 2014, 7:56 PM

Respond to this message   

Return to Index


Re: How many files open at once in QB64

by SMcNeill (no login)

We just had a long discussion about this a month or so ago over on the Qb64 forums. QB64 can open and access a LONG's worth of files at any given time: IF your computer has the memory to support them. Each open file uses 4 bytes of memory and 4 BILLION files causes out of memory errors on most any computer. (You'd need to compile in x64 mode and use over 16GB of ram to hold all the file handles....)

But 4 files? That shouldn't be an issue at all, on any system that can run QB64. ;)


As for numbering the files, either use 1,2,3,4 or use _FREEFILE with a variable, and you shouldn't have any issues. (FREEFILE automatically gives you the next available file handle.)

Posted on Apr 23, 2014, 11:06 AM

Respond to this message   

Return to Index


thanks

by (no login)

Thanks SMcNeill. Helpful and encouraging.

Posted on Apr 23, 2014, 4:39 PM

Respond to this message   

Return to Index


Qbasic program to store student data permanently in a file and search it

by (Login diwesh87)

Hi i am a complete newbie to Qbasic and am looking for help . I need to create a program that stores the student records in a file and can search it later from the file using the student name or id . I wrote a little program but doesn't work well .


Posted on Apr 22, 2014, 1:40 AM

Respond to this message   

Return to Index


Here is what i coded

by (Login diwesh87)

REM This program will create a sequential file named INFO.DAT.
REM The file will then be used to store input data supplied
REM by the user and then to retreive the data contained in
REM in the file.
REM
REM PROGRAMMER: Diwesh
REM DATE LAST UPDATED: 22-5-2014

OPEN "INFO.DAT" FOR OUTPUT AS #1

CLS

REM Get input from user
INPUT "Do you wish to enter student information (Y/N)"; answer$

DO WHILE answer$ = "Y" OR answer$ = "y"
INPUT "Enter student name: ", name$
INPUT "Enter student id: ", id
INPUT "Enter student gpa: ", gpa

REM Write current input to temporary buffer storage 1
WRITE #1, name$, id, gpa

INPUT "Do you wish to enter new student information (Y/N)"; answer$
LOOP

REM Transer data from temporary buffer 1 to actual INFO.DAT
CLOSE #1

OPEN "INFO.DAT" FOR INPUT AS #2

PRINT "STUDENT LISTING"
PRINT "----------------------------------------"

DO WHILE NOT EOF(2)
INPUT #2, name$, id, gpa
PRINT
PRINT "STUDENT NAME: "; name$
PRINT " STUDENT ID:"; id
PRINT " STUDENT GPA:"; gpa
LOOP

CLOSE #2

END

Posted on Apr 22, 2014, 1:42 AM

Respond to this message   

Return to Index


File extension and searching

by Solitaire (no login)

Your program works. I would suggest changing the file extension from .DAT to .TXT.

What is it about the program that doesn't work well for you?

In order to implement search functions, after you list the data, ask the user to enter the name and/or the id to search for. Then reopen the file for input and use another loop with an IF block to find a match for the name or the id. If found, it will then print out the data.


Posted on Apr 22, 2014, 10:06 AM

Respond to this message   

Return to Index


Graphical input routine

by Steve (no login)

I'm working on a program where I have a number of variables listed on the screen. I'm trying to revise it to the point where my variables are inside a box and if the mouse cursor is over that box it highlights and then increases or decreases the variable with the scroll wheel. At the moment I have about 20 lines checking keypresses to increase and decrease the variables. Is there a subroutine someone has or knows about that I can learn from and modify to fit into my program?

Posted on Apr 1, 2014, 10:14 AM

Respond to this message   

Return to Index


*Do you already have a mouse routine that covers x/y and scrollwheel?

by (Login qb432l)
Mod

*

Posted on Apr 1, 2014, 11:32 AM

Respond to this message   

Return to Index


2048 game

by deanm (no login)

' Move the tiles using the arrow keys
' Join the numbers and get to the 2048 tile!
DEFINT A-Z
RANDOMIZE TIMER
DIM grid(1 TO 4, 1 TO 4)
DO
CLS
placed = 0
DO
x = INT(RND(1) * 4) + 1
y = INT(RND(1) * 4) + 1
IF grid(x, y) = 0 THEN grid(x, y) = 2 + 2 * INT(RND(1) * 2): placed = 1
LOOP UNTIL placed = 1
lose = -1: win = 0
FOR i = 1 TO 4
PRINT "+-----+-----+-----+-----+"
PRINT "|";
FOR j = 1 TO 4
IF grid(i, j) = 2048 THEN win = -1: lose = 0
IF grid(i, j) = 0 THEN lose = 0: PRINT " |"; ELSE COLOR 0, LOG(grid(i, j)) / LOG(2): PRINT USING "#####"; grid(i, j); : COLOR 7, 0: PRINT "|";
NEXT
PRINT
NEXT
PRINT "+-----+-----+-----+-----+"
IF win THEN PRINT "You Win!!!": END
IF lose THEN PRINT "You Lose!": END
x$ = "": WHILE x$ = "": x$ = INKEY$: WEND
SELECT CASE x$
CASE CHR$(27)
END
CASE CHR$(0) + CHR$(72)' up
FOR i = 3 TO 1 STEP -1
FOR j = 1 TO 4
IF grid(i, j) = 0 THEN grid(i, j) = grid(i + 1, j): grid(i + 1, j) = 0
IF grid(i, j) = grid(i + 1, j) THEN grid(i, j) = grid(i, j) * 2: grid(i + 1, j) = 0
NEXT
NEXT
CASE CHR$(0) + CHR$(75) 'left
FOR i = 1 TO 4
FOR j = 3 TO 1 STEP -1
IF grid(i, j) = 0 THEN grid(i, j) = grid(i, j + 1): grid(i, j + 1) = 0
IF grid(i, j) = grid(i, j + 1) THEN grid(i, j) = grid(i, j) * 2: grid(i, j + 1) = 0
NEXT
NEXT
CASE CHR$(0) + CHR$(77)' right-
FOR i = 1 TO 4
FOR j = 2 TO 4
IF grid(i, j) = 0 THEN grid(i, j) = grid(i, j - 1): grid(i, j - 1) = 0
IF grid(i, j) = grid(i, j - 1) THEN grid(i, j) = grid(i, j) * 2: grid(i, j - 1) = 0
NEXT
NEXT
CASE CHR$(0) + CHR$(79) ' down
FOR i = 2 TO 4
FOR j = 1 TO 4
IF grid(i, j) = 0 THEN grid(i, j) = grid(i - 1, j): grid(i - 1, j) = 0
IF grid(i, j) = grid(i - 1, j) THEN grid(i, j) = grid(i, j) * 2: grid(i - 1, j) = 0
NEXT
NEXT
END SELECT


LOOP

Posted on Mar 25, 2014, 3:04 PM

Respond to this message   

Return to Index


MS-DOS source code now available from Microsoft

by Billy G (no login)

http://blogs.technet.com/b/microsoft_blog/archive/2014/03/25/microsoft-makes-source-code-for-ms-dos-and-word-for-windows-available-to-public.aspx

Posted on Mar 25, 2014, 1:47 PM

Respond to this message   

Return to Index


Cool

by (Login MCalkins)
Moderator

But the license is for non-commercial research. It allows derivation, but not redistribution.

Still waiting for the day when they release QBASIC 1.1, or Windows 95 through 98SE, or even 2000 SP4 under either LGPL, or something like 2-clause BSD. (Yeah, dream on...)

Regards,
Michael

Posted on Mar 26, 2014, 8:31 AM

Respond to this message   

Return to Index


We don't need the code. Galleon already did most of that.

by (Login burger2227)
R

The 16 bit stuff is lost anyhow. We will never go back.

I see somebody saw that link at QB64 too.

Posted on Mar 26, 2014, 10:25 AM

Respond to this message   

Return to Index


Updated to a new key input routine.

by Pete (Login The-Universe)
Admin

I decided to try out the newer QB64 statements, and made another key input program that can be customized. I posted it at QB64.net to avoid the hassle and probably "sign" bug mishaps N54 forums produce.

http://www.qb64.net/forum/index.php?topic=11727.0

QB64 has the advantage of dropping PEEk / POKE to map 2-key presses with INKEY$, but the trade off is more code in the way of conditional statements to achieve the same goal. That's OK, as the days of needing to optimize to save memory are no longer an issue with QB64.

Have a look, if you're interested.

Pete

Posted on Mar 18, 2014, 7:38 AM

Respond to this message   

Return to Index


*Very impressive. Never wrote a text editor, but if I ever do, you da man!

by (Login qb432l)
Mod

*

Posted on Mar 18, 2014, 3:44 PM

Respond to this message   

Return to Index


Nice, but I like QB64's INP arrays better

by (Login burger2227)
R

QB64 does not have those INP(96) Number Lock and Caps Lock limitations that QB did. Plus it now includes the Windows and Menu keys.

http://www.qb64.net/wiki/index.php/Keyboard_scancodes

Posted on Mar 20, 2014, 7:38 AM

Respond to this message   

Return to Index


I don't see a text use advantage, but...

by Pete (Login The-Universe)
Admin

I'm curious if it tests faster than _KEYHIT. If so, it would be a better gaming choice. BTW - Did you design that particular wiki page? If so, very impressive layout.

Pete

Posted on Mar 20, 2014, 9:08 AM

Respond to this message   

Return to Index


Yes I did.

by (Login burger2227)
R

Thanks, I just put the keyboard layouts all in one place for easy reference.

I never tested for any speed difference because I'm not fast enough anymore... happy.gif

Posted on Mar 20, 2014, 5:10 PM

Respond to this message   

Return to Index


*From my testing, _KEYHIT offers the fastest response times.

by SMcNeill (no login)

Posted on Mar 20, 2014, 5:41 PM

Respond to this message   

Return to Index


Needing some help

by (no login)

Let me clarify, this is my Programming MidTerm. Not asking for it to be finished for me, but asking help for ideas. Or hints to get my program finished. I am at a wall at this moment.

I finished almost all parts of the MidTerm, but now I must have it output the highest grade average out of the four students, then output it to a line.
"Search the grades array for the highest grade average and output it with the appropriate student name and class name."

I have notes and other examples from class, but I can't seem to figure what to use.If anything looks sloppy, let me know how to adjust it. I want to learn not to be told. If you understand what I am meaning.


CLS

DIM course(1 TO 2) AS STRING
DIM student(1 TO 4, 1 TO 2) AS STRING
DIM grades(1 TO 4, 1 TO 3, 1 TO 2) AS INTEGER
DIM class, person, Grade AS INTEGER
DIM average(1 TO 4) AS INTEGER
DIM format AS STRING


FOR class = 1 TO 2
INPUT "Enter course name: ", course(class)
FOR person = 1 TO 2
INPUT "Enter the student's name: ", student(person, class)
FOR Grade = 1 TO 3
PRINT "Enter grade #"; Grade; "for "; student(person, class);
INPUT ": ", grades(person, Grade, class)
NEXT Grade
NEXT person
NEXT class

average(1) = (grades(1, 1, 1) + grades(1, 2, 1) + grades(1, 3, 1)) / 3
average(2) = (grades(2, 1, 1) + grades(2, 2, 1) + grades(2, 3, 1)) / 3
average(3) = (grades(1, 1, 2) + grades(1, 2, 2) + grades(1, 3, 2)) / 3
average(4) = (grades(2, 1, 2) + grades(2, 2, 2) + grades(2, 3, 2)) / 3

CLS
SCREEN 12
format = "###.##"

PRINT "Class"; TAB(10); "Student"
PRINT "Number"; TAB(10); "Number"; TAB(19); "Grade 1"; TAB(27); "Grade 2";
PRINT TAB(35); "Grade 3"; TAB(44); "Average"

PRINT TAB(3); "1"; TAB(13); "1"; TAB(21); grades(1, 1, 1); TAB(29); grades(1, 2, 1);
PRINT TAB(37); grades(1, 3, 1); TAB(44); average(1)
PRINT TAB(13); "2"; TAB(21); grades(2, 1, 1); TAB(29); grades(2, 2, 1);
PRINT TAB(37); grades(2, 3, 1); TAB(44); average(2)
PRINT
LINE (1, 70)-(400, 70), 15
PRINT TAB(3); "2"; TAB(13); "1"; TAB(21); grades(1, 1, 2); TAB(29); grades(1, 2, 2);
PRINT TAB(37); grades(1, 3, 2); TAB(44); average(3)
PRINT TAB(13); "2"; TAB(21); grades(2, 1, 2); TAB(29); grades(2, 2, 2);
PRINT TAB(37); grades(2, 3, 2); TAB(44); average(4)
PRINT
LINE (1, 120)-(400, 120), 15
PRINT



PRINT student(1, 1); "'s average grade in "; course(1); " is:"; USING format; average(1)

PRINT student(2, 1); "'s average grade in "; course(1); " is:"; USING format; average(2)

PRINT student(1, 2); "'s average grade in "; course(2); " is:"; USING format; average(3)

PRINT student(2, 2); "'s average grade in "; course(2); " is:"; USING format; average(4)
PRINT



END


Posted on Mar 11, 2014, 9:39 AM

Respond to this message   

Return to Index


Highest to lowest is accomplished with a bubble sort.

by Pete (Login The-Universe)
Admin

There are different types of sort algorithms. The type I use is fairly simple...

DIM myname$(5), mygrade(5)

myname$(1) = "Steve"
myname$(2) = "Pete"
myname$(3) = "Michael"
myname$(4) = "Clippy"
myname$(5) = "Patrick"

mygrade(1) = 2.0
mygrade(2) = 4.0
mygrade(3) = 3.0
mygrade(4) = 0
mygrade(5) = 1.0

for i = 1 to 5
for j = 1 to 5
if mygrade(i) > mygrade(j) then swap mygrade(i), mygrade(j): swap myname$(i), myname$(j)
next
next

for k = 1 to 5
print myname$(k); mygrade(k)
next

End

-------------------------

The SWAP statement keeps swapping out numbers, organizing them from highest to lowest. Note we also had to swap the names, so the names kept the correct grades.

Try and apply this type of sorting technique to our program and see if you can get your names and grades reported according to your assignment.

- Pete


Posted on Mar 11, 2014, 11:07 AM

Respond to this message   

Return to Index


Get the highest value

by Solitaire (Login Solitaire1)
S

If you only need to get the highest average, then you can simply use the first number in the array and arbitrarily assign the HIGH value to it. Then compare all the rest of the averages to HIGH. If another number is higher, then reassign that number to HIGH.

Here is an example using random values assigned to an array, so you can see how it works.

=========================================================================================

CLS
DIM average(1 TO 4) AS INTEGER
DIM x AS INTEGER, high AS INTEGER, ndx AS INTEGER
RANDOMIZE TIMER
FOR x = 1 TO 4  'assign random values to the array
   average(x) = INT(RND * 100) + 1
   PRINT average(x); "  ";   'display the 4 averages
NEXT x

high = average(1)  'assign arbitrary value to high
ndx = 1
FOR x = 2 TO 4      'compare remaining values with high
    IF average(x) > high THEN
        high = average(x)
        ndx = x
    END IF
NEXT x
PRINT : PRINT "The highest average is "; high
PRINT "The index is "; ndx
END

Posted on Mar 11, 2014, 1:03 PM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement