BBS: Inland Empire Archive Date: 06-08-92 (21:54) Number: 164 From: PHILIP NELSON Refer#: NONE To: ALL Recvd: NO Subj: Object Oriented QB part 2 Conf: (2) Quik_Bas
To continue... There are many other advantages to writing Object Oriented Code in QuickBasic, and since I've started doing this, I find that most all programs I write use this concept. Now, to show one way of implementing Object Oriented Programming using QB, which is a way I've adopted, although there can be other methods. First step. You need to design the application itself. This is something that is taught by most programming classes, but seems to be relatively unknown in Basic programming. However, it is a good idea to do this when creating OOP code, since you'll more than likely want to re-use the libraries in other programs. The one type of object library I create, relates to IO handling. The keyboard is a good start, where I have a few instructions that deal with the keyboard, such as: KEYPRESS, WAITKEY, GETOPTION, GETNAME, GETPHONE and so on. Different editors are built into my keyboard object, which allows me to create applications quickly and without hastles. To create the master, or Class library, you need to create a seperate module. With this module, create an Include file, which will be the interface between the library and application program. In this include file, place the DECLAREs and any TYPE definitions required by the library, and that will be accessed by the application. To create the KEYBOARD class object, do the following: Create a function called: KEYIN$ (Message$) The next line would contain the following GOSUB ParseKeyInWord SELECT CASE Word$ CASE "WAITKEY" DO: A$ = INKEY$: LOOP UNTIL LEN(A$) KEYIN$ = A$ EXIT FUNCTION CASE "GETOPTION" GOSUB ParseKeyWord IF Len(Word$) = 0 THEN EXIT FUNCTION DO A$ = KEYIN$("WAITKEY") LOOP UNTIL INSTR(Word$, A$)>0 KEYIN$ = A$ EXIT FUNCTION CASE ELSE END SELECT EXIT FUNCTION ParseKeyInWord: ParseKeyWord: 'Spelling error in GETOPTION process Message$ = LTRIM$(RTRIM$(Message$)) A = INSTR(Message$+" "," ") Word$ = LEFT$(Message$+" ",A-1) Message$ = MID$(Message$+" ",A+1) Word$ = UCASE$(Word$) RETURN END FUNCTION Continued.... --- GEcho 1.00/beta * Origin: Brian's BBS [514-769-5023] Montreal : (1:167/149)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET