Weekly Qbasic and Qb64 Lesson Topics
July 17, 2018, 08:02:06 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

The First lesson, by Garry


Pages: [1]
  Print  
Author Topic: The First lesson, by Garry  (Read 962 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: January 07, 2011, 09:29:28 pm »

All though I am hopeing to post a better 1st lesson, as I am hardly qualified, but this is also to test, this board.
 This week 10:15 p.m. 07/01/2011 we will start with a simple "hello World"
Assumeing you have downloaded and installed qb64, or qb4.5...start you
qbasic program,...useing "file", select new,...
type in your code:
------code below-------

Code:
Screen 0
PRINT "HELLO WORLD"
PLAY "aagfebcd"
PRINT "this is fun"
END 
------end code------
Pretty simple, after yu type in the code, select run, start or start detached, and it should display Hello World, and then play a few notes,...you now have learned, PRINT and PLAY . If you want you can save the file as anyname.
In qb64 the executable is made automaticly, with the filename you used.exe and will run as a executable, for your records. Any questions, please feel free to ask, but post in the questions category.
Thats it from Garry
« Last Edit: September 07, 2011, 10:23:38 pm by GarrisonRicketson » Report Spam   Logged

Social Buttons

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #1 on: January 21, 2011, 11:23:07 pm »

12:06 a.m. 22/01/2011
 I apologize, it has almost been 2 weeks, ok With this code, you will also see how you can use locate, to put your text in different places on the screen.
 You can also set colors for the text and back ground, use qbasic or qb4.5 HELP, color to get complete color numbers chart,  or just change the numbers I used, and see what happens.NOTE: In the DEMOS category I have posted a demo, with some of the color numbers. Also by change the screen nmbr, 0-13, you can see what effects, this has. The numbers in the LOCATE can be changed to , to get a idea of what parts of the screen the text goes too.
There is more that could be exlained on this, but if I can figure this out, then anyone can,...Ok here is the code:
----------------Code below-------------------
Code:
DEFLNG A-Z

SCREEN 12
COLOR 0, 2
DO
    LOCATE 2, 5
    PRINT " Here it is now"
    PLAY " a4gc-b10c0eg"
    CLS
    LOCATE 15, 22
    PLAY "g10ae,ga0bc"
    PRINT "It went here"
    _DELAY 1
    CLS
    PRINT "any key, quits"
    PRINT "So this is a simple demo of locate,print, and play."
    PRINT " Also, DO, LOOP, UNTIL and INKEY$ ,since there is no key,specified"
    PRINT "then anykey exits the loop"
    _DELAY 2
    CLS
    LOCATE 26, 22
    PRINT "now it is here"
    _DELAY 1
LOOP UNTIL INKEY$ <> "" 
--------------- end code---------------
Of course if you get one or more of the tutorials available, you could breeze thru this basic stuff in a day or 2, ....this is a little special for me, as I wrote this, mostly by memory, althoug I did have to look at a sample someone gave me, to remember the loop until inkey$ <> ""  I have a hard time remembering that.
enjoy, from Garry
« Last Edit: September 07, 2011, 10:24:47 pm by GarrisonRicketson » Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #2 on: January 23, 2011, 11:50:37 pm »

Ok this time it is less then a week,...this is a demo useing PRINT,IF,GOTO,INPUT FOR AND NEXT, I got the idea from Vic's QBasic Programming Tutorial:
http://www.qbasicnews.com/tutorials.php
Actually just with these few basic commands, there is
a wide variety of things one can do, that will be up to you, to experment and see what you come up with.
------------------- code below---------
Code:
  DEFLNG A-Z
Screen 0
INPUT "What is your name "; name$
PRINT "Hello "; name$
PRINT " My name is Garry, I made this up,with the help of a tutorial,by Vic"
PRINT "Thank you, wait a couple of seconds to go on"
_DELAY 4
CLS
1 PRINT "These are some choices,of how many times to print something"
INPUT "0, 2,3,4,5,6,10"; number
IF number = 0 THEN
    END
END IF

IF number = 2 THEN
    CLS
    FOR i = 1 TO 2
        PRINT "You selected 2 "
    NEXT
    GOTO 1
END IF
IF number = 3 THEN
    CLS
    FOR i = 1 TO 3
        PRINT "You selected 3"
    NEXT
    GOTO 1
    END
END IF
IF number = 4 THEN
    CLS
    FOR i = 1 TO 4
        PRINT " you selected 4 "
    NEXT
    GOTO 1
    END
END IF
IF number = 5 THEN
    CLS
    FOR i = 1 TO 5
        PRINT "you selected 5 "
    NEXT
    GOTO 1
    END
END IF
IF number = 6 THEN
    CLS
    FOR i = 0 TO 1
        PRINT " 6 is going to be different"
    NEXT
    GOTO 2
    END
END IF
IF number = 10 THEN
    CLS
    FOR i = 1 TO 10
        PRINT "you selected 10"
    NEXT
    GOTO 1
    END
END IF
2 PRINT "this is 6"
PLAY "aaaaaa"
PRINT " 3 x 2 ="
PRINT 3 * 2
_DELAY 1
GOTO 1
----------end code------
 I have seen alot of times they discourage useing GOTO, but at this point I use it alot, as I do not know or understand another way to move to different parts of a program, and goto is simple, clear,..just number the parts and gotto the number.
from Garry
« Last Edit: September 07, 2011, 10:22:22 pm by GarrisonRicketson » Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #3 on: February 22, 2011, 07:17:09 am »

Here is the same program, but with out useing GOTO, this code was written by some one else, and also posted on QB64.net.
Code:
     REM
DEFINT A-Z

SCREEN 12
Done = 0

DO
  LOCATE 2, 10
  PRINT "WELCOME to Garrys invention"
  COLOR 2: PRINT "You Can do these things "

  PRINT "1)Multiply"
  PRINT "2)ADD"
  PRINT "3)Quit"
  Valid% = 0
  WHILE Valid% = 0
    Choice$ = INPUT$(1)
    Choice% = ASC(LTRIM$(Choice$))
    PRINT Choice$, Choice%
    SELECT CASE Choice%
      CASE 49 TO 51
        Valid% = 1
      CASE ELSE
        Valid% = 0
    END SELECT
  WEND
  CLS
  SELECT CASE Choice%
    CASE 49 'multiply
      RANDOMIZE TIMER
      Num1% = INT(RND * 9) + 1
      Num2% = INT(RND * 9) + 1
      LOCATE 10, 2
      PRINT "The product of"; Num1%; " x "; Num2%; "= "
      INPUT Answer$
      Answer% = VAL(LTRIM$(Answer$))
      IF Answer% = Num1% * Num2% THEN
        PRINT "Correct "; Num1%; " x "; Num2%; " = "; Answer%
        SOUND 1000, 1
      ELSE
        PRINT "Wrong ";
        SOUND 600, 3
        Answer% = Num1% * Num2%
        PRINT Num1%; " x "; Num2%; " = "; Answer%
      END IF
      PRINT Answer$
    CASE 50 'addition
      RANDOMIZE TIMER
      Num1% = INT(RND * 9) + 1
      Num2% = INT(RND * 9) + 1
      LOCATE 10, 2
      PRINT "The sum of"; Num1%; " + "; Num2%; "= "
      INPUT Answer$
      Answer% = VAL(LTRIM$(Answer$))
      IF Answer% = Num1% + Num2% THEN
        PRINT "Correct "; Num1%; " + "; Num2%; " = "; Answer%
        SOUND 1000, 1
      ELSE
        PRINT "Wrong ";
        SOUND 600, 3
        Answer% = Num1% + Num2%
        PRINT Num1%; " + "; Num2%; " = "; Answer%
      END IF
    CASE 51 'quit
      Done = 1
  END SELECT
  _DELAY 1
  CLS
LOOP WHILE Done = 0
SLEEP
SYSTEM


 
« Last Edit: April 11, 2012, 07:15:44 pm by GarrisonRicketson » Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #4 on: April 11, 2012, 09:18:54 pm »

I tried combining 2 of these into 1 program, it works, but it dose something kind of "odd",
 harmless , enough but at this point I do not understand why.
 First I want to mention this:
Quote
1] Always put this at the top of the program DEFLNG A-Z
(It means any variable you make will automatically be of the LONG type)
2] Create an output screen. If you don't screen 0 will be used as default.
3] To prevent the program ending immediately add this before SYSTEM
Dummy$=input$(1) (this waits for a key press without needing the enter key pressed)
4] End with the system command and your output screen will be closed automatically.   
All though these things are not always necessary, it probabley is a good "habbit" to get into, especially when you get into using 
SUBS , and Variables,..(need to add links too keywords)
Code:
  DEFLNG A-Z
