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



Too much to Fit on the Screen

by Jester (no login)

I have an Array; Array(1000)

Each Index is a random number between 1 - 10000

What I want to do is show these numbers on a screen, but not just in a list. So I used to Locate command like so;

FOR Row = 1 TO 22

FOR Column = 1 TO 70 STEP 5

LOCATE row, column

IF i < 999 THEN

PRINT array(i)

i = i + 1

END IF

NEXT Column

NEXT row

Unfortunately the screen isn't big enough to fit in all the numbers in the Array, and there is a limit to the rows and columns in the screen.

Is there any way for me to fit in all the indexes of the array whilst keeping that tabled look?

Posted on Mar 9, 2011, 11:22 PM

Respond to this message   

Return to Index


WIDTH 80,50

by WIDTH statement (no login)

Put this line at the beginning of your program:
WIDTH 80,50

If that isn't enough, you'll need to write the data to a file.

PS. If you are using QB64, then you can set WIDTH to higher, custom values like WIDTH 150,80

Posted on Mar 10, 2011, 1:00 AM

Respond to this message   

Return to Index


*In SCREEN 12, you can do WIDTH 80,60 too

by WIDTH statement (no login)

Posted on Mar 10, 2011, 1:04 AM

Respond to this message   

Return to Index


* That's only for SCREEN 0, the default...

by (Login burger2227)
R

Posted on Mar 10, 2011, 1:57 AM

Respond to this message   

Return to Index


You can use several screens to display your data.

by Solitaire (Login Solitaire1)
S

Use MOD to repeat the screen display and pause before clearing the screen and showing the next screen.

For example, if you need to repeat your data 150 times to fill a screen, use a counter for each data item, and then you can include:

IF count MOD 150 THEN
INPUT "Press Enter to continue...", E$
END IF

Or just reinitialize the counter to 0 each time and if the count goes to 150 (or whatever), then pause and clear the screen to repeat with the next group of data.

Posted on Mar 10, 2011, 1:33 PM

Respond to this message   

Return to Index


Re: Too much to Fit on the Screen

by Jester (no login)

Sorry, Didn't specify the entire problem well enough.

The program needs to create an array with 1000 indexes and each index needs a random value between 1 to 10000. Then the array needs to be sorted.

I have no problems so far. The problem begins when I have to display the arrays. The program needs to save these numbers as a text file. I just realised that even if I redefined the dimensions of the screen, I still won't be able to fit in all 3000 indexes. Is it possible for the program to just save the array's straight to a text file without printing to screen? Or is it easier to somehow print all 3000 indexes to screen and then saving.

For the person above, Is it possible to save the numbers on the screen, reset the screen and get the new numbers up and repeat that until all the numbers have been printed and saved?

Posted on Mar 10, 2011, 6:59 PM

Respond to this message   

Return to Index


Re: Too much to Fit on the Screen

by AlGoreIthm (no login)

You don't need to print anything before you save it.
Printing to the screen and saving to a file are not related in any way.

You can clear a screen by using CLS and you will have a
clean slate to display your next group of numbers.

This means you'll probably have to learn to use the SLEEP command
in between each set of values you'll be printing to the screen.

Posted on Mar 10, 2011, 8:15 PM

Respond to this message   

Return to Index


Re: Too much to Fit on the Screen

by Jester (no login)

I don't need to print to the scree, I just need to be able to print to a file but i would like the numbers structured in rows and columns. How can I print straight to a text file and not the screen.

This is my code so far,

http://i170.photobucket.com/albums/u248/Frozen_Pheonix/Code(dot)jpg

btw, any and all help is appreciated. And thanks for such quick responses, you guys are amazing.

Posted on Mar 14, 2011, 8:50 PM

Respond to this message   

Return to Index


The "structure" is established by the program, not the file...

by (Login qb432l)
Mod

You can write the information to your file in whatever order is appropriate, then when retrieving from the file, you structure the input when printing to the screen -- for example, using LOCATE, or TAB, or whatever method is convenient.

btw -- your link doesn't work, but this information would apply regardless of the content of your program.

-Bob

Posted on Mar 15, 2011, 2:57 AM

Respond to this message   

Return to Index


* "(dot)" to "." in his URL.

by (Login MCalkins)
Moderator

Posted on Apr 3, 2011, 5:24 PM

Respond to this message   

Return to Index


Re: Too much to Fit on the Screen

by (Login MCalkins)
Moderator

use

Print #filenum

to print to a file instead of the screen. For example:

open "file.txt" for output as 1
print #1, "Hello, from a file!"
close

By the way, you can open your QBASIC program in Notepad, then copy and paste it to the forum. That way, you don't have to post composite screen shots... :-)

Regards,
Michael

Posted on Apr 3, 2011, 5:24 PM

Respond to this message   

Return to Index


RND question

by Fmr (no login)

I know this is a simple command to do but I have not been able to find a tutorial that would lead me to doing this, and my Qbasic knowledge is quite limited.

Basically, I would like to make a command that lists a random combination of animals. It will ask me how many animals I would like to choose from, lets say 3. And from a pre made list, it will print 3 random animals from that list. I know it's a simple process but for the life of me I cannot figure it out. Any help would be greatly appreciated

Posted on Mar 5, 2011, 10:13 PM

Respond to this message   

Return to Index


RND example

by (Login rpgfan3233)

RND is a function that returns a number from 0.0 to 0.999999999999..., such as 0.6837472.

To use it, you do something like this:

RANDOMIZE TIMER
INPUT "How many animals"; nanimals
x = FIX(RND * (nanimals + 1)) + 1
PRINT "Animal"; x; " was chosen at random."

The first line seeds the random number generator, so RND will actually return random values.
The second line naturally gets the number of animals.
The fourth line prints the result.
The third line uses RND to fetch a random number such as 0.6837472 and multiplies it by the number of animals requested, plus 1 because RND will never return 1.0. Supposing nanimals was 3, then it would be 0.6837472*4, which is 2.7349888. That result is used as the argument to the FIX function, which removes the part after the decimal point since you can't have a part of an animal, leaving only 2. Then you add 1, and voilà. You now have animal #3.

