ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Example Programs In Qbasic
    카테고리 없음 2020. 2. 29. 12:08
    1. Qb64 Download For Windows 10
    2. Qb64 Program Samples
    3. Qbasic Programming Examples And Exercises

    As anyone who has programmed with QBasic knows, it is a fun, easy and ( for it's time ) quite powerful programming tool! Admittedly, it is rather slow, but given that it has never cost a dime, I suppose that's an acceptable concession.

    As I mentioned, QBasic includes a wide range of simple, powerful commands, although it's one glaring shortcoming is it's complete lack of mouse support!For the longest time, I had wanted to find a way to use the mouse in my own QBasic programs. While I eventually found several fine examples of code on-line that did in fact interface with the mouse, they all seemed very complicated to me, with multiple sub-routines, functions and procedure calls. So, I decided to 'boil it all down' to the simplest, bare-minimum method, and to my knowledge, what I came up with is still the quickest, easiest way to incorporate mouse functions into a QBasic program!One might think of my code as a kind of 'black box' or 'plug-in' of sorts; you simply copy my 'Mouse' sub-routine into your program, and it immediately provides rudimentary mouse support! Interfacing with the mouse is then accomplished by way of three simple functions; 'Mouse 1' shows the mouse cursor, 'Mouse 2' hides it again, and 'Mouse 3' reads the mouse's current button status as well as it's location. This information is communicated to the user's program through 3 global variables; 'B' represents the mouse buttons, 'H' contains it's horizontal co-ordinates, and 'V' returns it's vertical co-ordinates. As the title of this step implies, all we'll be doing in this step is downloading the 'template' file ( 'MOUSE.SUB' ), which is a bare-bones skeleton file, used for creating a new mouse-aware program, and a few sample programs ( 'QBMOUSE.BAS'), which demonstrates the mouse sub-routine in action! I've also included ('Buttons.bas'), a simple 'menu' style program and ('Pong3.bas'), a version of the classic 'Pong' game.

    Simply start by downloading these files into the folder on your hard-drive that contains the QBasic executable file. ( 'QBASIC.EXE' )When you're finished doing this, move on to Step 2. Assuming that you are at least familiar with programming in QBasic, I don't imagine I need to tell you how to open an existing Basic file!

    Qb64 Download For Windows 10

    Qbasic programs examples pdf

    However, if you'll notice, our template file, 'MOUSE.SUB', has the extension '.SUB', so it won't show up in the list of basic files you may already have on your hard-drive. Therefore, you'll need to type the full name of the file into the 'File Name' box, and then press 'Enter' ( Or, click the 'OK' button ). This is intentional; it sort of 'keeps it out of the way' while you're searching through your source files, and prevents you from accidentally opening ( and editing ) the file. Plus, as you create your own sub-routines, you can build a 'library' of sorts; essentially a collection of files, each with a handy, re-usable sub-routine, and give them all the '.SUB' extension. Then, you can just copy these routines & 'pop' them into any future project you may create!Once you've got the template file loaded, move on to the next step. Awright, looks like we're just about ready to go! Now, the first thing you'll want to do is CHANGE THE FILE NAME!

    This step is important - it keeps the template file in it's original condition, so that should any thing go wrong, you'll be able to start over with the original template file. Also, you'll want to give your new file the '.BAS' extension, so that it will show up in the file list box, next time you wish to load it! To change the file name, we simply click on the 'File' menu in the top left corner of the screen, and then click 'Save As.'

    Example

    From the drop menu. This will bring up an input box, where you'll supply the name you wish to give your new project. Now, we're ready to begin editing.

    To do this, simply move the cursor down to the line that reads 'Enter your code here' and, you guessed it; enter your code here! As to what code you should enter, well, that depends on what type of program you wish to create, although I will typically start with the command 'Mouse 1', which just displays the mouse cursor as mentioned before. Keep in mind however, that you may not want to display the cursor at all! For example, suppose you want to create the latest, greatest SLAMMIN' new version of the arcade classic 'Pong'.

    For a game like this, you can use the mouse to move your 'paddle' around, simply by reading the 'H' co-ordinate ( with the command 'Mouse 3' ), and then placing the paddle accordingly. In this situation, the mouse cursor would just get in the way if it were visible, so there's no need to display it at all! For a menu- or button- driven application however, you will certainly want to display the cursor, so that you know what you are clicking on! Just remember to hide the cursor ( using 'Mouse 2' ) before you send any text or graphics to the screen, so that it doesn't garble any of your artwork. You can always turn the cursor back on by calling 'Mouse 1' at any time! To make your program respond to specific actions, such as button clicks, you might use an 'IF' statement like the following; 'IF B = 1 THEN.' This causes the program to do something whenever the left button is pressed.

    Use 'B = 2' to intercept the right button, 'B = 3' for both, or even 'B 0' to activate on ANY combination of buttons! See the sample file 'QBMOUSE.BAS' for more examples of this and other techniques for interfacing with the mouse. If at any point it seems that your program just isn't responding to the mouse at all, it's probably because you haven't called 'Mouse 3' before trying to use the B, H or V values. Remember, you MUST read the mouse first, in order to ensure that these values are correct and current! That's why I typically make the command the first statement within a loop, just so I know the mouse variables are always up-to-date! Another handy trick I have found is to put the following line somewhere within the main loop of your program: 'Mouse 3: Locate 1,1: Print B;H;V' This just reads the mouse and prints the values of the mouse buttons, horizontal & vertical co-ordinates up in the top left corner of the screen, so that you can instantly see what's happening with the mouse. This helps immensely with development and de-bugging, and once your project is finished, you simply delete the line, and you're all set!

    That should just about do it! As I mentioned before, check out the sample program, and really try to get a handle on just what's happening with the mouse before you get started. And as always, please contact me at; flurng@gmail.com with any questions or comments! But above all, HAVE FUN!!!Update: For those who find it easier to learn visually, I have just uploaded the following video to Youtube:Please feel free to leave any questions or comments.( and TRY to stay awake! Yes, sorry for the confusion, but as I mentioned, if you download and run the sample programs, the process is pretty straight- forward.

    Essentially, there are just a few steps; first, you'd create your on-screen menu or 'buttons', then, call 'Mouse 1' to display the mouse cursor. At this point, you can see the cursor, but your program still has no idea what the mouse is doing. To get mouse data, start a loop and call 'Mouse 3'; this loads the variables 'B', 'H' and 'V' with the mouse button staus, and Horizontal and Vertical co-ordinates, respectively. Now, just test the variables with an 'If' statement, such as, 'If B = 1 AND H (top co-ordinate of your menu button) AND H (left side co-ordinate) AND V.

    Greetings,To answer your question, the 'poke' commands place numeric values directly into memory, in this case starting at offset 100, up to offset 117. The values listed correspond to Assembly language commands which access the mouse. The specific Assembly commands are as follows: Mov AX, 0000 Int 33 mov 0AAA,BX mov 0BBB,CX mov 0CCC,DX RETFNote that the second 'poke' command puts the value of Funk ( Either 1, 2 or 3, depending on which function is called) into memory at offset 101.

    Once these values are poked into memory, the command 'Call Absolute (100)' calls up the values in memory, and executes them as an assembly language routine. Hope this answers your question, and that my code helps you write many useful programs! Enjoy, and have fun programming!

    Greetings, SamH223! If you download and open the file; 'Buttons.bas', it should give you an idea how it all works, but the basic process goes as such; 1.Draw a button on screen. (Let's suppose It's 100 pixels from the left to 200 pixels from the left, and 100 pixels from the top to 200 down.) 2.Create a loop to check the mouse coordinates repeatedly.

    Qb64 Program Samples

    Call Mouse 3 to get the current coordinates and button status. 4.Write an 'if' statement, such as; 'If B = 1 then gosub WhichButton' 5.

    Create a 'WhichButton' subroutine, such as; 'WhichButton: Select case v Case 100 to 200: Gosub (do first button) Case 201 to 300: Gosub (do next button) Case 301 to 400: Gosub (do next, etc.) End select End sub 6. Create a subroutine for each button you created, and the the 'WhichButton' Routine should branch to the appropriate subroutine.

    Naturally, feel free to use whatever labels make sense for program. For instance, you might create an 'Open' routine, or 'Options', or 'Quit', etc. Whatever your program requires. Then, just create appropriate subroutines to handle each operation. Hope this helps & thanks for your interest in my code. And of course, should you have more questions, feel free to ask anything! So long for now & happy coding!

    I don't think that you took the various screen modes into account. You might have failed to test it under multiple resolutions. I don't think that I, originally, noticed that there were.sub and.bas files available for download; something may have been lost in translation. It would be nice if you could re-format your article to make the code more clear for online viewers.

    Qbasic Programming Examples And Exercises

    Thank you for the effort! I respect anyone who values the wealth of computing knowledge available via QBasic Especially these days!

Designed by Tistory.