SCREEN 0
INPUT "What is your name "; name$
PRINT "Hello "; name$
PRINT " My name is Garry, I made this up,with the help of a tutorial,by Vic"
PRINT "Thank you, wait a couple of seconds to go on"
_DELAY 4
CLS
1 PRINT "These are some choices,of how many times to print something"
PRINT "NOTE 0 will exit the program"
PRINT " 0 exits,2,3,5 and 10,print that many times"
PRINT " 6 beeps six times,"
PRINT " 9 goes to another program "
INPUT "0,2,3,4,5,6,10,9"; number
IF number = 9 THEN
    CLS
    FOR i = 1 TO 0
        PRINT "you selected 9,now you will see screen 12"
        _DELAY 3
    NEXT
    GOTO 12
    END
END IF

IF number = 0 THEN
    END
END IF

IF number = 2 THEN
    CLS
    FOR i = 1 TO 2
        PRINT "You selected 2 "
    NEXT
    GOTO 1
END IF
IF number = 3 THEN
    CLS
    FOR i = 1 TO 3
        PRINT "You selected 3"
    NEXT
    GOTO 1
    END
END IF
IF number = 4 THEN
    CLS
    FOR i = 1 TO 4
        PRINT " you selected 4 "
    NEXT
    GOTO 1
    END