Of course, supposing it was 0.2837472*4 for example, it would then be 1.1349888. FIX would remove the part after the decimal point, leaving only 1, and 1 would be added to that result, yielding animal #2 in the end. Remember to use RANDOMIZE TIMER, and RND will work just fine as long as you remember how to use it.

Edit: See the QB64 wiki entry for the RANDOMIZE statement for another example.

Posted on Mar 5, 2011, 11:34 PM

Respond to this message   

Return to Index


rnd is good for when you must make your program roll dice and stuff

by Ben (no login)

its for returning unpredictable numbers

Posted on Mar 6, 2011, 1:33 PM

Respond to this message   

Return to Index


Re: RND question

by (Login codeguy)
R

are ya allowed to pick the same animal more than once? if you are, it's not so bad to code that. if not, then it's a little bit but not much more complicated. ya might take a look at donald knuth's shuffle algo, which slightly modded is a pretty good candidate for this kind of project if an animal can only be chosen once per set of 3 picks.

this one uses a variant of knuth's shuffle to let ya pick 3 animals at random with no repeats in a set of picks, but because of the shuffle algorithm used alters the original list order. depending on the circumstances, this might or might not be alright. please check to make sure.

'***********************
numanimals = 7
Numanimalstochoose = 3
REDIM anim$(numanimals - 1)
FOR n = 0 TO numanimals - 1
READ anim$(n)
NEXT

IF Numanimalstochoose > numanimals THEN
Numanimalstochoose = numanimals
END IF

DO
CLS
FOR x = 0 TO Numanimalstochoose - 1
randomanimal = x + INT(RND * (numanimals - x))
PRINT anim$(randomanimal)
SELECT CASE randomanimal
CASE x
CASE ELSE
SWAP anim$(x), anim$(randomanimal)
END SELECT
NEXT
_DISPLAY
_LIMIT 15
LOOP UNTIL INKEY$ > ""

DATA elephant
DATA tiger
DATA zebra
DATA puma
DATA cheetah
DATA hyena
DATA iguana

Posted on Mar 22, 2011, 12:55 AM

Respond to this message   

Return to Index


Printing via a usb port

by (no login)

some (many) years ago I wrote a QB (4.0) program which prinhts out via LPT1 and I wish to up date it to print on modern printers via a USP port. Can I do this with the latest version of QB. if so how do I get the latest version how much?$ and what Basic command would I use? are my 4.0 manuals (by microsoft any use or can I get new ones/updates
Frank Haighton.

Posted on Feb 28, 2011, 12:10 PM

Respond to this message   

Return to Index


Visit this site...(URL)

by Pete (Login The-Universe)
Admin

http://www.qb64.net

go to the forum and find the download section.

LPRINT is a recent addition to QB64 that does work on newer systems. QBasic has not been updated in years, it is abandoned. Still we could use slave printers on USB ports with QB.

SHELL "cmd /c START /min Notepad /p mydoc.txt"

Pete

Posted on Feb 28, 2011, 3:14 PM

Respond to this message   

Return to Index


please write a program for an enrolement into a baptima class

by (no login)

a simple program for an enrolment into a baptismal class

Posted on Mar 3, 2011, 2:11 AM

Respond to this message   

Return to Index


Sure - Anything else??

by AlGoreIthm (no login)

Posted on Mar 3, 2011, 8:52 AM

Respond to this message   

Return to Index


* Anything else, you bet... he forgot to order fries with that!

by Pete (Login The-Universe)
Admin

Posted on Mar 3, 2011, 9:07 AM

Respond to this message   

Return to Index


* What the hell is a "batima"? Is that what Obama reportedly went to?...

by (Login burger2227)
R

Posted on Mar 5, 2011, 7:44 PM

Respond to this message   

Return to Index


*He said "baptima", a "batima" is a high colonic courtesy of the caped crusader.

by (Login qb432l)
Mod

*

Posted on Mar 5, 2011, 8:20 PM

Respond to this message   

Return to Index


* I'll have to take your word on that great one! :-)

by (Login burger2227)
R

Posted on Mar 6, 2011, 8:10 PM

Respond to this message   

Return to Index


Someone posted a solution to the LESS THAN display problem

by Solitaire (Login Solitaire1)
S

on this forum some time ago, but I can't find it now. Please post it again. It should also be placed in the FAQ or Tips subforum for future reference.

Thanks.

Posted on Feb 26, 2011, 7:51 AM

Respond to this message   

Return to Index


Here Tis

by (Login MarineDon)
R

Hi Solitaire:


The greater than and less than symbols are:
(I am placing spaces between the characters, otherwise
the  > <  symbols themselves will appear)

Greater than: > is & g t ;

Less than: < is & l t ;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You can also use ASCII characters (0-255)
converted to HTML:

ASCII 060 Is: & # 0 0 6 0 ; < LESS-THAN SIGN

ASCII 062 Is: & # x 0 0 3 e; > GREATER-THAN SIGN

Here is a link to converting ASCII to HTML:
For best viewing use your text editor, like NOTEPAD,
to view the page.

LINK;
http://www.smithselfgen.com/QuickBasic/Ascii2Html.Txt

Regards, Don Smith

Posted on Feb 26, 2011, 12:33 PM

Respond to this message   

Return to Index


Thank you, Don.

by Solitaire (Login Solitaire1)
S

But it's very flaky and I had to try several times before it would display correctly. It looks like the "Enable formatted text" needs to be checked.

The Greater Than symbol displays without a problem, but Less Than needs a lot of tweaking.

<
<
<

Posted on Feb 26, 2011, 1:18 PM

Respond to this message   

Return to Index


Unfortunately, N54's HTML filter doesn't handle the less-than character very well at all

by (Login rpgfan3233)

The formatted text option allows one to post plain ol' HTML. However, being reasonably security-conscious and sane, a filter for specific HTML tags was created. This, however, is rather buggy by design. I wish they'd fix it!

On the other hand, you might get away with using <pre>[your code here]</pre>, though the font will appear to be rather large, not to mention the spacing between lines will be exorbitant! However, it has the bonus of keeping the leading spaces in your program. For example:

'Sample program
DIM x AS LONG
x = INT(RND * 101)

IF x = 0 THEN
PRINT "ZERO!" 'Ten spaces between this comment and the statement
ELSEIF x < 60
PRINT "F"
ELSEIF x < 70
PRINT "D"
ELSEIF x < 80
PRINT "C"
ELSEIF x < 90
PRINT "B"
ELSEIF x < 100
PRINT "A"
ELSE
PRINT "A+"
END IF


Edit: By the way, if you use &lt; and &gt; do beware that they'll be converted to their proper forms (< and > respectively), and they won't get converted back if you go back and edit your post or preview your post and choose "Edit" from the preview screen!

Posted on Feb 26, 2011, 2:56 PM

Respond to this message   

Return to Index


Why

by (Login MarineDon)
R

I do not like N54's at all. Why cannot we here
at the forum use something like <code> </code>
to place our code. If we are unhappy with N54,
then why not use another web hosting company?
I have read many gripes about N54, but when
are we going to do something about it?

Yeah, I think I remember that they are inexpensive
and that is the primary consideration for using
them.

Oh well, one of these days, it'll get better,
bye the bye.

Regards friends, Don Smith

Posted on Feb 26, 2011, 5:51 PM

Respond to this message   

Return to Index


* One possible reason is that it already has a easy-to-use forum system set up.

by (Login rpgfan3233)

Posted on Feb 27, 2011, 8:00 AM

Respond to this message   

Return to Index


IT WILL NEVER GET BETTER HERE! IT CAN ONLY GET WORSE!

by (Login burger2227)
R

I just had to close an error box to post this message!

It keeps asking me if I want to DEBUG the forum!!!!!!!!

Those (_0_) have continued to make this place WORSE! They DON'T KNOW what they are doing. They are just barely hanging on at this point.

And DON'T BOTHER asking them for help, most of the "helpers" are JERKS!

Ted

- Pete edited in ASCII graphics in place of word/words we don't want used around here.

Posted on Feb 27, 2011, 8:39 AM

Respond to this message   

Return to Index


Hi Artelius, I've just released QB64 V0.927 for Linux with your _SNDRAW commands!

by Galleon (no login)

I tested them in Linux and as you said, it worked like a charm. The latest version of QB64 has a few nice touches such as proper OS-linked copy/paste support. Try an unmanaged runtime error and a message should appear in a box. Any feedback welcome.

Posted on Feb 26, 2011, 3:16 AM

Respond to this message   

Return to Index


* We could use a few more RAW examples too! :-)

