TechiWarehouse.Com

Programming Languages


QBasic Tutorial - QBasic TutorialQBasic is a very simple language to pick up, and yet it can accomplish a great deal. Granted you will probably never write Doom or Word Perfect with QBasic, but it has its strong points. One of them is to introduce people to programming without having to worry about the internal workings of the computer. It's simple to create games, business applications, simple databases, and graphics. The best aspect of the language is its close resemblance to English.
Divider Line

TW Tech Glossary - Misplaced your bible? Well here it is - Tech Glosasary! This truly took a while to complete and should be used by all from beginners to advance techies.
Divider Line

Software Engineering Phases - Software Engineering PhasesThere are four fundamental phases in most, if not all, software engineering methodologies. These phases are analysis, design, implementation, and testing. These phases address what is to be built, how it will be built, building it, and making it high quality. . These steps together define the cradle-to-grave life cycle of the software project. Obviously, if an action is done many times, it needs to be done correctly and efficiently.
Divider Line

How to be a Programmer - Programing training To be a good programmer is difficult and noble. The hardest part of making real a collective vision of a software project is dealing with one's coworkers and customers. Writing computer programs is important and takes great intelligence and skill. But it is really child's play compared to everything else that a good programmer must do to make a software system that succeeds for both the customer and myriad colleagues for whom she is partially responsible. In this essay I attempt to summarize as concisely as possible those things that I wish someone had explained to me when I was twenty-one.
Divider Line

What Programming Language To Learn - Programming LanguagesOne of the most common questions we hear from individuals hoping to enter the IT industry is, "What programming languages do I need to know?" Obviously this is a complex question, and the answer will depend on what field the questioner is going into. Many programming languages are taught during courses used to obtain a computer information science degree. However, those already in IT know that the greatest skill you can have is to be a jack-of-all-trades. A well-prepared worker can switch between computer programming jobs with only minimal training, thanks to a wide knowledge of multiple programming languages.
Divider Line

Computer Training Excuses - No ExcuseYou wouldn't go to a doctor who had never been to medical school, or hire a lawyer who never studied law. One side-effect of a world advancing as rapidly as ours is that fields are becoming more and more specialized and narrow. People can no longer get by on general knowledge in their careers, something I found out for myself not too long ago. I'd been out of high school for two years, scraping by on my own and picking up scraps of programming as I went. I saw all of the self-taught programmers breaking into the IT industry, and I hoped to do the same. After all, IT is one of the few industries out there where being creative and a quick learner is more important than a degree.
Divider Line

Which is the Easiest Programming Language? - Programming LanguagesIf you have some misconception in mind that the programming languages are easy or hard, I am afraid to say that you are mistaken. To tell you frankly about the programming languages, there is nothing such as easy or tough programming language. The only thing that you need to keep in mind while stepping into the world of programming languages is that which programming language would set your base by giving you in-depth knowledge of programming logics and the basics of programming techniques.
Divider Line

Entering into Programming World - Good Luck ProgrammingOnce you have learned some programming languages, you feel yourself completely prepared to enter into the programming world, and start working on the programming languages that you have learned. Many students also feel that they have learned extra things which might be helpful in their programming careers. The matter of fact is that the real world is entirely different from what you have been taught in the classrooms.
Divider Line

Why Programmers Love the Night - Programming at night One famous saying says that programmers are machines that turn caffeine from coffee and Coca Cola into a programming code. And if you ask a programmer when does he like working the most and when is he most productive - he is probably going to say late at night or early in the morning, that is when he has the greatest energy and concentration to work.
Divider Line

How to Install the Aptana Studio IDE on Windows - Aptana Studio 3IDE (Integrated Development Environment) represents an integrated development environment in which you can develop applications. This tutorial will be useful to all those that considering doing programing...
Divider Line

What is Basic?

Basic stands for Beginner's All-purpose Symbolic Instruction Code. Developed by John Kemeney and Thomas Kurtz in the mid 1960s at Dartmouth College, BASIC is one of the earliest and simplest high-level programming languages. During the 1970s, it was the principal programming language taught to students, and continues to be a popular choice among educators.

There is an ANSI standard for the BASIC language, but most versions of BASIC include many proprietary extensions. Microsoft's popular Visual Basic , for example, adds many object-oriented feature to the standard BASIC.

