This program let you choose your drives and folders and displays all the text files from the chosen folder in a list box. You need to place a combo box, a DriveListBox, a DirListbox and a Listbox into your form.
The code is as follows:
Private Sub Form_Load()
Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2
Combo1.Text = "All Text Files"
Combo1.AddItem "All Text Files"
Combo1.AddItem "All Files"
End Sub
Private Sub Combo1_Change()
If ListIndex = 0 Then
File1.Pattern = ("*.txt")
Else
Fiel1.Pattern = ("*.*")
End If
End Sub
Thursday, May 27, 2010
Scientific Calculator
The value of pi is now obtained by using the Atn function (Arc Tangent). We know that Tan(pi/4)=1, so Atn(1)=pi/4, therefore pi=Atn(1)*4. By using this function, we will obtain a more accurate value of pi.
In this project, we shall also limit the numbers to be less than 30 digit. If any user enters a number with more than 30 digits, an error message "data overflow" will be shown.
In this project, we shall also limit the numbers to be less than 30 digit. If any user enters a number with more than 30 digits, an error message "data overflow" will be shown.
Excel VBA Objects
Most programming languages today deal with objects, a concept called object oriented programming. Although Excel VBA is not a truly object oriented programming language, it does deal with objects. VBA object is something like a tool or a thing that has certain functions and properties, and can contain data. For example, an Excel Worksheet is an object, cell in a worksheet is an object, range of cells is an object, font of a cell is an object, a command button is an object, and a text box is an object and more.
An Excel VBA object has properties and methods. Properties are like the characteristics or attributes of an object. For example, Range is an Excel VBA object and one of its properties is value. We connect an object to its property by a period(a dot or full stop). The following example shows how we connect the property value to the Range object.
An Excel VBA object has properties and methods. Properties are like the characteristics or attributes of an object. For example, Range is an Excel VBA object and one of its properties is value. We connect an object to its property by a period(a dot or full stop). The following example shows how we connect the property value to the Range object.
InputBox and MsgBox
The InputBox function and the MsgBox function are two very important functions in VB. The InputBox function is to accept data from the user and the MsgBox function is to output data to the user. They are considered a form of simple dialog box for the user to interact with the VB program.
The Inputbox function with return a value of any data type, which means the value could be integer,single, string, boolean ,data and more. Normally you need to declare the data type for values to be accepted in the Inputbox.
Example:
Dim StudentName As String
Dim Mark As Integer
StudentName=InputBox("Enter Student Name")
Mark=InputBox("Enter Student Mark")
The Inputbox function with return a value of any data type, which means the value could be integer,single, string, boolean ,data and more. Normally you need to declare the data type for values to be accepted in the Inputbox.
Example:
Dim StudentName As String
Dim Mark As Integer
StudentName=InputBox("Enter Student Name")
Mark=InputBox("Enter Student Mark")
VB Mathematical Functions
Mathematical functions are very useful and important in programming because very often we need to deal with mathematical concepts in programming such as chance and probability, variables, mathematical logics, arithematic calculations, coordinates system, time intervals and more. Some of the common mathematical functions in Visual Basic are Rnd, Sqr, Int, Abs, Exp, Log, Sin, Cos, Tan , Atn, Fix and Round.
For example, Rnd is very useful when we deal with the concept of chance and probability. The Rnd function returns a random number between 0 and 1. In Example 1.
For example, Rnd is very useful when we deal with the concept of chance and probability. The Rnd function returns a random number between 0 and 1. In Example 1.
Monday, May 24, 2010
The use of Option Exlicit in VB program
The use of Option Explicit is to help us to track errors in the usage of variable names within a VB program code. For example, if we commit a typo, Visual Basic will pop up an error message “variable not defined”. Indeed, Option Explicit forces the programmer to declare all the variables using the Dim keyword. It is a good practice to use Option Explicit because it will prevent us from using incorrect variable names due to typing errors, especially when the program gets longer. With the usage of Option Explicit, it will save our time in debugging our programs. For example, In the following program, a typo was committed, EmployeID, which was declared as EmployeeID.
Option Explicit
Private Sub Command1_Click()
Dim EmployeeID As String
EmployeID = "John"
Text1.Text = EmployeeID
End Sub
When you run the program, a dialog box with an error message 'Variable not defined" will appear ,when you click the OK button, it will show the highlighted typo, enabling us to correct the mistake.
Option Explicit
Private Sub Command1_Click()
Dim EmployeeID As String
EmployeID = "John"
Text1.Text = EmployeeID
End Sub
When you run the program, a dialog box with an error message 'Variable not defined" will appear ,when you click the OK button, it will show the highlighted typo, enabling us to correct the mistake.