END IF
IF number = 5 THEN
    CLS
    FOR i = 1 TO 5
        PRINT "you selected 5 "
    NEXT
    GOTO 1
    END
END IF
IF number = 6 THEN
    CLS
    FOR i = 0 TO 1
        PRINT " 6 is going to be different"
    NEXT
    GOTO 2
    'END
END IF
IF number = 10 THEN
    CLS
    FOR i = 1 TO 10
        PRINT "you selected 10"
    NEXT
    GOTO 1
    END
END IF
2 PRINT "this is 6"
PLAY "aaaaaa"
PRINT " 3 x 2 ="
PRINT 3 * 2
_DELAY 2
GOTO 1
END

12
DEFINT A-Z

SCREEN 12
PRINT "Hello "; name$
PRINT "THIS WILL BE SCREEN 12"
PRINT "The following code dose not use GOTO,"
PRINT "Hit any key to continue"
SLEEP
CLS

Done = 0

DO
    LOCATE 2, 10
    PRINT "WELCOME to Garrys invention"
    COLOR 2: PRINT "You Can do these things "
'///Note it is in this part, that if any key other a number is "hit", it displays, the letter and  a number, for example v  111, the space key will cause a error, so I need to find out how to fix this.

    PRINT "1)Multiply"
    PRINT "2)ADD"
    PRINT "3)Quit"
    Valid% = 0
    WHILE Valid% = 0
        Choice$ = INPUT$(1)
        Choice% = ASC(LTRIM$(Choice$))
        PRINT Choice$, Choice%
        SELECT CASE Choice%
            CASE 49 TO 51
                Valid% = 1
            CASE ELSE
                Valid% = 0
        END SELECT
    WEND
    CLS
    SELECT CASE Choice%
        CASE 49 'multiply
            RANDOMIZE TIMER
            Num1% = INT(RND * 9) + 1
            Num2% = INT(RND * 9) + 1
            LOCATE 10, 2
            PRINT "The product of"; Num1%; " x "; Num2%; "= "
            INPUT Answer$
            Answer% = VAL(LTRIM$(Answer$))
            IF Answer% = Num1% * Num2% THEN
                PRINT "Correct "; Num1%; " x "; Num2%; " = "; Answer%
                SOUND 1000, 1
            ELSE
                PRINT "Wrong ";
                SOUND 600, 3
                Answer% = Num1% * Num2%
                PRINT Num1%; " x "; Num2%; " = "; Answer%
                _DELAY 3
            END IF
            PRINT Answer$
        CASE 50 'addition
            RANDOMIZE TIMER
            Num1% = INT(RND * 9) + 1
            Num2% = INT(RND * 9) + 1
            LOCATE 10, 2
            PRINT "The sum of"; Num1%; " + "; Num2%; "= "
            INPUT Answer$
            Answer% = VAL(LTRIM$(Answer$))
            IF Answer% = Num1% + Num2% THEN
                PRINT "Correct "; Num1%; " + "; Num2%; " = "; Answer%
                SOUND 1000, 1
            ELSE
                PRINT "Wrong ";
                SOUND 600, 3
                Answer% = Num1% + Num2%
                PRINT Num1%; " + "; Num2%; " = "; Answer%
                _DELAY 3
            END IF
        CASE 51 'quit
            Done = 1
    END SELECT
    _DELAY 1
    CLS
    PRINT "Press anykey to exit"
    _DELAY 2
    CLS