by (Login burger2227)
R

Posted on Feb 26, 2011, 7:51 PM

Respond to this message   

Return to Index


Has anyone done this yet?

by Zack (no login)

Hi, I was gonna make a program that finds the amount of time beteen to moments. Like you would say 1 month and it will take current DATE$ and TIME$ and save it to a file. Now it will save the amount of time you inputted. Then when you run the program at a later date, it will open the file of when you started it and the file of how long the timer was for and get the current DAtE$ and TIME$ and see how much time is left.

I was just wondering if anyone has already done this or something like this. Because it seems like it would be a lot of code because the time you entered plus the current time might move on to the next month or year which would be confusing. Anyway, before i jump into this, if someone has already accomplished this, could they please post the code or give me some tips?

Thanks in advance!
~Zack

Posted on Feb 25, 2011, 7:29 PM

Respond to this message   

Return to Index


Time interval

by Solitaire (Login Solitaire1)
S

I wrote this program several years ago. It doesn't save anything to a file, but has the user press Enter to start and again to stop. It will then display the interval in hours, minutes, and seconds.

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

DECLARE SUB clocktime ()
CLS
PRINT "Display time interval based on system timer."
PRINT "Press Enter to begin timing. Wait for a period of time. "
PRINT "Enter again to stop timing and display how much time has passed."
PRINT : INPUT "Press Enter to begin: ", B$
PRINT : PRINT "Timer is now: "; TIMER;
begin = INT(TIMER + .5)
PRINT " ="; begin; " rounded to nearest second."
CALL clocktime
PRINT : INPUT "Wait and then press Enter when ready to stop: ", S$
PRINT : PRINT "Timer is now: "; TIMER;
finish = INT(TIMER + .5)
IF begin > finish THEN 'if begin before midnight & finish after
    finish = finish + 86400 'total number of seconds in 24 hours
END IF
PRINT " ="; finish; " rounded to nearest second."
interval = INT((finish - begin) + .5)
CALL clocktime
sec = finish - begin
min = 0
IF sec >= 60 THEN
    DO
      min = min + 1
      sec = sec - 60
    LOOP UNTIL sec
END IF
hour = 0
IF min >= 60 THEN
    DO
      hour = hour + 1
      min = min - 60
    LOOP UNTIL min
END IF
PRINT : PRINT "Interval was"; interval; "seconds."
PRINT "The time passed was"; hour; "hours,"; min; "minutes, and"; sec; "seconds."
END

SUB clocktime
mytime$ = TIME$
hr$ = LEFT$(mytime$, 2)
hour = VAL(hr$)
IF hour = 0 THEN hour = 12 'midnight
IF hour < = 12 THEN
    mer$ = "AM"
ELSE
    hour = hour - 12
    mer$ = "PM"
END IF
hr$ = STR$(hour)
minsec$ = RIGHT$(mytime$, 6)
clock$ = hr$ + minsec$ + " " + mer$
PRINT "Clock time is: "; clock$
END SUB

Posted on Feb 25, 2011, 8:02 PM

Respond to this message   

Return to Index


Help needed

by (no login)

I want a program using loop statements which can find out maximum, minimum and the average of 5 given no.s... Please help me!

Thank you
HC

Posted on Feb 25, 2011, 6:35 AM

Respond to this message   

Return to Index


* Sounds like homework. Post your code so far...