Thursday, May 20, 2010
Adding Menus to Your VB Application
Most windows programs provide menu bar for easy navigation and control. The most common items are like File, Edit, View, Tools, Help and more. Each item on the main menu bar also provide a list of options in the form of a pull-down menu.
Adding menu bar is easily accomplished in Visual Basic. To start adding menu items to your application, open your file and then click on Tools in the menu bar of the Visual Basic IDE, then select Menu Editor. When you click on the Menu Editor, the following window will appear. In the Menu Editor, key in the items such as File, Edit, View and etc
Adding menu bar is easily accomplished in Visual Basic. To start adding menu items to your application, open your file and then click on Tools in the menu bar of the Visual Basic IDE, then select Menu Editor. When you click on the Menu Editor, the following window will appear. In the Menu Editor, key in the items such as File, Edit, View and etc
Monday, May 10, 2010
Creating a Calender in VB6
Creating a calender in VB6 is a relatively simple task. There is no need to write your own code. What you do is insert the calender component of an ActiveX Control that comes with VB6 into the form. However, the ActiveX control is not included into the toolbox by default, you have to add it with the following steps:
1. From the Project menu, choose Components
2. In the Components dialog, select Microsoft Windows Common Controls 2-6.0 and click OK.
The Calender control will be added to the toolbox.
2. In the Components dialog, select Microsoft Windows Common Controls 2-6.0 and click OK.
The Calender control will be added to the toolbox.
3. Select the MonthView control icon from the Visual Basic ToolBox
4. Drag the MonthView control into the form.
Now run the program and there you have your very own calender!
There is another way to create a calender in VB. This time you use the Microsoft Calender Control 11. As this is also an ActiveX control, it is not launched into the toolbox by default, you need to add it in using the method similar to the above example.
1. From the Project menu, choose Components
2. In the Components dialog, select Microsoft Calender Control 11 and click OK.
Now the calender control will appear in the toolbox. Drag it into the form and press F5 to run the program, and you have your calender as shown below:
1. From the Project menu, choose Components
2. In the Components dialog, select Microsoft Calender Control 11 and click OK.
Now the calender control will appear in the toolbox. Drag it into the form and press F5 to run the program, and you have your calender as shown below:
Try them out yourself. Everyone can do it!
Saturday, May 8, 2010
Function to calculate the sum of numbers between 1 and 100 that are divisible by 4
Function SumOfNum(ByVal x As Integer) As Integer
Dim i As Integer
SumOfNum = 0
For i = 1 To 100
If i Mod x = 0 Then
SumOfNum = SumOfNum + i
Else
SumOfNum = SumOfNum
End If
Next i
End Function
Private Sub Command1_Click()
Dim w As Integer
x = Text1.Text
w = SumOfNum(x)
Label1.Caption = w
End Sub
Dim i As Integer
SumOfNum = 0
For i = 1 To 100
If i Mod x = 0 Then
SumOfNum = SumOfNum + i
Else
SumOfNum = SumOfNum
End If
Next i
End Function
Private Sub Command1_Click()
Dim w As Integer
x = Text1.Text
w = SumOfNum(x)
Label1.Caption = w
End Sub
Friday, May 7, 2010
Temperature Converter

