r/QBeducation • • Nov 08 '24

There are more seconds in a day, than there are pixels in SCREEN 13

0 Upvotes

Just thought I'd share a QFact (quick fact) about math, in case anybody attempts to translate every second of the day into a SCREEN 13 pixel position.

(60 x 60 x 24) = 86,400

(320 x 200) = 64,000

So, we're 22,000 pixels short.

But if you split the SECONDS IN THE DAY to AM, and PM, there'd be 43,200 pixels each.

86,400 ÷ 2 = 43,200

If you try to divide 64,000 (SCREEN 13 pixels) by 43200 (AM or PM of seconds after midnight), you'll get 1.48 (48 repeated)

here's the formula for splitting AM and PM:

(TIMER seconds) MOD 43000

and if one wants to differentiate between AM, and PM, then....

m$(0) = "AM"
m$(1) = "PM"
mm = TIMER \ 43200
PRINT m$(mm)

Just thought I'd give a HEADS UP in case anybody gets tempted to translate each pixel of SCREEN 13 into each second of the day, so I guess there's another reason to split a 24 hour clock into AM and PM.

now, here's the way we convert TIMER into a clock display:

CLS
DO
sec = TIMER MOD 60
min = (TIMER \ 60) MOD 60
hour = (TIMER \ 60 \ 60) MOD 24
LOCATE 1, 1
PRINT RIGHT$("0" + LTRIM$(STR$(hour)), 2); ":";
PRINT RIGHT$("0" + LTRIM$(STR$(min)), 2); ":";
PRINT RIGHT$("0" + LTRIM$(STR$(sec)), 2)
LOOP UNTIL INKEY$ <> ""

Although this one converts it to military time

in military time, the phrase "6 PM", would be translated into "18 hundred hours", although it's more like 18 hundred minutes to some.

Just thought I'd type simple code for beginners to understand how time works in case somebody wants to create a clock program.

but it's important to know the pixel metrics in case we choose a screen mode to use a "pixel clock" on.

I'll explain the rest later.


r/QBeducation • • Nov 08 '24

How to detect invalid characters in an INPUT string

1 Upvotes
FOR c = 0 TO 255
SELECT CASE c   
CASE 48 TO 56 ' skips the numeric digits            
CASE ELSE       
z$ = z$ + CHR$(c) ' registers the invalid characters
END SELECT      
NEXT            
DO              
INPUT a$        
IF a$ = "" THEN END
s = 1        
FOR c = 1 TO LEN(a$)
IF INSTR(z$, MID$(a$, c, 1)) THEN s = 0 ' checks for valid characters
NEXT
IF s = 1 THEN PRINT a$
IF s = 0 THEN PRINT "all characters must be numeric digits."
LOOP

r/QBeducation • • Sep 12 '24

An abridged list of reasons to use selected Microsoft BASIC variants which support some of QBasic's commands...

3 Upvotes
variantreasonside note
GW-BASICif you want instant readouts with commandsGW-BASIC is actually more like SlowBasic than QuickBasic, but many commands which we think are "exclusive" to Q(uick)Basic acctually originated here, and it's more of a LINE NUMBER program than a text editor like QuickBASIC would be.
BASICAif you're curious about historical Microsoft BASIC variants on IBM PC, and for similar reasons why one could use GW-BASICit's requirements for the BASIC ROM on the IBM PC limit it's usefulness on other machines.
QuickBasicif you want to type in a long list of code, and want to immediately test the programQB64 has time delays with code testing, which is why running QuickBasic on DOSBox is recommended.
PDS, aka "QuickBASIC 7.1"if one wants to try out the advanced functions that QB 4.5 lacks.PDS stands for Professional Development System
QBasicfor similar reasons why one should run QuickBasicalthough QBasic does run slower, and doesn't produce EXE files.
Visual BASIC for DOSif one wants a more GUI-like interface for testing commands and functions which QB would use.well, it's also a curious piece of history.
QB64for those who prefer a native Win32 or Win64 EXE to run on Windows 7 and later, in addition to advanced functions that QB variants for DOS would lack.although it has issues with startup delays. But, unlike the other variants, it's not an official Microsoft product, but rather, a fan developed remake of QB made so one doesn't have to run DOSBox when using Windows.

Just thought I'd give tips on which QB variants to use if certain situations call for situations which depend on some amenities of them.


r/QBeducation • • Dec 01 '23

The POKE command can also be used to change pixels in SCREEN 13, also works in QB64.

1 Upvotes
'
' proof that the POKE command also works in QB64 for SCREEN 13
' graphics too! in addition to QBasic and QuickBasic.
'
SCREEN 13
FOR y% = 0 TO 199
    t = TIMER
    WHILE t = TIMER
    WEND
    FOR x% = 0 TO 319
        DEF SEG = &HA000 'Change the moemory SEGMENT
        POKE (x% + (y% * 320&)), 15 'POKE the colour into the memory OFFSET
    NEXT
NEXT

r/QBeducation • • Feb 12 '24

Fibonacci sequence code with some helpful coding tips

2 Upvotes
DIM SHARED a AS LONG ' enables variables to also be used
DIM SHARED b AS LONG ' in FUNCTION sections too.
'
'
'  How the Fibonacci sequence works.
'
' can be run in QuickBasic, QBasic and QB64.
'
a = 1
WHILE INSTR(STR$(c), "E") = 0
    a = a + b
    PRINT a;
    '
    b = b + a ' this is one way to explain why number 1
    '           occurs two times in a row in the
    '           Fibonacci sequence, it can alternate between
    '           variables which are the sum of each other.
    PRINT b;
WEND
' an occurrence of letter E in really big numbers
' is a sign that the number is too lange to be seen
' in it's exact form, which is why it was used as a
' "signal" to break the loop using INSTR.
'
'
PRINT c; 'thought we'd include the number with "E" in it
PRINT '   as the final number to be shown.
PRINT
PRINT "you can see here that the Fibonacci sequence"
PRINT "can easily exceed one billion after a brief"
PRINT "chain of adding numbers."
'
FUNCTION c
IF a > b THEN c = a ' a function has been added to
IF b > a THEN c = b ' automatically sense which
'                alternating component is greater
END FUNCTION
'
' what was originally meant to be Fibonacci sequence
' code has turned into an opportunity to educate some
' QB users how some of these statements work.

r/QBeducation • • Jul 14 '24

Qb training

2 Upvotes

Take your game to the next level with a holistic approach to Qb training coachup.com/me/sandwolfat3


r/QBeducation • • May 09 '22

r/QBeducation Lounge

1 Upvotes

A place for members of r/QBeducation to chat with each other


r/QBeducation • • May 09 '22

QB64's ASCII character chart, a helpful tool for making ASCII art, and one can learn some ASCII codes using this.

Post image
1 Upvotes

r/QBeducation • • May 09 '22

EDUCATIONAL CHILDREN'S SONG: 🚌 The Wheels On The Bus 🚌 [USING THE PLAY COMMAND] its also a song about SCHOOL BUSES, vehicles that transport students to educational places such as school.

Thumbnail self.qbmusic
1 Upvotes

r/QBeducation • • May 09 '22

QBasic Tutorial 25 - Sound And Music - QB64 - Ode To Joy - Beethoven

Thumbnail
youtube.com
1 Upvotes

r/QBeducation • • Sep 16 '23

🖥 GW-BASIC binary to decimal converter ported to BAM

Thumbnail
basicanywheremachine-news.blogspot.com
2 Upvotes

r/QBeducation • • May 09 '22

Joystick axis tester using all 63 EGA color values, learn how the joystick or gamepad works using this.

Thumbnail self.qbart
1 Upvotes

r/QBeducation • • Sep 09 '23

BASIC Anywhere Machine

2 Upvotes

You might find BASIC Anywhere Machine useful for education. It is a no install (in the traditional sense), integrated development environment for BASIC, decently compatible with GW-BASIC / QBASIC / QB64.

It is a single-HTML-file TiddlyWiki instance that runs in a web browser (offline as well as online), meant to be downloaded and stored wherever suits you best. Everything that you see when working in BASIC Anywhere Machine (everything that makes "BAM" work as an IDE and all BASIC programs) exist in the one HTML file.