by (Login burger2227)
R

We won't do homework FOR YOU!

Posted on Feb 25, 2011, 8:10 AM

Respond to this message   

Return to Index


One possible approach:

by Solitaire (Login Solitaire1)
S

The following algorithm assumes the user will be inputting the numbers. If you have a prepared list of numbers, you need a different approach.

1. Set the minimum to the highest possible number and the maximum to the lowest.
2. Start a FOR loop to repeat 5 times.
3. Get the number.
4. Use two IF blocks to compare the number to the minimum and maximum and reassign those values as needed.
5. Total all the numbers entered.
6. After the loop ends, divide the total by 5 to get the average.

Note: No one here will write the code for you. You must make an effort to write the program yourself and post the code you have so far. Then ask for help with the specific part of the program that's giving you trouble.

Posted on Feb 25, 2011, 9:12 AM

Respond to this message   

Return to Index


This is not my homework...

by HC (no login)

My friend gave me a challenge to do this... I tried it but I got a very long code which could find only the max of it... I thought that I could get some help here... I will post the code after some time...

Posted on Feb 25, 2011, 5:49 PM

Respond to this message   

Return to Index


and

by HC (no login)

Which statement should I use to find max and min? I am not too good with QBASIC... I am now learning loops... Here's the code->

INPUT "ENTER NO.S" ; A, B, C, D, E
IF A>B THEN GOTO 10 ELSE
GOTO 100
10 IF A>C THEN GOTO 30 ELSE
GOTO 100
20 IF A>D THEN GOTO 30 ELSE
GOTO 100
30 IF A>E THEN PRINT A; "IS GREATEST" ELSE
GOTO 100
END
100 IF B>C THEN GOTO 110 ELSE
GOTO 200
110 IF B>D THEN GOTO 120 ELSE
GOTO 200
120 IF B>E THEN PRINT B; "IS GREATEST" ELSE
GOTO 200
END
200 IF C>A THEN GOTO 210 ELSE
GOTO 300
210 IF C>B THEN GOTO 220 ELSE
GOTO 300
220 IF C>D THEN GOTO 230 ELSE
GOTO 300
230 IF C>E THEN PRINT C; "IS GREATEST"
END
300 .............................................................................AND SO ON!!!

Posted on Feb 25, 2011, 6:00 PM

Respond to this message   

Return to Index


What ugly code!

by Solitaire (Login Solitaire1)
S

Forgive me for being blunt, but all those GOTOs are enough to make me puke. I just don't have the stomach for it.

Please get rid of those GOTOs and learn to use a proper loop. I won't even look at that code until you clean it up.


Here is an example of a FOR-NEXT loop to get you started. This will get the average of 5 numbers the user enters, but it doesn't get the maximum or minimum values. I'll let you try to figure that out for yourself. There are several ways of doing it. Give it a try and post your code WITHOUT ANY GOTOS!!!

FOR x = 1 to 5
   INPUT "Enter a number:  ", snum$
   num = VAL(snum$)
   total = total + num
NEXT x
average = total / 5
PRINT average

Posted on Feb 25, 2011, 6:47 PM

Respond to this message   

Return to Index


LOL...

by (Login burger2227)
R

INPUT "How many numbers do you want to average"; nm$
n = VAL(nm$)
FOR x = 1 to n
INPUT "Enter a number: ", snum$
num = VAL(snum$)
IF num > highest THEN highest = num 'highest = 0 when first used in program
total = total + num
NEXT x
average = total / n
PRINT average, highest

Posted on Feb 25, 2011, 8:13 PM

Respond to this message   

Return to Index


well

by HC (no login)

dude... i get the average thing... but max and min is puzzling me...

Posted on Feb 26, 2011, 1:13 AM

Respond to this message   

Return to Index


AND ALSO

by hc (no login)

i m a beginner in QBASIC... not a pro

Posted on Feb 26, 2011, 1:22 AM

Respond to this message   

Return to Index


...

by HC (no login)

I know I am troubling you all... and I am sorry for that... how to get the minimum??? I get what clippy said... but how to find min??? :(

Posted on Feb 26, 2011, 1:30 AM

Respond to this message   

Return to Index


You need to get a base value for max and min.

by Solitaire (Login Solitaire1)
S

The following program has all the requirements. I used hi and lo instead of max and min. It uses the first number that is input for the base value, and compares hi and lo against that value in all the subsequent repeats. This will work with any number, even a negative one. Clippy's version only works with a max of 0 as the base value, and doesn't get a value for the minimum. That's because the user's smallest number can be more or less than 0. By comparing all input numbers to the first one, you have a legitimate starting value.

Alternatively, you can get a "primed" value before starting the loop by getting the user input of the first number, and then looping from 2 to 5. But then you need to assign that number to hi, lo, and tot before starting the loop. This version is shorter.

You don't need to restrict the program to 5 repeats. You can get the user's input for the number of repeats and use that variable after the TO in the FOR-NEXT loop. (That was how Clippy did it.)

Note I started out by declaring the variables by type.

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

CLS
DIM snum AS STRING, avg AS DOUBLE
DIM num AS INTEGER, hi AS INTEGER, lo AS INTEGER, tot AS INTEGER
FOR x = 1 TO 5
    INPUT "Enter a number:   ", snum$
    num = VAL(snum$)
    IF x = 1 THEN
        hi = num
        lo = num
    END IF
    tot = tot + num
    IF num > hi THEN hi = num
    IF num < lo THEN lo = num
NEXT x
avg = tot / 5
PRINT "The average is "; avg
PRINT "The minimum is "; lo
PRINT "The maximum is "; hi
END

Posted on Feb 26, 2011, 7:34 AM

Respond to this message   

Return to Index


* The less than symbol < won't display in posts :-P

by (Login burger2227)
R

Posted on Feb 26, 2011, 8:43 AM

Respond to this message   

Return to Index


whoa

by HC (no login)

I could never do that! You and Clippy are champs! I know I am troublesome... but what does the DIM do?
Thanks... cuz I know you can answer it... ;D

Posted on Feb 26, 2011, 11:39 PM

Respond to this message   

Return to Index


* DIM defines the variable type

by (Login burger2227)
R

Posted on Feb 27, 2011, 12:36 AM

Respond to this message   

Return to Index


Variables must be defined by type in most languages.

by Solitaire (Login Solitaire1)
S

The DIM stands for "Dimension" meaning size. It reserves a certain number of bytes in memory depending on the type of data. For example, the INTEGER type uses 2 bytes; LONG and SINGLE use 4 bytes; and DOUBLE uses 8 bytes of memory. Number types use stack memory but STRING uses heap memory, consuming 1 byte for each character plus overhead.

QBasic allows variables to be used without declaring them first by type. Instead of using DIM, it is also possible to add a type suffix to a variable name. For example, INTEGER variables may end with %, SINGLE ends with !, LONG ends with &, and DOUBLE ends with #. Numbers are given type SINGLE (4 bytes) by default, unless you declare them otherwise or use the suffix. But STRING variables require the $ suffix unless you declare them with DIM. You may continue using the suffix after a variable name whether or not you DIM it first, but the suffix may not be used with the DIM statement itself.

Other languages (expecially C and C++) require type declaration before the variables can be assigned, so it's a good idea to get used to using it if you are serious about continuing with the study of programming.

Posted on Feb 27, 2011, 1:11 AM

Respond to this message   

Return to Index


Thanks!

by HC (no login)

Okay... I understood :)
Thanks to both of you and clippy

Posted on Feb 27, 2011, 4:45 PM

Respond to this message   

Return to Index


THIS PLACE IS A MESS! SERVER ERRORS ALL DAY!

by (Login burger2227)
R

And I am STILL being asked to fix some pages when I post!

Who do they have "fixing" the place now? A MONKEY?

Posted on Feb 22, 2011, 5:28 PM

Respond to this message   

Return to Index


a little help with a few problems?

by Zack (no login)

I have a few problems that I need help with.

1) Is there a way to DRAW using SCREEN 0?

2) How do you clear the previously pressed keys? I am using _KEYHIT to navigate through my program now, but some things need an INPUT, unless there is a way to get it to recognize when your press 11 or 34 or whatever. Anyway, if to get to the INPUT you have to go through 4 menus. You press 1, 5, 2, 1 for the different menus to navigate there and then it asks you to INPUT. Once you get there, there is already "1521" on the INPUT is there a way to clear this data before it asks for your INPUT?

Thanks for any help!
-Zack

Posted on Feb 20, 2011, 4:42 PM

Respond to this message   

Return to Index


Re: a little help with a few problems?

by (Login MCalkins)
Moderator

>1) Is there a way to DRAW using SCREEN 0?

I don't think so.

2) How do you clear the previously pressed keys?

I don't use QB64, but in qbasic:

do while len(inkey$): loop

would do it.

This _KEYHIT of which you speak: does it not remove the keystrokes from the buffer as it reads them? If not, why don't you use a function that does?

Regards,
Michael


Posted on Feb 20, 2011, 5:27 PM

Respond to this message   

Return to Index


Use INKEY$ WITH _KEYHIT to clear in a loop...

by (Login burger2227)
R

DO: K$ = INKEY$
x = _KEYHIT
LOOP UNTIL x = 27

PRINT x

INPUT "Enter:", nam$

Ted

Posted on Feb 20, 2011, 5:50 PM

Respond to this message   

Return to Index


Re: Is there a way to draw using SCREEN 0...

by (Login qb432l)
Mod

The only way to "draw" in SCREEN 0 is to use ASCII characters. In QBasic there is an extended character set which includes line and texture characters. Some amazing things have been done with these, but they're really just meant for drawing boxes and other simple shapes.

If you're interested, open QBasic Help (not available in QB64), click Contents, and then select ASCII Character Codes. Press Page Down for the extended set.

If you don't have QBasic, copy and run this code in QB64:

CLS
FOR n = 176 TO 223
PRINT n; CHR$(n),
NEXT n

'-Bob

Posted on Feb 20, 2011, 8:31 PM

Respond to this message   

Return to Index


Thanks so much, but one more thing

by Zack (no login)

Thank you so much! Thanks for the idea of using INKEY$ along with _KEYHIT, it works really well. Also, I played around with it and made the things i wanted to DRAW out of those characters.

But one thing I forgot to ask before, that I probably should have learned a long time ago: How do you make a integer variable long? Like if i want it to display a number larger than 1 billion, it writes it in scientific notation. How can I make it so it displays the entire number?

Thanks for your continued help
~Zack

Posted on Feb 21, 2011, 7:16 PM

Respond to this message   

Return to Index


Declare your variable as a LONG instead of INTEGER

by Solitaire (Login Solitaire1)
S

Instead of: DIM myintvariable AS INTEGER

Do this: DIM mylngvariable AS LONG

If you use a suffix instead of a type declaration, use an ampersand & instead of a percent % symbol.



Posted on Feb 21, 2011, 10:45 PM

Respond to this message   

Return to Index


You can use _INTEGER64 in QB64 too.

by (Login burger2227)
R

Also try _UNSIGNED INTEGER64 to get up to 18,446,744,073,709,551,615

Posted on Feb 22, 2011, 12:24 AM

Respond to this message   

Return to Index


Re: Thanks so much, but one more thing :P

by Zack (no login)

I ended up using the & type declaration because I had no need for the variable to be that large, but I know now how to if the need ever arises.

Also, I keep forgetting what I wanted to ask you guys. I had a list of things I needed help with, but then when I go to actually ask, I always forget. Anyway, I remembered the two things I was forgetting.

1) How do you double the size of an image using _PUT.

2) Also, is there a way to convert a string into an integer variable? I am trying to make a little alarm thing where you can set in how long you want it to go off. Then it writes a file for the current time and date. Then I want to add the time that they want to elapse before it rings to the original time and date, but I cant seem to figure out how to convert it. If there is an easier way to do what I am trying to do please tell me.

Thanks so much
~Zack