With winter around and daily temperature change has become a concern for many people especially those who travel a lot. They are constantly checking out temperature readings everyday However, different parts of the world often use different temperature scales, some of them use Fahrenheit and some use Celsius, so the readings can be confusing. Therefore, it is nice if we have a program that can convert Celsius to Fahrenheit and vice versa. And I have done just that using Visual Basic 6. The code is like this:
Private Sub Command1_Click()
Dim cel, Fah As Single
cel = Val(txtC.Text)
Fah = Val(txtF.Text)
If txtC.Text <> "" And txtF = "" Then
Fah = ((9 / 5) * cel + 32)
txtF.Text = Round(Fah, 1)
Else
cel = (5 / 9) * (Fah - 32)
txtC.Text = Round(cel, 1)
End If
End Sub
Private Sub Command2_Click()
txtC.Text = ""
txtF.Text = ""
End Sub
Wednesday, May 5, 2010
Changing Background and Foreground Color at Run Time for VB6
It is very easy to change background color and foreground color at run time, just use the code below:
Private Sub Form_Load()
Form1.Show
Form1.BackColor = vbRed
Form1.ForeColor = vbBlue
Form1.Print "Foreground"
End Sub
Private Sub Form_Load()
Form1.Show
Form1.BackColor = vbRed
Form1.ForeColor = vbBlue
Form1.Print "Foreground"
End Sub
Friday, April 30, 2010
Creating VBA Functions For MS Excel
15.1 The Needs to Create VBA Functions in MS-Excel
You can create your own functions to supplement the built-in functions in Microsoft Excel spreadsheet, which are quite limited in some aspects. These user-defined functions are also called Visual Basic for Applications functions, or simply VBA functions. They are very useful and powerful if you know how to program them properly. One main reason we need to create user defined functions is to enable us to customize our spreadsheet environment for individual needs. For example, we might need a function that could calculate commissions payment based on the sales volume, which is quite difficult if not impossible by using the built-in functions alone. The code for VBA is illustrated on the right.
You can create your own functions to supplement the built-in functions in Microsoft Excel spreadsheet, which are quite limited in some aspects. These user-defined functions are also called Visual Basic for Applications functions, or simply VBA functions. They are very useful and powerful if you know how to program them properly. One main reason we need to create user defined functions is to enable us to customize our spreadsheet environment for individual needs. For example, we might need a function that could calculate commissions payment based on the sales volume, which is quite difficult if not impossible by using the built-in functions alone. The code for VBA is illustrated on the right.
Table 15.1: Commissions Payment Table
Sales Volume($) | Commissons |
<500 | 3% |
<1000 | 6% |
<2000 | 9% |
<5000 | 12% |
>5000 | 15% |
Wednesday, April 28, 2010
Creating User-Defined Functions
14.1 Creating Your Own FunctionThe general format of a function is as follows:
Public Function functionName (Arg As dataType,..........) As dataType
or
Private Function functionName (Arg As dataType,..........) As dataType
* Public indicates that the function is applicable to the whole project and
Private indicates that the function is only applicable to a certain module or procedure.
Example 14.1
In this example, a user can calculate the future value of a certain amount of money he has today based on the interest rate and the number of years from now, supposing he will invest this amount of money somewhere .The calculation is based on the compound interest rate.
Public Function functionName (Arg As dataType,..........) As dataType
or
Private Function functionName (Arg As dataType,..........) As dataType
* Public indicates that the function is applicable to the whole project and
Private indicates that the function is only applicable to a certain module or procedure.
Example 14.1
In this example, a user can calculate the future value of a certain amount of money he has today based on the interest rate and the number of years from now, supposing he will invest this amount of money somewhere .The calculation is based on the compound interest rate.
Saturday, April 24, 2010
Formatting Functions
Formatting output is a very important part of programming so that the data can be presented systematically and clearly to the users. Data in the previous lesson were presented fairly systematically through the use of commas and some of the functions like Int, Fix and Round. However, to have better control of the output format, we can use a number of formatting functions in Visual basic.
The three most common formatting functions in VB are Tab, Space, and Format
(i) The Tab function
Tab (n); x
The item x will be displayed at a position that is n spaces from the left border of the output form. There must be a semicolon in between Tab and the items you intend to display (VB will actually do it for you automatically).
Example1
Private Sub Form_Activate
Tuesday, April 20, 2010
String Manipulation Functions
In this lesson, we will learn how to use some of the string manipulation function such as Len, Right, Left, Mid, Trim, Ltrim, Rtrim, Ucase, Lcase, Instr, Val, Str ,Chr and Asc.
(i)The Len Function
The length function returns an integer value which is the length of a phrase or a sentence, including the empty spaces. The format is
Len (“Phrase”)
For example,
Len (VisualBasic) = 11 and Len (welcome to VB tutorial) = 22
The Len function can also return the number of digits or memory locations of a number that is stored in the computer. For example,
Friday, April 9, 2010
Mathematical Functions
The mathematical functions are very useful and important in programming because very often we need to deal with mathematical concepts in programming such as chance and probability, variables, mathematical logics, calculations, coordinates, time intervals and etc. The common mathematical functions in Visual Basic are Rnd, Sqr, Int, Abs, Exp, Log, Sin, Cos, Tan , Atn, Fix and Round.
(i) Rnd is very useful when we deal with the concept of c
(i) Rnd is very useful when we deal with the concept of c
Wednesday, April 7, 2010
Looping
Visual Basic allows a procedure to be repeated many times as long as the processor until a condition or a set of conditions is fulfilled. This is generally called looping . Looping is a very useful feature of Visual Basic because it makes repetitive works easier. There are two kinds of loops in Visual Basic, the Do...Loop and the For.......Next loop
9.1 Do Loop
The formats are
a) Do While condition
Block of one or more VB statements
Loop
b) Do
Block of one or more VB statements
Loop While condition
c) Do Until condition
Block of one or more VB statements
Loop
d) Do
Block of one or more VB statements
Loop Until condition
9.2 Exiting the Loop
Sometime we need exit to exit a loop prematurely because of a certain condition is fulfilled. The syntax to use is known as Exit Do. You can examine Example 9.2 for its usage.
9.3 For....Next Loop
The format is:
For counter=startNumber to endNumber (Step increment)
One or more VB statements
Next
Please refer to example 9.3a,9.3b and 9.3 c for its usage.Sometimes the user might want to get out from the loop before the whole repetitive process is executed, the command to use is Exit For. To exit a For….Next Loop, you can place the Exit Forstatement within the loop; and it is normally used together with the If…..Then… statement. Let’s examine example 9.3 d.
Example 9.1
Do while counter <=1000
num.Text=counter
counter =counter+1
Loop
* The above example will keep on adding until counter >1000.
The above example can be rewritten as
Do
num.Text=counter
counter=counter+1
Loop until counter>1000
Example 9.2
Dim sum, n As Integer
Private Sub Form_Activate()
List1.AddItem "n" & vbTab & "sum"
Do
n = n + 1
Sum = Sum + n
List1.AddItem n & vbTab & Sum
If n = 100 Then
Exit Do
End If
Loop
End Sub
Explanation
In the above example, we compute the summation of 1+2+3+4+……+100. In the design stage, you need to insert a ListBox into the form for displaying the output, named List1. The program uses the AddItem method to populate the ListBox. The statement List1.AddItem "n" & vbTab & "sum" will display the headings in the ListBox, where it uses the vbTab function to create a space between the headings n and sum.
9.1 Do Loop
The formats are
a) Do While condition
Block of one or more VB statements
Loop
b) Do
Block of one or more VB statements
Loop While condition
c) Do Until condition
Block of one or more VB statements
Loop
d) Do
Block of one or more VB statements
Loop Until condition
9.2 Exiting the Loop
Sometime we need exit to exit a loop prematurely because of a certain condition is fulfilled. The syntax to use is known as Exit Do. You can examine Example 9.2 for its usage.
9.3 For....Next Loop
The format is:
For counter=startNumber to endNumber (Step increment)
One or more VB statements
Next
Please refer to example 9.3a,9.3b and 9.3 c for its usage.Sometimes the user might want to get out from the loop before the whole repetitive process is executed, the command to use is Exit For. To exit a For….Next Loop, you can place the Exit Forstatement within the loop; and it is normally used together with the If…..Then… statement. Let’s examine example 9.3 d.
Example 9.1
Do while counter <=1000
num.Text=counter
counter =counter+1
Loop
* The above example will keep on adding until counter >1000.
The above example can be rewritten as
Do
num.Text=counter
counter=counter+1
Loop until counter>1000
Example 9.2
Dim sum, n As Integer
Private Sub Form_Activate()
List1.AddItem "n" & vbTab & "sum"
Do
n = n + 1
Sum = Sum + n
List1.AddItem n & vbTab & Sum
If n = 100 Then
Exit Do
End If
Loop
End Sub
Explanation
In the above example, we compute the summation of 1+2+3+4+……+100. In the design stage, you need to insert a ListBox into the form for displaying the output, named List1. The program uses the AddItem method to populate the ListBox. The statement List1.AddItem "n" & vbTab & "sum" will display the headings in the ListBox, where it uses the vbTab function to create a space between the headings n and sum.
Example 9.3 a For counter=1 to 10 display.Text=counter Next | Example 9.3 b For counter=1 to 1000 step 10 counter=counter+1 Next |
Example 9.3 c For counter=1000 to 5 step -5 counter=counter-10 Next *Notice that increment can be negative | Example 9.3 d Private Sub Form_Activate( ) For n=1 to 10 If n>6 then Exit For End If Else Print n End If End Sub |
Saturday, April 3, 2010
Introduction to VB Built-in Functions
A function is similar to a normal procedure but the main purpose of the function is to accept a certain input from the user and return a value which is passed on to the main program to finish the execution. There are two types of functions, the built-in functions (or internal functions) and the functions created by the programmers
the general format of a function is
FunctionName (arguments)
The arguments are values that are passed on to the function.
FunctionName (arguments)
The arguments are values that are passed on to the function.
In this lesson, we are going to learn two very basic but useful internal functions of Visual basic , i.e. the MsgBox( ) and InputBox ( ) functions. You can also learn about mathematical functions, formatting functions and string manipulation functions by clicking the links at the end of this page.
Saturday, March 27, 2010
Select Case....End select Control Structure
In the previous lesson, we have learned how to control the program flow using the If...ElseIf control structure. In this chapter, you will learn another way to control the program flow, that is, the Select Case control structure. However, the Select Case control structure is slightly different from the If....ElseIf control structure . The difference is that the Select Case control structure basically only make decision on one expression or dimension (for example the examination grade) while the If ...ElseIf statement control structure may evaluate only one expression, each If....ElseIf statement may also compute entirely different dimensions. Select Case is preferred when there exist many different conditions because using If...Then..ElseIf statements might become too messy.
The format of the Select Case control structure is show below:
The format of the Select Case control structure is show below:
Wednesday, March 17, 2010
Controling Program Flow
In previous lessons, we have learned how to create Visual Basic code that can accept input from the user and display the output without controlling the program flow. In this chapter, you will learn how to crreate VB code that can make decision when it process input from the user, and control the program flow in the process. Decision making process is an important part of programming because it can help to solve practical problems intelligently so that it can provide useful output or feedback to the user. For example, we can write a program that can ask the computer to perform certain task until a certain condition is met.
7.1 Conditional Operators
To control the VB program flow, we can use various conditional operators.
Wednesday, March 10, 2010
Working With Variables
6.1 Assigning Values to Variables
After declaring various variables using the Dim statements, we can assign values to those variables. The general format of an assignment is Variable=Expression The variable can be a declared variable or a control property value. The expression could be a mathematical expression, a number, a string, a Boolean value (true or false) and more. The following are some examples:
firstNumber =100
secondNumber =firstNumber-99
userName ="John Lyan"
userpass.Text = password
Label1.Visible = True
Command1.Visible = false
Label4.Caption = textbox1.Text
ThirdNumber = Val(usernum1.Text)
total = firstNumber + secondNumber+ThirdNumber
After declaring various variables using the Dim statements, we can assign values to those variables. The general format of an assignment is Variable=Expression The variable can be a declared variable or a control property value. The expression could be a mathematical expression, a number, a string, a Boolean value (true or false) and more. The following are some examples:
firstNumber =100
secondNumber =firstNumber-99
userName ="John Lyan"
userpass.Text = password
Label1.Visible = True
Command1.Visible = false
Label4.Caption = textbox1.Text
ThirdNumber = Val(usernum1.Text)
total = firstNumber + secondNumber+ThirdNumber
Sunday, March 7, 2010
Managing Visual Basic Data
There are many types of data that we come across in our daily life. For example, we need to handle data such as names, addresses, money, date, stock quotes, statistics and more everyday. Similarly in Visual Basic, we have to deal with all sorts of of data, some can be mathematically calculated while some are in the form of text or other forms. VB divides data into different types so that it is easier to manage when we need to write the code involving those data.
5.1 Visual Basic Data Types
Visual Basic classifies the information mentioned above into two major data types, they are the numeric data types and the non-numeric data types.
5.1.1 Numeric Data Types
Numeric data types are types of data that consist of numbers, which can be computed mathematically with various standard operators such as add, minus, multiply, divide and more. Examples of numeric data types are examination marks, height, weight, the number of students in a class, share values, price of goods, monthly bills, fees and others. In Visual Basic, numeric data are divided into 7 types,
5.1 Visual Basic Data Types
Visual Basic classifies the information mentioned above into two major data types, they are the numeric data types and the non-numeric data types.
5.1.1 Numeric Data Types
Numeric data types are types of data that consist of numbers, which can be computed mathematically with various standard operators such as add, minus, multiply, divide and more. Examples of numeric data types are examination marks, height, weight, the number of students in a class, share values, price of goods, monthly bills, fees and others. In Visual Basic, numeric data are divided into 7 types,
Saturday, February 27, 2010
Writing the Code
Each control or object in VB can usually run many kinds of events or procedures; these events are listed in the dropdown list in the code window that is displayed when you double-click on an object and click on the procedures’ box(refer to Figure 2.3). Among the events are loading a form, clicking of a command button, pressing a key on the keyboard or dragging an object and more. For each event, you need to write an event procedure so that it can perform an action or a series of actions
To start writing an event procedure, you need to double-click an object. For example, if you want to write an event procedure when a user clicks a command button, you double-click on the command button and an event procedure will appear as shown in Figure 2.1. It takes the following format:
Private Sub Command1_Click
(Key in your program code here)
End Sub
Friday, February 19, 2010
Working With Controls
3.1 The Control Properties
Before writing an event procedure for the control to response to a user's input, you have to set certain properties for the control to determine its appearance and how it will work with the event procedure. You can set the properties of the controls in the properties window or at runtime.
Figure 3.1 on the right is a typical properties window for a form. You can rename the form caption to any name that you like best. In the properties window, the item appears at the top part is the object currently selected (in Figure 3.1, the object selected is Form1). At the bottom part, the items listed in the left column represent the names of various properties associated with the selected object while the items listed in the right column represent the states of the properties. Properties can be set by highlighting the items in the right column then change them by typing or selecting the options available.
For example, in order to change the caption, just highlight Form1 under the name Caption and change it to other names. You may also try to alter the appearance of the form by setting it to 3D or flat. Other things you can do are to change its foreground and background color, change the font type and font size, enable or disable minimize and maximize buttons and etc.
Before writing an event procedure for the control to response to a user's input, you have to set certain properties for the control to determine its appearance and how it will work with the event procedure. You can set the properties of the controls in the properties window or at runtime.
Figure 3.1 on the right is a typical properties window for a form. You can rename the form caption to any name that you like best. In the properties window, the item appears at the top part is the object currently selected (in Figure 3.1, the object selected is Form1). At the bottom part, the items listed in the left column represent the names of various properties associated with the selected object while the items listed in the right column represent the states of the properties. Properties can be set by highlighting the items in the right column then change them by typing or selecting the options available.
For example, in order to change the caption, just highlight Form1 under the name Caption and change it to other names. You may also try to alter the appearance of the form by setting it to 3D or flat. Other things you can do are to change its foreground and background color, change the font type and font size, enable or disable minimize and maximize buttons and etc.
Tuesday, February 16, 2010
Building Visual Basic Applications
2.1 Creating Your First Application
In this section, we will not go into the technical aspects of Visual Basic programming yet, what you need to do is just try out the examples below to see how does in VB program look like:
Example 2.1.1 is a simple program. First of all, you have to launch Microsoft Visual Basic 6. Normally, a default form with the name Form1 will be available for you to start your new project. Now, double click on Form1, the source code window for Form1 as shown in figure 2.1 will appear. The top of the source code window consists of a list of objects and their associated events or procedures. In figure 2.1, the object displayed is Form and the associated procedure is Load.
Figure 2.1 Source Code Window
In this section, we will not go into the technical aspects of Visual Basic programming yet, what you need to do is just try out the examples below to see how does in VB program look like:
Example 2.1.1 is a simple program. First of all, you have to launch Microsoft Visual Basic 6. Normally, a default form with the name Form1 will be available for you to start your new project. Now, double click on Form1, the source code window for Form1 as shown in figure 2.1 will appear. The top of the source code window consists of a list of objects and their associated events or procedures. In figure 2.1, the object displayed is Form and the associated procedure is Load.
Figure 2.1 Source Code Window
Friday, February 12, 2010
Introduction to Visual Basic 6
1.1 The concept of computer programming
Before we begin Visual Basic 6 programming, let us understand some basic concepts of programming. According to Webopedia, a computer program is an organized list of instructions that, when executed, causes the computer to behave in a predetermined manner. Without programs, computers are useless. Therefore, programming means designing or creating a set of instructions to ask the computer to carry out certain jobs which normally are very much faster than human beings can do.
A lot of people think that computer CPU is a very intelligent thing, which in actual fact it is a dumb and inanimate object that can do nothing without human assistant. The microchips of a CPU can only understand two distinct electrical states, namely, the on and off states, or 0 and 1 codes in the binary system. So, the CPU only understands a combinations of 0 and 1 codes, a language which we called machine language. Machine language is extremely difficult to learn and it is not for us laymen to master it easily. Fortunately , we have many smart programmers who wrote interpreters and compilers that can translate human language-like programs such as BASIC into machine language so that the computer can carry out the instructions entered by the users. Machine language is known as the primitive language while Interpreters and compilers like Visual Basic are called high-level language. Some of the high level computer languages beside Visual Basic are Fortran, Cobol, Java, C, C++, Turbo Pascal, and etc .
Before we begin Visual Basic 6 programming, let us understand some basic concepts of programming. According to Webopedia, a computer program is an organized list of instructions that, when executed, causes the computer to behave in a predetermined manner. Without programs, computers are useless. Therefore, programming means designing or creating a set of instructions to ask the computer to carry out certain jobs which normally are very much faster than human beings can do.
A lot of people think that computer CPU is a very intelligent thing, which in actual fact it is a dumb and inanimate object that can do nothing without human assistant. The microchips of a CPU can only understand two distinct electrical states, namely, the on and off states, or 0 and 1 codes in the binary system. So, the CPU only understands a combinations of 0 and 1 codes, a language which we called machine language. Machine language is extremely difficult to learn and it is not for us laymen to master it easily. Fortunately , we have many smart programmers who wrote interpreters and compilers that can translate human language-like programs such as BASIC into machine language so that the computer can carry out the instructions entered by the users. Machine language is known as the primitive language while Interpreters and compilers like Visual Basic are called high-level language. Some of the high level computer languages beside Visual Basic are Fortran, Cobol, Java, C, C++, Turbo Pascal, and etc .
Tuesday, February 2, 2010
==Timeline of Visual Basic (VB1 to VB6)==
* Project 'Thunder' was initiated
* Visual Basic 1.0 (May [[1991]]) was released for Windows at the Comdex/Windows World trade show in Atlanta, Georgia.
[[Image:VBDOS-icon.PNG|right|VB DOS Logo]]
[[Image:Microsoft Visual Basic for MS-DOS (Professional Edition Version1.00).png|thumb|right|300px|Visual Basic for MS-DOS]]
* Visual Basic 1.0 for [[DOS]] was released in September [[1992]]. The language itself was not quite compatible with Visual Basic for Windows, as it was actually the next version of Microsoft's DOS-based BASIC compilers, [[QuickBASIC]] and BASIC Professional Development System. The interface used the [[Character Oriented Windows|"COW" (Character Oriented Windows)]] interface, using [[extended ASCII]] characters to simulate the appearance of a [[Graphical user interface|GUI]].
* Visual Basic 2.0 was released in November [[1992]]. The programming environment was easier to use, and its speed was improved. Notably, forms became instantiable objects, thus laying the foundational concepts of class modules as were later offered in VB4.
* Visual Basic 3.0 was released in the summer of [[1993]] and came in Standard and Professional versions. VB3 included version 1.1 of the [[Microsoft Jet Database Engine]] that could read and write Jet (or Access) 1.x databases.
* Visual Basic 4.0 (August [[1995]]) was the first version that could create [[32-bit]] as well as [[16-bit]] Windows programs. It also introduced the ability to write non-GUI classes in Visual Basic. Incompatibilities between different releases of VB4 caused installation and operation problems. While previous versions of Visual Basic had used VBX controls, Visual Basic now used OLE controls (with files names ending in .OCX) instead. These were later to be named ActiveX controls.
* Visual Basic 1.0 (May [[1991]]) was released for Windows at the Comdex/Windows World trade show in Atlanta, Georgia.
[[Image:VBDOS-icon.PNG|right|VB DOS Logo]]
[[Image:Microsoft Visual Basic for MS-DOS (Professional Edition Version1.00).png|thumb|right|300px|Visual Basic for MS-DOS]]
* Visual Basic 1.0 for [[DOS]] was released in September [[1992]]. The language itself was not quite compatible with Visual Basic for Windows, as it was actually the next version of Microsoft's DOS-based BASIC compilers, [[QuickBASIC]] and BASIC Professional Development System. The interface used the [[Character Oriented Windows|"COW" (Character Oriented Windows)]] interface, using [[extended ASCII]] characters to simulate the appearance of a [[Graphical user interface|GUI]].
* Visual Basic 2.0 was released in November [[1992]]. The programming environment was easier to use, and its speed was improved. Notably, forms became instantiable objects, thus laying the foundational concepts of class modules as were later offered in VB4.
* Visual Basic 3.0 was released in the summer of [[1993]] and came in Standard and Professional versions. VB3 included version 1.1 of the [[Microsoft Jet Database Engine]] that could read and write Jet (or Access) 1.x databases.
* Visual Basic 4.0 (August [[1995]]) was the first version that could create [[32-bit]] as well as [[16-bit]] Windows programs. It also introduced the ability to write non-GUI classes in Visual Basic. Incompatibilities between different releases of VB4 caused installation and operation problems. While previous versions of Visual Basic had used VBX controls, Visual Basic now used OLE controls (with files names ending in .OCX) instead. These were later to be named ActiveX controls.
Thursday, January 28, 2010
==Language features==
Like the BASIC programming language, Visual Basic was designed to be easy to learn and use. The language not only allows programmers to create simple GUI applications, but can also develop complex applications. Programming in VB is a combination of visually arranging components or controls on a form, specifying attributes and actions of those components, and writing additional lines of code for more functionality. Since default attributes and actions are defined for the components, a simple program can be created without the programmer having to write many lines of code. Performance problems were experienced by earlier versions, but with faster computers and native code compilation this has become less of an issue.
Although programs can be compiled into native code executables from version 5 onwards, they still require the presence of runtime libraries of approximately 1 MB in size. This runtime is included by default in Windows 2000 and later, but for earlier versions of Windows like 95/98/NT it must be distributed together with the executable.
Forms are created using drag-and-drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls have attributes and event handlers associated with them. Default values are provided when the control is created, but may be changed by the programmer. Many attribute values can be modified during run time based on user actions or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a keypress in a text box, the program can automatically translate the case of the text being entered, or even prevent certain characters from being inserted.
Although programs can be compiled into native code executables from version 5 onwards, they still require the presence of runtime libraries of approximately 1 MB in size. This runtime is included by default in Windows 2000 and later, but for earlier versions of Windows like 95/98/NT it must be distributed together with the executable.
Forms are created using drag-and-drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls have attributes and event handlers associated with them. Default values are provided when the control is created, but may be changed by the programmer. Many attribute values can be modified during run time based on user actions or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a keypress in a text box, the program can automatically translate the case of the text being entered, or even prevent certain characters from being inserted.
Wednesday, January 27, 2010
==Characteristics present in Visual Basic==
Visual Basic has the following traits which differ from C-derived languages:
* Multiple assignment available in C language is not possible. A = B = C does not imply that the values of A, B and C are equalled. The boolean result of "Is B = C?" is stored in A. The result stored in A could therefore be false(0) or true(-1)
* [[Boolean datatype|Boolean]] constant True has numeric value −1.In most languages, True is mapped to a non zero numeric value, often 1 or -1. This is because the Boolean data type is stored as a 16-bit signed integer. In this construct −1 evaluates to 16 binary 1s (the Boolean value True), and 0 as 16 0s (the Boolean value False). This is apparent when performing a Not operation on a 16 bit signed integer value 0 which will return the integer value −1, in other words True = Not False. This inherent functionality becomes especially useful when performing logical operations on the individual bits of an integer such as And, Or, Xor and Not.[http://vb.mvps.org/tips/Truth.asp Microsoft Basic Logical Expression Evaluation] This definition of True is also consistent with BASIC since the early 1970s Microsoft BASIC implementation and is also related to the characteristics of CPU instructions at the time.
* [[Boolean datatype|Boolean]] constant True has numeric value −1.In most languages, True is mapped to a non zero numeric value, often 1 or -1. This is because the Boolean data type is stored as a 16-bit signed integer. In this construct −1 evaluates to 16 binary 1s (the Boolean value True), and 0 as 16 0s (the Boolean value False). This is apparent when performing a Not operation on a 16 bit signed integer value 0 which will return the integer value −1, in other words True = Not False. This inherent functionality becomes especially useful when performing logical operations on the individual bits of an integer such as And, Or, Xor and Not.[http://vb.mvps.org/tips/Truth.asp Microsoft Basic Logical Expression Evaluation] This definition of True is also consistent with BASIC since the early 1970s Microsoft BASIC implementation and is also related to the characteristics of CPU instructions at the time.
Tuesday, January 26, 2010
==Evolution of Visual Basic==
VB 1.0 was introduced in [[1991]]. The drag and drop design for creating the user interface is derived from a prototype form generator developed by [[Alan Cooper]] and his company called ''Tripod''. Microsoft contracted with Cooper and his associates to develop Tripod into a programmable form system for Windows 3.0, under the code name ''Ruby'' (no relation to the [[Ruby (programming language)|Ruby programming language]]).
Tripod did not include a programming language at all. Microsoft decided to combine Ruby with the Basic language to create Visual Basic.
The Ruby interface generator provided the "visual" part of Visual Basic and this was combined with the "EB" Embedded BASIC engine designed for Microsoft's abandoned "Omega" database system. Ruby also provided the ability to load [[dynamic-link library|dynamic link libraries]] containing additional controls (then called "gizmos"), which later became the [[Visual Basic Extension|VBX]] interface{{cite web| url=http://www.forestmoon.com/BIRTHofVB/BIRTHofVB.html| title = The Birth of Visual Basic}}.
Tripod did not include a programming language at all. Microsoft decided to combine Ruby with the Basic language to create Visual Basic.
The Ruby interface generator provided the "visual" part of Visual Basic and this was combined with the "EB" Embedded BASIC engine designed for Microsoft's abandoned "Omega" database system. Ruby also provided the ability to load [[dynamic-link library|dynamic link libraries]] containing additional controls (then called "gizmos"), which later became the [[Visual Basic Extension|VBX]] interface{{cite web| url=http://www.forestmoon.com/BIRTHofVB/BIRTHofVB.html| title = The Birth of Visual Basic}}.