QBasic Tutorial

If you haven't already done so download the QB64 compiler from here : http://www.qb64.net/. Select your operating system and install.

Your First Program

Try typing this into the qbasic compiler (It's a blue window) :

Print "Hello World"

Now, press 'F5' to run the program (Or go to the 'run' menu and click start)

What happened? It probably displayed the message 'Hello World' on the screen right?

Commands

PRINT
The first command you're going to learn about is the print command. Basically what  'Print' does is tell Qbasic to write something to the screen. In the program above, Qbasic printed the message "Hello World".

*HINT*
Instead of typing print into the blue window/compiler, just type ?     "Hello World". When you press enter/return, the '?' will be changed to PRINT
*HINT*

You can also print variables onto the screen.

Try this :

x = 1
Print x

Now QBasic will print '1'.

You can also type multiple things, separated by semicolons (;).

Try this :

x = 1
? "Hello World" ; x

Now, that will print 'Hello World 1'!

MATHEMATICAL OPERATORS


+ : adds two values
- : subtracts the second value from the first
* : (That's an asterisk) multiplies two values
/ : divides the first value by the second
^ : raises the first number by the second number. 3^2 would be 3 raised to 2, or 9
SQR(num) : Takes the square root of a number
(num) MOD (num2) : Gives you the remainder when you divide num by num2




REM
Rem doesn't actually do anything. It stands for remark and is used to add comments to the code. The compiler COMPLETELY IGNORES anything typed after REM.

Try this

REM Print "Hello World"

Now, when you press 'F5', nothing happens.

So why do we need REM?

REM is used to put comments for other programmers to see.

For example :

REM Prints a message
Print "Hello World"

Now, just by looking at the REM statement, other programmers would know what the program does, without having to read the code.

You can use the apostrophe (') as a shortcut for REM

For example :

? "Hello World"     ' This is a comment



INPUT
What use is a computer if you can't tell it what to do?

That is where the Input command comes in handy!

With Input, you can ask the user to enter a value. Just like print, you can type many things separated by semicolons (;).

Try this :

Input "Enter your name"

Now Press 'F5'. What happened? Probably Nothing! (Don't worry, you didn't type it in wrong). That's because when you INPUT a value, you need to tell Qbasic where to put it!

Try this now :

Input "Enter your name" ; name$  'Whatever the user types is put in the variable name$
Print name$

Run it and see what happens!

It probably printed whatever you typed!

IF...THEN...ELSE


If you've taken any science classes you've probably been taught to write your hypotheses in "IF...THEN...BECAUSE" for. In QBASIC, the format is this :

IF (condition is met) THEN (do this task) ELSE (otherwise do this. NOTE : THE "ELSE" PART IS OPTIONAL, THE "THEN" PART IS NOT!!)


These are the statements usually used in the (condition is met) part

  • > (greater than) : If the first value is more than the second, the condition IS met otherwise it is NOT
  • < (less than) same as above except if the first value is LESS than the second, the condition IS met otherwise it is NOT
  • >=(greater than OR equal to) if the first value is greater than or equal to the second,  the condition IS met otherwise it is NOT
  • <= (less than OR equal to) if the first value is less than the second,  the condition IS met otherwise it is NOT
  • = (equal to) (I think this one is pretty obvious)
  • <>(NOT equal to) (again, its quite obvious)


For example if I wrote the following :

Input "Enter a number"; num
IF num > 5 THEN Print "Your number is more than 5" ELSE print "Your number is less than or equal to 5"


More conditionals

In an IF...THEN statement you can have multiple conditions."How" you say? I'll show you...

OR


The OR statement tells QBASIC to do the action after "THEN" if either of the conditions are met.

For example,

Input "Enter a number";num


If num>10 OR num <5 then print "That's a good number" 'If num is more than 10 OR num is less than 5 then it will print the message


AND


The AND statement tells QBASIC to do the action after "THEN" if ALL of the conditions are met.



For example,

Input "Enter a number";num
Input "Enter another number"; num2


If num>10 AND num2 <5 then print "That's a good number" 'If num is more than 10 AND num2 is less than 5 then it will print the message.


NOT

The NOT statement tells QBASIC to do the action after "THEN" if a condition is NOT met.




For example,

Input "Enter a number";num


If NOT(num>5) then print "num is NOT greater than 5" ' If num is NOT greater than 5, then it will print the message


THERE ARE MORE CONDITIONAL, BUT FOR NOW, THESE ARE THE IMPORTANT ONES. Some of the other conditionals include : XOR, NAND (basically NOT + AND) , and NOR (basically NOT + OR).


Modifying a String


Modifying strings is very useful in a number of places. I'll show you some basic commands which modify strings.

LEFT$

This command will take the left part of a string. For example, if i created a string called str$ and stored "Hello,I am" in it and I wrote the following command :

modified$ = left$(str$,5)

modified$ would now be equal to the first 5 characters of the string "str$", which means, modified$ would be "Hello".

RIGHT$

RIGHT$ is just like LEFT$ except it takes part of the string starting from the right.

In the previous example, if i had written :

modified$ = right$(str$,5)


modified$ would now be ",I am". (Spaces count as characters too!)

*Just a thought*
What would you do if you wanted to take the middle part of the string?

In the previous example with the string "Hello,I am" what would I do if I only wanted the "o,I" part of the string?

I would take the left half of the string "o,I am"

But how would I get the string "o,I am"?

I would take the right part of the full string.

For example I could do this :

' By the way, remember comments? Anything after an apostrophe is a comment. This is a comment!
temporary$ = right$(str$,6) 'Now temporary$ = "o,I am"


modified$ = left$(temporary$,3) ' Now modified$ = "o,I"


That's just one way to do it. Another way would be this :

modified$ = left$(right$(str$,6),3) ' Basically, I combined the two statements into one. This will take the 3 letters on the left OF the 6 letters on the right


BUT WAIT! *drum roll please* THERE'S AN EVEN BETTER WAY TO DO THIS! CHECK THE NEXT COMMAND!


*Just a thought*


MID$ (THIS IS THE NEXT COMMAND)


With mid$ you can take the middle of a string by specifying where you want to start from and how many letters you want.

With the previous example (I will use a new example for the next command!) if I wanted the string "o,I" I would do this :

modified$ = mid$(str$,5,3) ' This tells QBASIC to start at character 5 (which is "o") and take 3 total characters ("o,I"). MUCH EASIER THAN USING RIGHT$ AND LEFT$!


UCASE$


Have you ever wanted to make plain text seem like shouting? (It's alright,neither have I)

That's what UCASE$ is for!!

UCASE$ tells QBASIC to capitalize each letter in a string.

For example :

Print ucase$("I am not shouting right now. ")


This would print "I AM NOT SHOUTING RIGHT NOW."

LCASE$


Are you annoyed when people type in all caps?

If so, then LCASE$ is for you!

LCASE$ tells QBASIC to make every letter in a string lower case.

For example,

Print lcase$("I AM SHOUTING RIGHT NOW")


This would print "i am shouting right now".

*WAIT*
You might be thinking "Why would I ever need to use these commands?"

The answer to that is simple. Lets say that I wrote the follow program :

input "Type 'y' for yes or 'n' for no";yn$


if yn$ = "y" then print "you said YES" else print "you said NO"


At first glance, the program seems to work well.

BUT, what if the user entered capital letter "Y" instead of "y"?

Let's change the previous program to this :


input "Type 'y' for yes or 'n' for no";yn$



if LCASE$(yn$) = "y" then print "you said YES" else print "you said NO"


Now, it works even if the user types "Y" instead of "y"


*WAIT*

LOOPS


In most programs, we need to be able to do the same thing over and over again. For example, if I wanted to make a program which tells me the square root of the number entered by a user, I would want it to keep going until I closed the program. Loops allow us to do this. There are two main types of loops in most programming languages : The FOR...NEXT loop and the DO...LOOP. In QBASIC there are also modifications of the DO...LOOP, which we'll discuss later.

*THERE WILL BE MORE POSTED TOMORROW. IF YOU HAVE ANY QUESTIONS POST A COMMENT IS THE QUESTIONS AND COMMENTS SECTION*






























29 comments:

  1. It was very useful if you try to to continue this program it will be very helpful for me though so please continue this program and I request all of you to take help of this program and leave a comment. Bye

    ReplyDelete
  2. It was very useful if you try to to continue this program it will be very helpful for me though so please continue this program and I request all of you to take help of this program and leave a comment. Bye

    ReplyDelete
  3. It was very useful of me to use this program and I request all of you to use this program and leave a comment this is very helpful for me and I request all of you to help out of this program and learn basic.

    ReplyDelete
  4. very useful indeed!!
    please continue with the loops,library functions , series etc. and any other qbasic programs

    ReplyDelete
  5. This is very helpful for me
    I have enjoyed it.
    And i will request all my friends to go through this.

    ReplyDelete
  6. Thank you very much................this is the super than the super blog for students who want to learn qbasic

    ReplyDelete
  7. Please help me with the Qbasic codes for the following
    Examination Scores Assigned Grade
    90 and above A
    80-89 B
    70-79 C
    60-69 D
    50-59 E
    Below 50 F

    ReplyDelete
    Replies
    1. Yes this is my time of learning qbasic and l find it very useful

      Delete
    2. cls
      rem assigning grades(Hopefully works)
      input"Enter your name";A$
      input"Enter your marks";M
      select case M
      CASE 90 to 100
      ? a$;" got an A"
      CASE 80 to 90
      ? a$;" got a B"
      CASE 70 to 80
      ? a$;" got a C"
      CASE 60 to 70
      ? a$;" got a D"
      CASE 50 to 60
      ? a$;" got an E"
      CASE 0 to 50
      ? a$;" got an F"
      CASE else
      ? "Wrong entry"
      end


      Delete
  8. Tevida nutrients needed to maintain the firmness and longevity of an erection for a long time after the end of intercourse.This leads to a more pleasant sexual contact each time it is used. As it grows in size, man's
    https://www.supplementsforfitness.com/tevida/

    ReplyDelete
  9. Keto 180 Shark Tank defines personal characteristics of health merchandise.Keto 180 is a 100% pure weight loss product which Ddminishing stored fats and calories from the bodies

    ReplyDelete
  10. Quit 9 To 5 Academy Review is a place for beginners and experts in the field of affiliate marketing and for those who want to leave their 9 to 5 job and start their own business in this platform.

    ReplyDelete
  11. Dieta Salutares is an best site where you can get detail about health, wellness and beauty products that really helps you to select best products according to your needs. This site also provides you latest supplements that is more helpful to make your life better.

    http://dietasalutares.it/

    https://www.facebook.com/Dieta-Salutares-582647302249651/

    ReplyDelete
  12. Online Supplements Angles for Health Products and Their Uses, Benefits, review and exparts advice, visit At Supplements Angles

    ReplyDelete
  13. Enzolast : I will not even hassle to say you even have to do that. I grasp that is sort of drawn out. It's how to start out working with Testosterone Booster once more. This is often how to prevent worrying and begin living. Some rules are actually enforced. After I first began out with Male Enhancement I was quite confused also.


    https://www.supplementmegamart.org/enzolast/

    ReplyDelete




  14. Healthy GNC >>>> Healthy Gnc is one only Health & Wellness supplement hub in usa. We have natural ingredients supplements with no side effects. we are providing Muscle building , Weight Management , weight loss and wellness supplements.

    For More Information Click Here >>>> http://www.healthygnc.com/


    ReplyDelete
  15. I'm looking forward to be seeing such article thank you God bless you all.

    ReplyDelete
  16. healthonway
    Nerotenze Examination - In the speak second, most of the virile adults meet the one sympathetic of problems in their lives. These problems are low libido, erectile dysfunction, low rate evaluate and numerous author, consanguine to the embody. These issues mostly chance because of low production of testosterone endocrine after a reliable age. Sometimes you property little spanking and less reassured with your partner and it is vindicatory because of the consequences of ontogeny age that brings careful sexy issues with itself. There are many health products acquirable in the mart that assures you that they leave give you assistance health supplements the one which mitigated our necessary is the Nerotenze . It is a real new shaping and advisable affix in the lean of someone improvement supplements. It totally differs from others because it deeply maintains the vigour story, increases the testosterone catecholamine which is the statesman grounds behind all these issues. There are lots of awful features which you eff moldiness jazz so scan this afloat article
    What is Nerotenze?

    ReplyDelete
  17. Endurmax Reviews: no one can correct their sex life like other successful qualities, fitness only for time and experience. Sex life and penis size are genetics only and people after a point of time are unable to have satisfactory bedroom sessions with their partner. This is very common men definitely want to overcome sexual problems because they also want to have a romantic relationship. This is the reason why we have a new and laboratory tested product for you and that is Endurmax.

    ReplyDelete
  18. Nook miles Ticket is very important for your progress in Animal Crossing: New Horizons. You can purchase the Nook miles Ticket at the Nook station served by residents. Then go to the airport to visit the desert island, harvest resources such as wood or iron, and convince the villagers to join your beautiful island. You can find various goods on the new island, so make sure you have increased your inventory to bring back a lot of cool things. Therefore, to fly to various mysterious islands to collect items and items, you need more Animal Crossing Nook miles Ticket. Fortunately, on IGGM.com, you can buy the Nook miles Ticket at the cheapest price in the entire market. Ample inventory can ensure fast delivery. They can help you save time and money to enjoy better games. ! Buy ACNH Nook Miles tickets from IGGM now!

    ReplyDelete
  19. Microsoft Exam Dumps That have an impact on the estimation results. Fundamental fashions of the estimations are delivered that assist take a look at architects and professionals see exactly what's being estimated. These fashions define how right proper right proper right here and there reputedly minor options identified with the take a look at set-up can basically have an impact on the results of an estimation. Course Outline Computer Modeling Tools for Electromagnetic Compatibility Computer showing has emerge as a huge part of the plan cycle for digital frameworks.
    https://dumpsboss.com/certification-provider/microsoft/

    ReplyDelete
  20. Cisco Exam Dumps in thoughts (and are robotically needed to have) the Microsoft Certified Trainer (MCT) affirmation. The MCT might be received via documenting a product software program software utility programming to Microsoft that demonstrates which you preserve a the the the the front line Microsoft confirmation

    https://dumpsboss.com/certification-provider/cisco/

    ReplyDelete
  21. Cisco Exam Dumps And rely upon it has a deep rooted gain. They have greater noteworthy seriousness among man or woman human beings and are notably a super deal plenty tons much less tough to be supported via their chief. Truly, the customers of our DES-1721 test targeted on schooling have procured greater super than that, however an interminable abundance of life. You can likewise have a few questions why our DECS-IE DES-1721 legitimate test exercise has pulled in quite severa customers; the accompanying abilities will offer you with an explanation. DF rendition: Easy to test out and print Under the

    https://dumpsboss.com/certification-provider/cisco/

    ReplyDelete
  22. Oracle Exam dumps day-day-day-day and the exceptional amazing DES-1721 have a take a have a test guide in your email in multiple indistinct time withinside the predetermination of the complete three hundred and sixty five days after buy. We make certain you that our present day-day-day-day capability reassets and sufferers of EMI, control switch speeds, dismiss round approximately frameworks and coupling processes that do not make a energy of will to EMC problems, and intentionally discover and function a take a have a test frameworks and coupling processes geared up to incurring an object to be resistant. This is a muddled EMC bearing. Understudies taking this path want to have finished
    https://dumpsboss.com/certification-provider/oracle/

    ReplyDelete
  23. CBD Gummies Shop compounds that could probably enhance recovery consequences of hemp. Kanibi is constantly a fan desired in phrases of flavor, and they provide transparency with their finding out opinions on their internet site. 9. CBDFX CBD Gummies With Melatonin 9 cbdfx A bottle of CBDFX CBD Gummies With Melatonin Milligrams: 5 in step with gummy Gummies in step with bundle: 60 Price: $50 Ready to hit the hay?
    https://ecuacbd.shop/

    ReplyDelete