Posted on Feb 22, 2011, 2:39 PM

Respond to this message   

Return to Index


Use VAL() to convert a string to a number.

by Solitaire (Login Solitaire1)
S

The VAL() function will convert a numeric string into a number. It will ignore any spaces and stop at the first non-numeric character. If the string is non-numeric, VAL will return 0. For example:

DIM snum AS STRING, mynum AS DOUBLE
INPUT "Enter a number: ", snum$
mynum = VAL(snum$)

If the user enters: 1234qwst
VAL will return 1234

If the user enters: qrst1234
VAL will return 0.

The VAL function returns a type DOUBLE number, so it will work with decimal points. Of course, it will convert a string into a whole number, if the input does not include a fraction. If you require an integer and the input includes a dot followed by more digits, then you need to add more code. You could use the CINT() function to convert a fractional number into an integer.

Posted on Feb 22, 2011, 3:43 PM

Respond to this message   

Return to Index


Re: How do you double the size of an image using _PUT...

by (Login qb432l)
Mod

Assuming you're referring to QB64's command, _PUTIMAGE, here's the link to the Wiki:

http://qb64.net/wiki/index.php?title=PUTIMAGE

If you're referring to QBasic's PUT statement, there is no way to do it using the statement itself, you would have to physically enlarge the image and then GET it in it's enlarged form. I doubt however, that you're referring to QBasic.

I'm not really familiar with _PUTIMAGE, but I know that the second set of x/y coordinates (following _PUTIMAGE) can be used to resize the image.

-Bob

Posted on Feb 22, 2011, 9:57 PM

Respond to this message   

Return to Index


Like this...

by Galleon (no login)

f$ = "s2_poster_1.jpg"
i = _LOADIMAGE(f$, 32)
IF i = -1 THEN PRINT "You don't have the file '" + f$ + "'": END
i2 = _NEWIMAGE(_WIDTH(i) * 2, _HEIGHT(i) * 2, 32)
_PUTIMAGE , i, i2
SCREEN i2 'display it (optional)

Posted on Feb 24, 2011, 11:02 AM

Respond to this message   

Return to Index


Thanls guys

by Zack (no login)

Thank you for pointing out the VAL() command to me, it is just what i needed.

And yes, I meant _PUTIMAGE sorry about that. But I couldn't get the way it does it in the example to work, but the way Galleon says worked fine.

Thanks.

Posted on Feb 25, 2011, 7:16 PM

Respond to this message   

Return to Index


Parallel port issues

by nmcmill (Login ratwouldbeking)

Hello all,

I am a researcher who uses QBasic essentially as an end user, with simple programming for various archaic pieces of hardware (Skinnerian operant chambers, if anyone's interested). I'm having some problems getting some equipment to respond to QBasic commands over the parallel port (Windows 98).

Our department wiring expert has put together a circuit board for an operant box that features two lights (soldered to independent pins, 8 and 9), an infrared beam (input pin 10), and a pump for delivering sucrose (output pin 2). The parallel port is connected to LPT1 (confirmed to be at hex 0378). To test, I use the following brief code, but the box is completely nonresponsive (the lights remain on and the hopper remains active).

> OUT $H378, 0

This remains the case if I use other numbers than zero, all the bits apparently remain high.

Anyone here have any idea what glaring stupidity I have committed in my coding assumptions, or must this be an issue with the hardware? Thanks for any pointers!

Cheers!

Posted on Feb 17, 2011, 9:37 AM

Respond to this message   

Return to Index


Pin 10 is the status

by (Login burger2227)
R

All pins will be high when first read so set to zero. Pins 8 and 9 are the highest bits of the port value sent. So you need values of 128 for 9 and 64 for 8. Use the ground pins to complete the circuits.

[linked image]

Don't load the port down! It is only 5 volts with low current capabilities. Use optoisolators and a separate(isolated) power supply to drive other devices!

Ted

Posted on Feb 17, 2011, 5:56 PM

Respond to this message   

Return to Index


*Replace the $ sign with an &

by (Login Mikrondel)
R

Posted on Feb 19, 2011, 8:23 PM

Respond to this message   

Return to Index


* Good catch Artie I missed that one...:-)

by (Login burger2227)
R

Posted on Feb 19, 2011, 10:31 PM

Respond to this message   

Return to Index


QBasic under XP - screen colors corrupted.

by (no login)

Suddenly, the QBasic edit and output screen colors have become corrupted when running QBasic under XP in a window and from a shortcut. (Same applies to the associated EDIT.COM.) Strangely, colors are OK when switched to full screen or if running from the command prompt.
Magenta, white and bright green all print as black. This makes the window unuseable. help would be much appreciated.

Posted on Feb 12, 2011, 8:22 AM

Respond to this message   

Return to Index


Try this

by (Login burger2227)
R

Try this video fix for XP only:

http://dl.dropbox.com/u/8440706/XPvideoFix.zip


Also you may want to copy Autoexec.NT from the C:\WINDOWS\REPAIR folder to the C:\WINDOWS\SYSTEM32 folder. Sometimes that file is corrupted and Qbasic will not run at all.

Try using QB64 to compile your Qbasic programs.

Ted

Posted on Feb 12, 2011, 11:36 AM

Respond to this message   

Return to Index


QBasic screen colors

by (Login slowneutron)

Have found how to correct the problem - posted under QB Tricks & Techniques: "Proceedure for changing QBasic screen colors under Windows XP"

Posted on Feb 13, 2011, 9:31 AM

Respond to this message   

Return to Index


*Yes, I'm upgrading the QB64 website. Refer to my post in the QB64 N54 forum here.

by Galleon (no login)

Posted on Feb 11, 2011, 10:27 PM

Respond to this message   

Return to Index


Full screen mode in Windows 7 or Vista...

by Solitaire (Login Solitaire1)
S

The following excerpt appeared in a Windows 7 newsletter. It also describes how to get the command prompt to fill the screen, although it's not a true full screen. The full story is at this link:

http://www.thewindowsclub.com/full-screen-command-prompt-in-windows-7#more-23706

The article doesn't explain how to install the device drivers or where to get them from. (Who needs Aero anyway!?!) Maybe someone here can find out.

=============================================================================
In Windows 7 or Windows Vista, if you try to maximize the command prompt window, it will expand only to cover around half the screen. You will not be even able to drag and increase its size!

In Windows XP, after you open a command prompt, you could run the cmd in full-screen mode by clicking Alt+Enter, but if you try this in Windows Vista and later, you will get the following message: This system does not support fullscreen mode.

This happens because in Windows 7 and Windows Vista, the device drivers do not support running all of the DOS video modes. The device drivers are based on the Windows Display Driver Model (WDDM).

You may be able to work around this problem by installing the Microsoft Windows XP version of the video drivers for your video adapter. But by doing this, while you may be able to to run full screen DOS programs, you may lose the ability to run Aero!

Source:http://www.thewindowsclub.com/full-screen-command-prompt-in-windows-7#ixzz1DiFXdsej

Posted on Feb 11, 2011, 7:51 PM

Respond to this message   

Return to Index


*Thanks, Solitaire -- although I'm getting used to losing the old stuff, bit by bit.

by (Login qb432l)
Mod

*

Posted on Feb 11, 2011, 8:58 PM

Respond to this message   

Return to Index


Qbasic full screen mode in Windows 7

by (no login)

Thank you so much.

Posted on Oct 29, 2013, 6:48 AM

Respond to this message   

Return to Index


Anyway to time things in sub 1 second intervals?

by (no login)

I searched but couldn't find anything definitive.

Are whole seconds the smallest time increment TIMER and TIME$ can be directly used for? Or is there some other command, or some variation of those commands that will return fractions of seconds as counted on the system clock?

I'm making a program to calibrate a pendulum clock, but it takes a while for the pendulum to drift off by more than a whole second. If there was a way to get tenths, hundredths, or milliseconds from the system clock, it would make for easier programming.

I can always try measuring loop cycles and get a rough approximation of fractions of a second, but easier is better, if it exists :) .

Thanks,
Lou

Posted on Feb 6, 2011, 7:41 PM

Respond to this message   

Return to Index


What does TIMER actually return?

by Loudhvx (no login)

Sorry, I'm not on a work computer, so I couldn't try it, but also couldn't find documentation on what TIMER actually returns. I find that some say it's the number of seconds since midnight, but I guess I assumed it was whole (integer) seconds.

Based on some tutorials, I gather it is in some other format which includes decimal fractions of a second. Is that correct? If so, then I guess that's all I need. I think I can work with 1/18ths of a second.

Thanks,
Lou

Posted on Feb 6, 2011, 9:13 PM

Respond to this message   

Return to Index


You should check for Midnite in TIMER delays...

by (Login burger2227)
R

At midnight TIMER goes to 0 to restart the second count. So a loop "could" keep looping forever if the delay value added makes the final TIMER value greater than 86399.

Delay .5 'calls SUB for 1/2 second

SUB Delay (Dlay!)
start = TIMER
DO WHILE start + Dlay! >= TIMER
IF start > TIMER THEN start = start - 86400
LOOP
END SUB

Ted

Posted on Feb 7, 2011, 1:47 PM

Respond to this message   

Return to Index


*Thanks. It's a short-run program, but will keep in mind.

by Loudhvx (no login)

Posted on Feb 8, 2011, 4:17 PM

Respond to this message   

Return to Index


MAYBE ...

by OPRESION (no login)

http://qbasicnews.com/abc/showpacket.php?packet=DATETIME.ABC

Posted on Feb 6, 2011, 10:36 PM

Respond to this message   

Return to Index


*Resolved. Can use TIMER. Thanks!

by Loudhvx (no login)

Posted on Feb 7, 2011, 1:09 AM

Respond to this message   

Return to Index


A few suggestions

by (Login Mikrondel)
R

You're right about TIMER. Number of seconds since last midnight. Accurate to approximately 1/18.2 of a second.

If you want more accurate timing you can read the PIT counter that gets updated about a million times a second, but this is tricky. I can dig up some details if you want.

There is also the screen refresh interval which is usually 60Hz. I don't think this method is going to suit your application.

QB64 allows more precise timing with _TIMER and other things. I would suggest you look into this unless you are using DOS.

Posted on Feb 19, 2011, 8:38 PM

Respond to this message   

Return to Index


*Thanks. Found the PIT details on a tutorial.

by Lou (no login)

Posted on Feb 21, 2011, 11:32 AM

Respond to this message   

Return to Index


Disk Read/Write Sectors QB7 or QB4.1

by Dave (no login)

Hello everyone. I am wondering what commands to use to read and write to a HDD sector really simply. If possible could someone make a function called writesector(address,data) and data=readsector(address). Thanks im also wondering if its possible to be able to directly access the pins of the IDE port but that is optional

Posted on Feb 6, 2011, 5:27 AM

Respond to this message   

Return to Index


MAYBE ...

by OPRESION (no login)

http://qbasicnews.com/abc/showpacket.php?packet=DISK.ABC

Posted on Feb 6, 2011, 10:40 PM

Respond to this message   

Return to Index


I did not find any suitable code

by Dave (no login)

I did not find any suitable code on that website. I tried the boot sector example but it did not work on either qb 4.5 or QBX 7.

Posted on Feb 7, 2011, 3:01 PM

Respond to this message   

Return to Index


read sector demo

by (Login MCalkins)
Moderator

http://fornax.elf.stuba.sk/SUPERMAN/SYSTEMS/DOS/advdos.txt

see int 0x25 and int 0x26 functions in the above file. You might also look at chapter 10.

I wrote a read disk demo, but it doesn't work in NTVDM. It doesn't seem to work in DOSBox either, at least the version I've got. I took it to my old Win 98se computer, and the only drive it would work on was my USB flash drive.

I wrote the buffer dump portion in a hurry, but it seems to work.

I'll let you figure out how to write a sector. (this is dangerous, of course).

Why do you need raw sector access? I assume you are using DOS or Win 9x instead of NTVDM?