Recently, many variations of BASIC have appeared as programming , or macro, languages within applications. For example, Microsoft Word and Excel both come with a version of BASIC with which user can write programs to customize and automate these applications.

BASIC ProgrammingWhat is QBasic?

QBasic ("QuickBasic") is a language published by Microsoft. The current (and last) version is 4.5, and version 1.1 is distributed with DOS in place of GW-BASIC.

QBasic is extremely easy to use. Its math functions are especially good, and it's a great "learners language" for schools and other similar institutions. It resembles BASIC in its statements, but is more structured -and- flexible at the same time. For instance, line numbers are not required but can be used - as well as "line labels" with text names. The graphics support 256 color 320 x 200 VGA, and 16-color 640x480 VGA, as well as an array of other graphics cards.

QBasic can be expanded with the use of Quick Libraries (.QLB's) which add routines from Assembler and C. It can also be expanded through structured programming - the re-use of SUBroutines and functions. There are many possibilities. Some QLB examples include QBSVGA, a library which gives QB 4.5 SVGA capabilities - up to 1024x768 and 256+ colors, PLUS animation and sprite routines.


Tips

Did you know you can change the menu text in the Qbasic environment?

Type the following into the Immediate window:

POKE 696,65

Now open the File menu. You'll notice that the letter N of New has been changed to A. Now type the following in the Immediate window:
 

POKE 1686,65

Notice that the letter F of File has changed to an A.

Here is a program to try to find out where the menu titles & choices are:

addr=696
CLS
DO
value%=PEEK(addr) ' Ascii code
char$=CHR$(value%) ' The letter
PRINT "Address: ";addr,"Character";char$
PRINT "Press Esc to quit, or another key to continue."
kbd$=INPUT$(1)
addr=addr+1
LOOP UNTIL kbd$=CHR$(27)

Feel free to keep experimenting with the menu system.

Mathematical tips

Try to use integers(% and #) instead of floating point(! and &) numbers, they are much faster.
When dividing integers use "a \ b" instead of "INT(a / b)"
If you can add numbers("a + a") instead of multiplying("a * 2"), adding is much faster.
Also multiplying("x * x") is faster than raising a number to a power("x ^ 2").
To find out if a number is odd do "x AND 1", if it returns 1 it is odd.
You could also do "x MOD 2" to find out if a number is odd, if it returns 1 it is odd.
To find out if a number is divisible by another number do "x % y", if it returns 0 x is divisible by y.
Instead of doing "b = x : x = y : y = b" to swap the numbers x and y, do "SWAP x, y"

5 impotent Datatypes

INTEGER

2-byte value in the range -32,768 through 32,767

LONG

4-byte value in the range -2,147,483,648 through 2,147,483,647

SINGLE

4-byte value with 7 digits of significance

DOUBLE

8-byte value with 15 digits of significance

STRING

A sequence of up to 32,767 characters

You can see above the different types of datatypes there are, but let's now look at a programming example. The following program returns some different results depending on the datatypes.

DIM number1 AS INTEGER
DIM number2 AS INTEGER
DIM yourname AS STRING
DIM number3 AS LONG
DIM number4 AS SINGLE
number1 = 32767
number2 = 43
yourname = "Freddy Bloggs"
number3 = 1443233
number4 = 23435667
PRINT number1
PRINT number2
PRINT yourname
PRINT number3
PRINT number4

Variable Names

A QBasic variable name can contain up to 40 characters (letters, numbers, and periods). In addition, you can append one of the following characters to the name to indicate a specific variable type:

% = Integer variable

& = Long integer variable

! = Single-precision variable

# = Double-precision variable

$ = String variable

Names reserved for Basic commands, functions, or operator names cannot be used as variable names. QBasic is not case sensitive. (For example, the variable names count and COUNT are identical to QBasic.)

To extend th e above theory, you could use these variable types like the below example.

number1% = 32767
number2% = 43
yourname$ = "Freddy Bloggs"
number3& = 1443233
number4! = 23435667
PRINT number1%
PRINT number2%
PRINT yourname$
PRINT number3&
PRINT number4!

So instead of actually specifying the type of datatype you would like to variable to as in the first example, you could use the technique in the second example which actually compacts your program.

ARRAYS

To create a QBasic array, use the following syntax:

DIM arrayname ([start_index TO] last_ index[, ?]) AS typename

start_index TO last_index is the range of index values for the elements of the array. If you omit a starting index, QBasic uses the value 0 by default. (The OPTION BASE statement allows you to set the default starting index.) The three periods indicate that QBasic supports multidimensional arrays.

You can specify up to 60 dimensions. For example, the following statement creates a two-dimensional array with 3 rows and 5 columns:

DIM box (1 TO 3, 1 TO 5) AS INTEGER

typename is the type of the array: INTEGER, LONG, SINGLE, DOUBLE or STRING. The maximum array size is 64KB. Valid index values range from -32,768 to 32,767.

Symbolic Constants

QBasic allows your programs to reference symbolic constants that you define with the CONST statement:

CONST size% = 255

QBasic constant names follow the naming conventions used for variables. Once you define a constant, you can use it throughout your program:

DIM a(size%) AS INTEGER

In so doing, you simplify future changes to your program and improve the program's readability.

Label Names

For programs that don't use line numbers, QBasic allows you to use labels to reference specific locations in the program. A label name can contain up to 40 characters. Label names must begin with a letter and must end with a colon( : ). Names reserved for Basic commands, functions, or operator names cannot be used as label names, QBasic is not case sensitive. (For example, the label Handler: and HANDLER: are identical to Qbasic.)

Subroutines and Functions

The maximum QBasic subroutine size is 64 KB. You can pass up to 60 parameters to a subroutine. You can create subroutines and functions using the SUB and FUNCTION statements.

Data files

QBasic data files can be as large as the available space on your disk. You can use the file numbers 1 to 255. The largest possible record size for a random-access file is 32,767 bytes. The largest possible record number is 2,147,483,647.

Sorting: Bubble Sort

CONT FALSE = 0
CLS
DIM a(100)
LOCATE 1, 1
FOR x = 1 TO UBOUND(a)
a(x) = INT(RND * 100) + 1
PRINT a(x);
NEXT
Limit = UBOUND(a)
DO
Switch = FALSE
FOR x = 1 TO (Limit - 1)
IF a(x) > a(x + 1) THEN
SWAP a(x), a(x + 1)
Switch = x
END IF
NEXT x
' Sort on next pass only to where the last switch was made:
Limit = Switch
LOOP WHILE Switch
LOCATE 10, 1
FOR x = 1 TO UBOUND(a)
PRINT a(x);
NEXT
Creating Delays in Qbasic
The SLEEP statement suspend the program execution for a specified time measured in seconds. If you want to use a more accurate delay use the TIMER function. The procedure "delay" suspends your program execution in terms of milliseconds.
DECLARE SUB delay (duration!)
SUB delay (duration AS SINGLE)
tim = TIMER
DO
LOOP UNTIL (TIMER - tim + 86400) - (INT((TIMER - tim + 86400) / 86400) * 86400) > duration
END SUB
Monitoring how long a key has been pressed
This piece of code calculates the time a key is pressed until it is released.
DIM tim AS SINGLE
DIM b AS INTEGER, c AS INTEGER
DO
'Catch the spacebar
getkey$ = INKEY$
'The ASCII code for the spacebar is 32. Change it if you want to monitor another key.
IF getkey$ = CHR$(32) THEN
b = INP(&H60)
tim = TIMER
DO
c = INP(&H60)
v$ = INKEY$
LOOP UNTIL c <> b
PRINT "delay equals to : "; TIMER - tim
END IF
LOOP UNTIL getkey$ <> ""


Did You Know?

  • QBasic is found on the Win95 CD-ROM in the 'OTHER\OLDMSDOS' directory. All you have to do is copy QBASIC.EXE and QBASIC.HLP to your hard drive from this directory, and you're set!

  • In the '70s when Bill Gates and Paul Allen licensed their BASIC to M.I.T.S. for the Altair. This version took a total of 4K memory including the code and data used for a source code.

  • The first Basic considered to be a full language implemented on a microprocessor was Li Chen Wang's "Tiny Basic", which appeared in Dr. Dobbs.

  • Basic was the first product sold by Microsoft corporation, and also the first major case of software piracy - It was copied widely even before Microsoft made it available (Billy Boy Gates lost track of a copy on paper tape during a computer show).




Premium Tutorials & Screencasts


AlarmPlanet: Web's First Home Security Portal

Follow Us on TwitterFollow Us on TwitterFollow Us on Facebook


Partners Links