As a browser-based BASIC, it does not have access to operating system services (for example: the file system); BAM has access to the services provided by the web browser.

Please, check out the following (BASICAnywhereMachine reddit posts) and see if BAM is suitable for use cases in Education:


r/QBeducation • • Jun 25 '23

Code tables for the common typographical characters

1 Upvotes

Thought I'd share some code tables to educate QBASIC programmers on more advanced uses of them.

Here's some code tables of the basic text characters:

numeric digits:

numeric digitCardinal numeralvalue variable digitSTRING entry (includes INKEY$ as an example)ASCII codeINP(&H60) keyboard scan code
0zero0"0"4811
1one1"1"492
2two2"2"503
3three3"3"514
4four4"4"525
5five5"5"536
6six6"6"547
7seven7"7"558
8eight8"8"569
9nine9"9"5710

letters of the alphabet:

alphabetical letterlowercase variantnth positionUPPERCASE ASCII codelowercase ASCII codeINP(&H60) KEY DOWNINP(&H60) KEY UP
Aa1659730158
Bb2669848176
Cc3679946174
Dd46810032160
Ee56910118146
Ff67010233161
Gg77110334162
Hh87210435163
Ii97310523151
Jj107410636164
Kk117510737165
Ll127610838166
Mm137710950178
Nn147811049177
Oo157911124152
Pp168011225153
Qq178111316144
Rr188211419147
Ss198311531159
Tt208411620148
Uu218511722150
Vv228611847175
Ww238711917145
Xx248812045173
Yy258912121149
Zz269012244172

just thought I'd cover the BASICs, get it? BASIC? QBASIC


r/QBeducation • • May 12 '22

QB64's ASCII character chart, learn some ASCII codes from this part of QB64.

Post image
2 Upvotes

r/QBeducation • • May 10 '22

[Wikibooks] QBasic: Subroutines and Functions

Thumbnail en.wikibooks.org
1 Upvotes

r/QBeducation • • May 10 '22

INP(&H60) Key press detector, an introductory demo on how to use INP(&H60) as a INKEY$ substitute.

Thumbnail self.qbprograms
1 Upvotes

r/QBeducation • • May 21 '22

A HELLO WORLD program that substitutes PRINT with a custom command that goes to a SUB using the PRINT command, education on how SUBs are created in QB64.

3 Upvotes
'
' make sure you have QB64 installed to run this.
'
'
'
' This program will educate you on how SUBs will be useful, but this is
' an introduction so we can at least have a general idea on how it works.
'
' below, is a phrase serving as a substitute to regular BASIC commands.
'
' this phrase will refer to a SUB for the program.
'
'
WriteText "Hello World"
'
' you can see here that PRINT has been replaced with WriteText.
'
' WriteText is the name of a SUB in this program, and also a custom command
' that serves as an entrance for the SUB below.
'
'
' When you create a sub, you can have all sorts of custom commands for the program.
' more info below
'
END ' program runtime ends here.
'
'
' ------------------------------------------------------------------------------------
' =============THE LINE THAT SEPARATES THE GENERAL PROGRAM FROM THE SUB===============
' ------------------------------------------------------------------------------------
'
'
SUB WriteText (a$)
'
' as you can see, WriteText is the name of the sub.
' while a$ is the entry that carries the text string to the other commands.
'
' below is the PRINT command that WriteText replaced for this demo
' in the above section.
'
PRINT a$
'
'
' In practice, this sub is not an absolute necessity.
'
' but this SUB section of the program was created to educate users on how
' the SUB feature of QB64 works, and how it kinda serves as a way to create
' your own custom commands that are exclusive to one program.
'
'
'
END SUB

r/QBeducation • • May 09 '22

Hot Cross Buns, a short song I learned in elementary school music class years ago, and only requires one line of code to be heard.

Thumbnail self.qbmusic
1 Upvotes

r/QBeducation • • May 22 '22

SCREEN 0 page tour, so you can understand how it's page function works, but some of you may have to learn other commands in this before you understand it fully.

Thumbnail self.qbprograms
1 Upvotes

r/QBeducation • • May 24 '22

HISTORY EDUCATION: a Wikipedia article about the PC speaker..... this would be the hardware speaker used for the PLAY command on GW-BASIC and QuickBasic and QBasic running on authentic old school IBM and clones running MS-DOS, while newer hardware emulates it via DOSBox and QB64.

Thumbnail
en.wikipedia.org
2 Upvotes

r/QBeducation • • May 21 '22

use of the DATA and READ command with a text string

1 Upvotes
'
' compatible with QuickBasic, QBasic, and QB64.
'
' with the DATA command, a sequence of data (as the command name implies)
' is stored into memory.
'
' take for example the text of all beginner programs.
'
DATA "Hello World"
'
'
READ a$ ' this command, READ will refer the DATA entry to a string variable.
'
' although in other cases, uses of the DATA command involving
' numeric values go to value variables that don't use $
'
PRINT a$ ' outputs the text string of the DATA that was READ.
'
'

r/QBeducation • • May 22 '22

A QB64 podcast about SCREEN modes

Thumbnail
youtube.com
1 Upvotes

r/QBeducation • • May 09 '22

INTRODUCTORY POST: how to create a border around SCREEN 0 TEXT MODE, with a brief message to us.

1 Upvotes
' ==== Introductory program for the /r/QBeducation subreddit ====
'
' made for QuickBasic, QBasic, and QB64
'
' an educational program on how to create a border in TEXT MODE.
'
' in this program, we'll show you how to create a border.
'
' so, this is educational as an example of something to create.
'
PRINT
COLOR 14
PRINT " initialzing..."
WHILE TIMER <> INT(TIMER)
WEND
SCREEN 0 ' 0 is a TEXT-ONLY mode that's also the default SCREEN for QB
CLS ' CLS clears the screen
WIDTH 80, 25
COLOR 14
LOCATE 3
PRINT "  Welcome to /r/QBeducation"
PRINT
PRINT "  This here is an example program that will educate users"
PRINT "  on how to form a border around the screen."
PRINT
PRINT "  While you see the border form, you can also read the BASIC"
PRINT "  code as a way to learn how to make a program like this."
PRINT
PRINT "  program begins in 9 seconds"
s = 9
DO
    t = INT(TIMER)
    WHILE t = INT(TIMER)
    WEND
    s = s - 1 ' counting down seconds
    LOCATE 11, 21
    PRINT LTRIM$(STR$(s));
    SOUND 100, .5
LOOP UNTIL s < 0
CLS
y = 1
DO
    COLOR 10 ' border is green, and color returns to this after text appears below.
    t = INT(TIMER * 6)
    WHILE t = INT(TIMER * 6) ' a time delay was added so messages could pop up
    WEND
    SELECT CASE d ' here you can see that the direction changes, and messages change too.
        CASE 0
            LOCATE 2, 1
            PRINT " " ' fixes a glitch
            MESSAGE$ = "The border goes right" ' message will change when direction changes.
            x = x + 1
            IF x = 79 THEN ' you can see that an X position
                d = d + 1 '  signals a change of direction
            END IF ' fill in a gap as the direction changes for double-character
        CASE 1 '                                        a change in program behavior.
            MESSAGE$ = "The border then goes downard"
            x = 79 ' border is double-wide this way
            y = y + 1
            IF y = 25 THEN
                d = d + 1 ' this Y position changes behavior too.
                LOCATE 25, 79
                PRINT "±±";
            END IF
        CASE 2
            MESSAGE$ = "The border goes left"
            x = x - 1
            IF x = 1 THEN d = d + 1 ' hope you get the gist of this.
        CASE 3
            MESSAGE$ = "The border then goes up"
            y = y - 1
            IF y = 1 THEN d = d + 1
    END SELECT
    LOCATE y, x
    PRINT "±"; ' ASCII CODE 177 is a good border style.
    IF d / 2 <> INT(d / 2) THEN PRINT "±"; ' border is double-wide on the Y axis
    COLOR 15
    LOCATE 5, 34 - INT((19 + LEN(MESSAGE$)) / 2)
    PRINT "      as variable d = "; LTRIM$(STR$(d)); ", "; MESSAGE$; "          "
LOOP UNTIL d = 4
LOCATE 4, 12
PRINT "now that variable d = 4, the border is now complete"
LOCATE 5, 4
PRINT SPACE$(70) ' one can keep the code text short using SPACE$
LOCATE 6, 15
PRINT "If you wanna know how to create a text mode border,"
LOCATE 7, 20 ' use larger numbers in LOCATE to reduce beginning spaces in PRINT.
PRINT "you can read the code after seeing this."
LOCATE 9, 4
PRINT "Press any key to end"
WHILE INKEY$ = ""
WEND
CLS ' clear screen for DOSBox (and also real DOS versions, VirtualBox or host system).
'
' This program can be education by reading the code after seeing the program run.
'
'
' this program was made as an introductory example for /r/QBeducation
'
'
' ===== THIS CONCLUDES OUR PRESENTATION =====

r/QBeducation • • May 21 '22

A course on how the RESTORE, READ, and DATA commands work

2 Upvotes
'
' an educational program on DATA, RESTORE, and READ commands.
'
' designed for QB64, QuickBasic 4.5, and QBasic 1.1, and compatible.
'
' A program that teaches us how the DATA, RESTORE, and READ commands work.
'
' The code here was laid out so we can have a more comprehensive idea for how this works.
'
' This program was made for the /r/QBeducation subreddit to educate QB64 and QBasic users
'
' on how DATA, RESTORE, and READ work, and so this example will demonstrate it's effect.
'
'
' ================ NOW, LET'S GET INTO THIS EXERCISE  =================
'
'                  this RESTORE command below jumps to the DATASEQUENCE
'                  label to gather DATA (also as a command).
'
RESTORE DATASEQUENCE
'
'                  the RESTORE command works similarly to GOSUB.
'
'
'                  this FOR...NEXT statmement below will read
'                  the DATA values sequentially.
'
FOR ASCII = 1 TO 9
    '
    '              ASCII character values will be referenced
    '
    READ Soo '     the READ comand will output DATA values below that were
    '              retrived by the RESTORE command above
    '
    '              a historical figure from Sault Ste Marie, Michigan
    '              (The Soo) developed ASCII.
    '
    '
    '              the PRINT command outputs text, unless you are a
    '              beginner at BASIC, this should be obvious.
    '
    PRINT CHR$(Soo);
    '
    '              each ASCII character gets printed one-by-one
    '              the CHR$ function is used for referring to
    '              numeric values of ASCII characters.
    '
    '              CHR$(#) is the syntax for CHR$.
    '              the # entry is for the ASCII value of
    '              the character
    '
    '
NEXT
'
'                  the NEXT command increments a value of the FOR
'                  command up, and the loop repeats until it
'                  reaches the highest number of the FOR command.
PRINT
PRINT
PRINT
PRINT "now you know how the RESTORE, READ, and DATA commands work."
PRINT
PRINT "press any key to continue"
'
'                  the phrase "press any key to continue"
'                  is an old school routine that programs
'                  had back in the days of DOS, that allowed
'                  users to read text before proceeding.
'
'
'
'                  INKEY$ outputs keypresses, and the
'                  WHILE...WEND loop waits for one below.
'
WHILE INKEY$ = ""
WEND
'
'                  the END command will end the program
'                  before it reaches the DATA section.
'
END
'
'
'                  just so you know, the DATASEQUENCE
'                  label below is being referred to by the
'                  above RESTORE command, so we don't get
'                  confused about the code sequence as we
'                  educate aspiring QB64 and QBasic programmers.
'
'
'                  the DATA command uses numeric values as
'                  data, hence the command name
'
DATASEQUENCE:
DATA 66,79,66,32,66,69,77,69,82
'
'
' here you can see ASCII values of the name of somebody who developed the ASCII standard.
'
'
'
'
'
' We also have more to learn about coding in QB64 and QBasic.
'