Saturday, November 19, 2011

my latest photo

This is my latest photo. I hope you like it because I like this photo very much..... 

Tuesday, October 11, 2011

Happy Vijaya dashami 2068
















Monday, October 10, 2011




Thursday, April 28, 2011

Q-BASIC

Introduction

This tutorial is laid out in what I believe to be a good order for learning QBasic. I have been frustrated often because the QBasic help menu has not explained things to me well enough. If you have seen the QBasic help menus you'll know that they use very formal language. This tutorial was written more casually, so you should be able to catch on fairly quickly. I hope that this document helps you get what you want out of QBasic.

Command: PRINT

PRINT can be used in many ways. If you were to use PRINT without any parameters, it would simply cause the cursor to move down one row and return to the left side of the screen (also known as a carriage return). This does us not much good, but now you know. To print the word QBASIC on the screen, you would need PRINT "QBASIC" in your program- pretty easy. You may also print numbers on the screen in two different ways. One is PRINT "2000". The other way is PRINT 2000. The first way is printing 2000 as text, while the second is printing it as a number. Printing numbers in this way is not very practical, but it is more often used for displaying the values that variables have been assigned. Later on in the section about variables, I will show you how to use a variable in the PRINT command.

PRINT "This is how to use the PRINT command"
PRINT
PRINT "It's amazing!"
PRINT 2000
PRINT "The number is: "; 2000


Output:
This is how to use the PRINT command


It's amazing!
2000
The number is: 2000
Command: CLS

Once we have a bunch of words on the screen, they can get rather annoying. Well, what do you know! There is something you can do about it. CLS is probably the simplest command in QBasic. There is one way to use the CLS command; type it in. When QBasic executes this command, the screen is cleared and the cursor returns to the top left corner of the screen.

PRINT "This line of text is going to be erased"
CLS
PRINT "Only these words are on the screen"


Output:(At top left corner of screen)
Only these words are on the screen
Command: BEEP

Of course, there is much more to programming than text. The BEEP command when in a program makes the speaker make a tone for about a half a second. This is a very old command, but it works for teaching. You will learn how to produce different frequencies and lengths of sound later.

CLS
PRINT "The speaker is going to beep!"
BEEP
PRINT "Cool!"
Output:
The speaker is going to beep!
(speaker emits tone)
Cool!
Tool: REM

Before we get any further, it would be a good idea to know how to explain your programs within the source code without affecting the program. You can do this using the REM (remark) command. To make a remark in your program type REM followed by any text that you want. REM causes QBasic to ignore everything on the line that is to the right of it. Take a look at the example.

REM This program demonstrates the REM command
PRINT "The REM command won't work if inside quotes"
REM Here is another remark line
REM You can have many remarks in a program


Output:
The REM command won't work if inside quotes
Command: END

In the case that you want to stop the running of your program even though there are more lines of commands (this is applicable mainly in debugging), the END command is what you need. END will trick QBasic into thinking that there are no more lines to run and it will return you to the editor. You may not use this command for some time, but it is just something to know.

REM The END command will stop the program"
PRINT "First line of text"
PRINT "Second line of text"
END
PRINT "Third line of text
PRINT "The third and fourth lines won't be displayed"
REM Oh well!


Output:
First line of text
Second line of text
Command: GOTO

Now we get into the more complex part of QBasic. The GOTO command will make QBasic run lines of commands in different order than what they are written. At the moment, there is not much use for this, but later you will see that it is very important. The GOTO command requires that you have a destination for it. You have to tell it where you want the program execution to go. This is called a line number. In earlier versions of Basic, every line in the program was required to have a line number. This is not so any more. In QBasic, the line number (or label) can be either a number, a word, of a combination of the two as long as you only have that combination as a label once in the program.

PRINT "Line of text #1"
GOTO 10
PRINT "This line gets skipped"
10:
PRINT "Line of text #2"
PRINT
GOTO abcd
PRINT "QBasic will not execute this line either"
abcd:
PRINT "Line of text #3"

Output:
Line of text #1
Line of text #2


Line of text #3
As you can see, each label must be followed by a : in order for it to work. Also, the labels "10" and "abcd" only appeared as labels once in the program. This does not mean that you may only have one GOTO 10 command in the program; you can have as many as you need. This will be demonstrated later.

Concept: Variables

Before learning any more commands, you now must learn about variables. A variable in it's simplest form is a letter or word that represents a number that it has been assigned. Examples of QBasic numerical variables are: x, y, num, hjk1, d45. (A variable may contain numbers as long as it starts with a letter.) QBasic variables are NOT case sensitive. For example: x = X and hjk1 = hJK1. Once a variable has been assigned a number, it will be the equivalent to that number.

REM Syntax for assigning variables
x = 25
q = 4
op1 = 17


(There is no output for this program)
Once these lines have been executed, the variable x, y, and op1 will be numerically equivalent to 25, 4, 17 respectively. But I can't do anything with them yet. Well, Remember before when I talked about using variables in the print command? This is where they fit in. In the example x and q are assigned values using the = sign and then using PRINT the values are displayed onto the screen.

CLS
x = 25
q = 4
PRINT x
PRINT q


Output:
25
4
Command: IF. . .THEN. . .ELSE

The "IF...THEN...ELSE" command bring variety into a program. It is the main controller of program line execution (the way the program runs). When an IF...THEN statement is executed, QBasic evaluates the criteria for decision and directs the program flow accordingly. Look at this example line of code:

IF A = 1 THEN GOTO 100
The criteria for this IF...THEN statement to send the program flow to line 100 is for the variable `A' to hold a value of 1. If, in this case, the value of `A' does not equal 1, the program would continue execution onto the following line of the program. Now we add the ELSE part of the command:

IF B = 1 THEN GOTO 100 ELSE GOTO 200
The ELSE part of this command is optional. The reason for it is to allow for the criteria of the IF...THEN statement not to be met. In the above example, let us say that B = 3. Since B does not equal 1, the command after THEN (GOTO 100) is not executed but rather the one after ELSE (GOTO 200). The completely literal description for this IF...THEN statement is: If the value of `B' is 1, continue running the program at line 100, but if NOT, continue to line 200 instead. You must realize that the GOTO command is not the only one that can be used in this statement. Any other command can be executed via IF...THEN statements such as CLS, BEEP, PRINT, etc. Here are a few of the formats of different kinds of variables in IF...THEN statments:

IF A = 1 THEN... If `A' equals 1
IF A > 1 THEN... is greater than 1
IF A <= 1 THEN... is less than or equal to 1
IF A <> 1 THEN... does not equal one
Some examples of using the IF...THEN command for something other than GOTO:

IF A = 1 THEN PRINT "Well what do you know? A = 1"
IF A = 2 THEN BEEP
IF A = 3 THEN N = 15
If you want, you could copy the above three examples and put them into a program. When QBasic gets to those lines, they evaluate the value of `A' and choose what commands to execute. If `A' is 1 it prints a message, if 2 it beeps, if 3 it sets that value of `N' to 15. This may sound complex at first, but once you learn it, the concept is really quite simple.

Command: FOR. . .NEXT

One of the most time saving commands (both programming time and processing time) is the FOR...NEXT command. A single FOR...NEXT loop involves only one variable, but that one variable has very valuable characteristics. The syntax for the command is:

FOR variable = beginning_number TO end_number
.
.
.
NEXT variable
For example:

FOR T = 1 to 5
PRINT T
NEXT T


Output:
1
2
3
4
5
The variable `T' was put into a loop, increasing by 1 for each time the cycle was run. Any commands inside the FOR...NEXT loop that depend on the variable `T' are affected. In the above example, as you can see, when the PRINT command displayed the value of `T' it had incremented by one for each time around the loop. One of the valuable aspects of FOR...NEXT is in animation. That is way more advanced, but just as an example, the FOR...NEXT loop makes it easy to "drag" a picture across the screen with a simple loop that changes its coordinates. Sound tricky? Sorry if it confuses you. Never mind then.

If you are the type that always wants to know more, here is something for you. To get a variable to count downward, do this:

FOR T = 10 to 1 STEP -1
.
.
NEXT T
Or you could get it to count up (or down using a `-' sign) by a specific increment like this:

FOR T = 1 to 100 STEP 10
.
.
NEXT T
Conclusion

This tutorial can merely instruct you on the basics of QBasic. There are hundreds of commands/functions used in QBasic. Refer to the Advanced Tutorial for learning specifics on individual QBasic commands. The Advanced Tutorial is index-based to make the locating of specific information easier

Sunday, April 17, 2011

Happy new year

नयाँ वर्ष २०६८सालको हार्दिक मंगलमय कामना व्यक्त गर्दछु।