LOOP WHILE Done = 0
SLEEP
SYSTEM
 
You will see where I remarked about the key entered displaying a  letter and the  number.  When I find out why, I can explain, and correct this.
« Last Edit: April 11, 2012, 11:49:00 pm by GarrisonRicketson » Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #5 on: April 12, 2012, 12:49:12 am »

Ok, the previous demo, has been modified and corrected, thanks due to Small No More, at qb64.net,..
 This is the corrected version:
Code:
DEFLNG A-Z
SCREEN 0
INPUT "What is your name "; name$
PRINT "Hello "; name$
PRINT " My name is Garry, I made this up,with the help of a tutorial,by Vic"
PRINT "Thank you, wait a couple of seconds to go on"
_DELAY 4
CLS
1 PRINT "These are some choices,of how many times to print something"
PRINT "NOTE 0 will exit the program"
PRINT " 0 exits,2,3,5 and 10,print that many times"
PRINT " 6 beeps six times,"
PRINT " 9 goes to another program "
INPUT "0,2,3,4,5,6,10,9"; number
IF number = 9 THEN
    CLS
    FOR i = 1 TO 0
        PRINT "you selected 9,now you will see screen 12"
        _DELAY 3
    NEXT
    GOTO 12
    END
END IF

IF number = 0 THEN
    END
END IF

IF number = 2 THEN
    CLS
    FOR i = 1 TO 2
        PRINT "You selected 2 "
    NEXT
    GOTO 1
END IF
IF number = 3 THEN
    CLS
    FOR i = 1 TO 3
        PRINT "You selected 3"
    NEXT
    GOTO 1
    END
END IF
IF number = 4 THEN
    CLS
    FOR i = 1 TO 4
        PRINT " you selected 4 "
    NEXT
    GOTO 1
    END
END IF
IF number = 5 THEN
    CLS
    FOR i = 1 TO 5
        PRINT "you selected 5 "
    NEXT
    GOTO 1
    END
END IF
IF number = 6 THEN
    CLS
    FOR i = 0 TO 1
        PRINT " 6 is going to be different"
    NEXT
    GOTO 2
    'END
END IF
IF number = 10 THEN
    CLS
    FOR i = 1 TO 10
        PRINT "you selected 10"
    NEXT
    GOTO 1
    END