Regards,
Michael

-------- readdisk.asm

;public domain, feb 2011, michael calkins

cpu 386
org 0x0

_readdisk:
push bp
mov bp,sp
pusha
mov bx,[bp+0x8]
mov ds,bx
mov bx,[bp+0x6]
mov al,[bx+0xa]
mov cx,0xffff
int 0x25 ;destroys all except segment registers. SP needs to have 2 added
jc .err

add sp,0x2
mov bp,sp
add bp,0x10
mov bx,[bp+0x6]
xor dx,dx
mov [bx+0xc],dx
popa
pop bp
retf 0x4

.err:
add sp,0x2
mov bp,sp
add bp,0x10
mov bx,[bp+0x6]
mov dx,0xffff
mov [bx+0xc],dx
mov [bx+0xe],ax
popa
pop bp
retf 0x4


-------- readdisk.bas

'public domain, feb 2011, michael calkins
DEFINT A-Z
TYPE readdiskblockt
sector AS LONG
numsectors AS INTEGER
bufferoffs AS INTEGER
buffersegm AS INTEGER
drivenum AS INTEGER 'although an integer, only the low byte is used.
er AS INTEGER
errorcode AS INTEGER
END TYPE

DIM readdiskblock AS readdiskblockt
DIM buffer AS STRING * 512
DIM code AS STRING * 72, t AS STRING, i, c, l, a

t = "5589E5608B5E088EDB8B5E068A470AB9FFFFCD25721781C4020089E581C51000"
t = t + "8B5E0631D289570C615DCA040081C4020089E581C510008B5E06BAFFFF89570C"
t = t + "89470E615DCA0400"
FOR i = 0 TO 71
MID$(code, i + 1, 1) = CHR$(VAL("&h" + MID$(t, (i * 2) + 1, 2)))
NEXT i

COLOR 7, 0: CLS

readdiskblock.sector = 0
readdiskblock.numsectors = 1
readdiskblock.drivenum = 2
readdiskblock.buffersegm = VARSEG(buffer)
readdiskblock.bufferoffs = VARPTR(buffer)

DEF SEG = VARSEG(code)
CALL absolute(SEG readdiskblock, VARPTR(code))

IF readdiskblock.er THEN
PRINT "error code: 0x"; HEX$(readdiskblock.errorcode)
ELSE
WIDTH 80, 50
COLOR 7, 0: CLS : COLOR 3
FOR i = 0 TO 15
LOCATE 1, 6 + (i * 3): PRINT HEX$(i);
LOCATE 1, 65 + i: PRINT HEX$(i);
NEXT i
FOR i = 0 TO 31
t = HEX$(i)
IF LEN(t) < 2 THEN t = "0" + t
PRINT t; "0"
NEXT i
COLOR 7
DEF SEG = &HB800
FOR i = 0 TO 511
a = ASC(MID$(buffer, i + 1, 1))
t = HEX$(a)
IF LEN(t) < 2 THEN t = "0" + t
l = i \ 16
c = i MOD 16
LOCATE l + 2, (c * 3) + 5: PRINT t
POKE c * 2 + 128 + (160 * (l + 1)), a
NEXT i
SLEEP: DO UNTIL LEN(INKEY$): LOOP
WIDTH 80, 25: COLOR 7, 0: CLS
END IF
SYSTEM

Posted on Feb 7, 2011, 4:11 PM

Respond to this message   

Return to Index


Re: read sector demo

by Dave (no login)

I am unfortunately wanting to run this software on my Windows XP machine. Thanks for the demo i will try it out now. Is there a way to get it to work through windows XP or is the access prevention levels too high (like with controlling the parallel ports)

Posted on Feb 8, 2011, 1:25 PM

Respond to this message   

Return to Index


I think you're going to have a hard time doing it from NTVDM.

by (Login MCalkins)
Moderator

First, I don't have much knowledge or experience with parallel ports on any OS, so I'll skip that.

As far as the sector access, I don't think it's a matter of access rights, I think it's a matter of the subsystem not implementing it.

The exact message is:

-----
16 bit MS-DOS Subsystem

Command Prompt - qbasic readdisk
An Application has attempted to directly access the hard disk, which cannot be supported. This may cause the application to function incorrectly. Choose 'Close' to terminate the application.

Close Ignore
-----

I know it is possible to do it, because Sysinternals RootkitRevealer does it. (A number of Sysinternals programs install drivers, but from what I am reading elsewhere, I think an application can do it without a special driver.)

Here is a paragraph from Windows Internals, 4th edition, chapter 10, Storage Management. Typing accuracy not guaranteed.

-----
As you saw in Chapter 3, the Windows API is unaware of the Windows object manager namespace. Windows reserves two different namespace subdirectories to use, one of which is the \Global?? (\?? on Windows 2000) subdirectory. (The other is the \BaseNamedObjects subdirectory, which is covered in Chapter 3.) In this subdirectory, Windows makes available device objects that Windows applications interact with-including COM and parallel ports-as well as disks. Because disk objects actually reside in other subdirectories, Windows uses symbolic links to connect names under \Global?? with objects located elsewhere in the namespace. For each physical disk on a system, the I/O manager creates a \Global??\PhysicalDriveX link that points to \Device\HarddiskX\Partition0. (Numbers, starting from 0, replace X.) Windows applications that directly interact with the sectors on a disk open the disk by calling the Windows CreateFile function and specifying the name \\.\PhysicalDriveX (in which X is the disk number) as a parameter. The Windows application layer converts the name to \Global??\PhysicalDriveX before handing the name to the Windows object manager.
-----

Here is the MSDN article for CreateFile function:

http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx

A Google search found this:

http://www.codeguru.com/cpp/w-p/system/misc/article.php/c5765

Regards,
Michael

Posted on Feb 8, 2011, 2:23 PM

Respond to this message   

Return to Index


* You can access the LPT with Port Talk in XP

by (Login burger2227)
R

Posted on Feb 8, 2011, 4:24 PM

Respond to this message   

Return to Index

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