END IF
2 PRINT "this is 6"
PLAY "aaaaaa"
PRINT " 3 x 2 ="
PRINT 3 * 2
_DELAY 2
GOTO 1
END

12
DEFINT A-Z

SCREEN 12
PRINT "Hello "; name$
PRINT "THIS WILL BE SCREEN 12"
PRINT "The following code dose not use GOTO,"
PRINT "Hit any key to continue"
SLEEP
CLS

Done = 0
start:
CLS
DO
    '/// This is PART 2 and it has a bug
    LOCATE 2, 10
    PRINT "WELCOME to Garrys invention"
    COLOR 2: PRINT "You Can do these things "
    '///Note it is in this part, that if any key other a number is "hit", it displays, the letter and  a number, for example v  111, the space key will cause a error, so I need to find out how to fix this.NOW it is fixed,

    PRINT "1)Multiply"
    PRINT "2)ADD"
    PRINT "3)Quit"
    Valid% = 0
    WHILE Valid% = 0
        Choice$ = INPUT$(1)

        Choice% = ASC(LTRIM$(Choice$))
        'PRINT Choice$, Choice% <===this line you was telling it to print the numbers and characters
        SELECT CASE Choice%
            CASE 49 TO 51
                Valid% = 1
            CASE ELSE
                Valid% = 0
        END SELECT
    WEND
    CLS
    SELECT CASE Choice%
        CASE 49 'multiply
            RANDOMIZE TIMER
            Num1% = INT(RND * 9) + 1
            Num2% = INT(RND * 9) + 1
            LOCATE 10, 2
            PRINT "The product of"; Num1%; " x "; Num2%; "= "
            INPUT Answer$
            Answer% = VAL(LTRIM$(Answer$))
            IF Answer% = Num1% * Num2% THEN
                PRINT "Correct "; Num1%; " x "; Num2%; " = "; Answer%
                SOUND 1000, 1
            ELSE
                PRINT "Wrong ";
                SOUND 600, 3
                Answer% = Num1% * Num2%
                PRINT Num1%; " x "; Num2%; " = "; Answer%
                _DELAY 3
            END IF
            PRINT Answer$
        CASE 50 'addition
            RANDOMIZE TIMER
            Num1% = INT(RND * 9) + 1
            Num2% = INT(RND * 9) + 1
            LOCATE 10, 2
            PRINT "The sum of"; Num1%; " + "; Num2%; "= "
            INPUT Answer$
            Answer% = VAL(LTRIM$(Answer$))
            IF Answer% = Num1% + Num2% THEN
                PRINT "Correct "; Num1%; " + "; Num2%; " = "; Answer%
                SOUND 1000, 1
            ELSE
                PRINT "Wrong ";
                SOUND 600, 3
                Answer% = Num1% + Num2%
                PRINT Num1%; " + "; Num2%; " = "; Answer%
                _DELAY 3
            END IF
        CASE 51 'quit
            Done = 1
    END SELECT
    _DELAY 1
    CLS
    PRINT "Press anykey to exit"
    _DELAY 2
    CLS
LOOP WHILE Done = 0
SLEEP
SYSTEM
' You can try this code, separate, just add start: to the top, right above dontdoit:
dontdoit:
CLS
LOCATE 12, 20: PRINT "Sorry input must be a number"
LOCATE 14, 20: PRINT "Returning to menu in 10 seconds"
SLEEP 10
GOTO start
Quote
  'PRINT Choice$, Choice% <===this line you was telling it to print the numbers and characters This is what needs to be removed,..using the ' in front of the code line, "remarks" it out, The ' Is used to indicate a line is a remark and not code to be executed.
So now, you should be starting to understand a little, about "codeing" with qb64,.. using a few commands, remarks,..  and also, when you get to the point where you do not understand, why it dose not work right, just ask,...someone will find a answer,.. also looking  at the wiki, http://qb64.net/wiki/index.php?title=Main_Page is a good place to start, when you need more info.
 
 
Report Spam   Logged


Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Buy traffic for your forum/website
traffic-masters
Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy