Selasa, 30 Maret 2010

Repetition Structures in Visual Basic


Do While... Loop Statement 

The Do While...Loop is used to execute statements until a certain condition is met. The following Do Loop counts from 1 to 100.

Dim number As Integer
number = 1
Do While number <= 100 
number = number + 1 
Loop 

A variable number is initialized to 1 and then the Do While Loop starts. First, the condition is tested; if condition is True, then the statements are executed. When it gets to the Loop it goes back to the Do and tests condition again. If condition is False on the first pass, the statements are never executed. 

While... Wend Statement 

A While...Wend statement behaves like the Do While...Loop statement. The following While...Wend counts from 1 to 100 

Dim number As Integer 
number = 1 
While number <=100 
number = number + 1 
Wend 

Do...Loop While Statement 

The Do...Loop While statement first executes the statements and then test the condition after each execution. The following program block illustrates the structure: 

Dim number As Long 
number = 0 
Do 
number = number + 1 
Loop While number < 201 

The programs executes the statements between Do and Loop While structure in any case. Then it determines whether the counter is less than 501. If so, the program again executes the statements between Do and Loop While else exits the Loop. 

Do Until...Loop Statement 

Unlike the Do While...Loop and While...Wend repetition structures, the Do Until... Loop structure tests a condition for falsity. Statements in the body of a Do Until...Loop are executed repeatedly as long as the loop-continuation test evaluates to False. 

An example for Do Until...Loop statement. The coding is typed inside the click event of the command button 

Dim number As Long 
number=0 
Do Until number > 1000
number = number + 1
Print number
Loop

Numbers between 1 to 1000 will be displayed on the form as soon as you click on the command button.

The For...Next Loop

The For...Next Loop is another way to make loops in Visual Basic. For...Next repetition structure handles all the details of counter-controlled repetition. The following loop counts the numbers from 1 to 100:

Dim x As Integer
For x = 1 To 50
Print x
Next

In order to count the numbers from 1 yo 50 in steps of 2, the following loop can be used

For x = 1 To 50 Step 2
Print x
Next

The following loop counts numbers as 1, 3, 5, 7..etc

The above coding will display numbers vertically on the form. In order to display numbers horizontally the following method can be used.

For x = 1 To 50
Print x & Space$ (2);
Next

To increase the space between the numbers increase the value inside the brackets after the & Space$.

Following example is a For...Next repetition structure which is with the If condition used.

Dim number As Integer
For number = 1 To 10
If number = 4 Then
Print "This is number 4"
Else
Print number
End If
Next
»»  read more

Control Structures

If...Then selection structure

The If...Then selection structure performs an indicated action only when the condition is True; otherwise the action is skipped.

Syntax of the If...Then selection

If Then
statement
End If

e.g.: If average>75 Then
txtGrade.Text = "A"
End If

 

If...Then...Else

If condition1 Then
statements1
Else
statements2
End If

e.g.: If average>50 Then
txtGrade.Text = "Pass"
Else
txtGrade.Text = "Fail"
End If

Nested If...Then...Else selection structure

Nested If...Then...Else selection structures test for multiple cases by placing If...Then...Else selection structures inside If...Then...Else structures.

Syntax of the Nested If...Then...Else selection structure

You can use Nested If either of the methods as shown above

Method 1

If < condition 1 > Then
statements
ElseIf < condition 2 > Then
statements
ElseIf < condition 3 > Then
statements
Else
Statements
End If

Method 2

If < condition 1 > Then
statements
Else
If < condition 2 > Then
statements
Else
If < condition 3 > Then
statements
Else
Statements
End If
End If
EndIf

e.g.: Assume you have to find the grade using nested if and display in a text box

If average > 75 Then
txtGrade.Text = "A"
ElseIf average > 65 Then
txtGrade.Text = "B"
ElseIf average > 55 Then
txtGrade.text = "C"
ElseIf average > 45 Then
txtGrade.Text = "S"
Else
txtGrade.Text = "F"
End If

Select Case

Can be used as an alternative to the If...Then...Else structure, especially when many comparisons are involved.

Select Case ShirtSize
Case 1
SizeName.Caption = "Small"
Case 2
SizeName.Caption = "Medium"
Case 3
SizeName.Caption = "Large"
Case 4
SizeName.Caption = "Extra Large"
Case Else
SizeName.Caption = "Unknown size"
End Select

e.g.: Assume you have to find the grade using select...case and display in the text box

Dim average as Integer


average = txtAverage.Text
Select Case average
Case 100 To 75
txtGrade.Text ="A"
Case 74 To 65
txtGrade.Text ="B"
Case 64 To 55
txtGrade.Text ="C"
Case 54 To 45
txtGrade.Text ="S"
Case 44 To 0
txtGrade.Text ="F"
Case Else
MsgBox "Invalid average marks"
End Select

Do...Loop

Used to execute a block of statements an unspecified number of times.

Do While condition
statements
Loop

First, the condition is tested; if condition is True, then the statements are executed. When it gets to the Loop it goes back to the Do and tests condition again. If condition is False on the first pass, the statements are never executed.

For...Next

When the number of iterations of the loop is known, it is better to use the For...Next rather than the Do...Loop.

For counter = start To end
statements
Next

  1. The counter is set to the value of start.
  2. Counter is checked to see if it is greater than end; if yes, control passes to the statement after the Next; if not the statements are executed.
  3. At Next, counter is incremented and goes back to step 2).

More will be covered on Control strucures as it becomes necessary in upcoming lessons. Meanwhile,if you want to know more, consult the VB Language Reference.
»»  read more

Procedures in Visual Basic 6


Visual Basic offers different types of procedures to execute small sections of coding in applications. The various procedures are elucidated in details in this section. Visual Basic programs can be broken into smaller logical components called Procedures. Procedures are useful for condensing repeated operations such as the frequently used calculations, text and control manipulation etc. The benefits of using procedures in programming are:

It is easier to debug a program a program with procedures, which breaks a program into discrete logical limits.Procedures used in one program can act as building blocks for other programs with slight modifications. A Procedure can be Sub, Function or Property Procedure.

Sub Procedures

A sub procedure can be placed in standard, class and form modules. Each time the procedure is called, the statements between Sub and End Sub are executed. The syntax for a sub procedure is as follows:

[Private | Public] [Static] Sub Procedurename [( arglist)]
[ statements]
End Sub

arglist is a list of argument names separated by commas. Each argument acts like a variable in the procedure. There are two types of Sub Procedures namely general procedures and event procedures.

Event Procedures

An event procedure is a procedure block that contains the control's actual name, an underscore(_), and the event name. The following syntax represents the event procedure for a Form_Load event.

Private Sub Form_Load()
....statement block..
End Sub

Event Procedures acquire the declarations as Private by default.

General Procedures

A general procedure is declared when several event procedures perform the same actions. It is a good programming practice to write common statements in a separate procedure (general procedure) and then call them in the event procedure.

In order to add General procedure:

  • The Code window is opened for the module to which the procedure is to be added.
  • The Add Procedure option is chosen from the Tools menu, which opens an Add Procedure dialog box as shown in the figure given below.
  • The name of the procedure is typed in the Name textbox
  • Under Type, Sub is selected to create a Sub procedure, Function to create a Function procedure or Property to create a Property procedure.
  • Under Scope, Public is selected to create a procedure that can be invoked outside the module, or Private to create a procedure that can be invoked only from within the module.
We can also create a new procedure in the current module by typing Sub ProcedureName, Function ProcedureName, or Property ProcedureName in the Code window. A Function procedure returns a value and a Sub Procedure does not return a value.

Function Procedures

Functions are like sub procedures, except they return a value to the calling procedure. They are especially useful for taking one or more pieces of data, called arguments and performing some tasks with them. Then the functions returns a value that indicates the results of the tasks complete within the function.

The following function procedure calculates the third side or hypotenuse of a right triangle, where A and B are the other two sides. It takes two arguments A and B (of data type Double) and finally returns the results.

Function Hypotenuse (A As Double, B As Double) As Double
Hypotenuse = sqr (A^2 + B^2)
End Function

The above function procedure is written in the general declarations section of the Code window. A function can also be written by selecting the Add Procedure dialog box from the Tools menu and by choosing the required scope and type.

Property Procedures

A property procedure is used to create and manipulate custom properties. It is used to create read only properties for Forms, Standard modules and Class modules.Visual Basic provides three kind of property procedures-Property Let procedure that sets the value of a property, Property Get procedure that returns the value of a property, and Property Set procedure that sets the references to an object.
»»  read more

Senin, 29 Maret 2010

Variables in Visual Basic

Variables are the memory locations which are used to store values temporarily. A defined naming strategy has to be followed while naming a variable. A variable name must begin with an alphabet letter and should not exceed 255 characters. It must be unique within the same scope. It should not contain any special character like %, &, !, #, @ or $.

There are many ways of declaring variables in Visual Basic. Depending on where the variables are declared and how they are declared, we can determine how they can be used by our application. The different ways of declaring variables in Visual Basic are listed below and elucidated in this section.
  • Explicit Declaration
  • Using Option Explicit statement
  • Scope of Variables
Explicit Declaration

Declaring a variable tells Visual Basic to reserve space in memory. It is not must that a variable should be declared before using it. Automatically whenever Visual Basic encounters a new variable, it assigns the default variable type and value. This is called implicit declaration. Though this type of declaration is easier for the user, to have more control over the variables, it is advisable to declare them explicitly. The variables are declared with a Dim statement to name the variable and its type. The As type clause in the Dim statement allows to define the data type or object type of the variable. This is called explicit declaration.

Syntax

Dim variable [As Type]

For example,

Dim strName As String
Dim intCounter As Integer

Using Option Explicit statement

It may be convenient to declare variables implicitly, but it can lead to errors that may not be recognized at run time. Say, for example a variable by name intcount is used implicitly and is assigned to a value. In the next step, this field is incremented by 1 by the following statement

Intcount = Intcount + 1

This calculation will result in intcount yielding a value of 1 as intcount would have been initialized to zero. This is because the intcount variable has been mityped as incont in the right hand side of the second variable. But Visual Basic does not see this as a mistake and considers it to be new variable and therefore gives a wrong result.

In Visual Basic, to prevent errors of this nature, we can declare a variable by adding the following statement to the general declaration section of the Form.

Option Explicit
This forces the user to declare all the variables. The Option Explicit statement checks in the module for usage of any undeclared variables and reports an error to the user. The user can thus rectify the error on seeing this error message.

The Option Explicit statement can be explicitly placed in the general declaration section of each module using the following steps.

  • Click Options item in the Tools menu
  • Click the Editor tab in the Options dialog box
  • Check Require Variable Declaration option and then click the OK button
Scope of variables

A variable is scoped to a procedure-level (local) or module-level variable depending on how it is declared. The scope of a variable, procedure or object determines which part of the code in our application are aware of the variable's existence. A variable is declared in general declaration section of e Form, and hence is available to all the procedures. Local variables are recognized only in the procedure in which they are declared. They can be declared with Dim and Static keywords. If we want a variable to be available to all of the procedures within the same module, or to all the procedures in an application, a variable is declared with broader scope.
Local Variables

A local variable is one that is declared inside a procedure. This variable is only available to the code inside the procedure and can be declared using the Dim statements as given below.

Dim sum As Integer

The local variables exist as long as the procedure in which they are declared, is executing. Once a procedure is executed, the values of its local variables are lost and the memory used by these variables is freed and can be reclaimed. Variables that are declared with keyword Dim exist only as long as the procedure is being executed.

Static Variables

Static variables are not reinitialized each time Visual Invokes a procedure and therefore retains or preserves value even when a procedure ends. In case we need to keep track of the number of times a command button in an application is clicked, a static counter variable has to be declared. These static variables are also ideal for making controls alternately visible or invisible. A static variable is declared as given below.

Static intPermanent As Integer

Variables have a lifetime in addition to scope. The values in a module-level and public variables are preserved for the lifetime of an application whereas local variables declared with Dim exist only while the procedure in which they are declared is still being executed. The value of a local variable can be preserved using the Static keyword. The follwoing procedure calculates the running total by adding new values to the previous values stored in the static variable value.

Function RunningTotal ( )
Static Accumulate
Accumulate = Accumulate + num
RunningTotal = Accumulate
End Function

If the variable Accumulate was declared with Dim instead of static, the previously accumulated values would not be preserved accross calls to the procedure, and the procedure would return the same value with which it was called. To make all variables in a procedure static, the Static keyword is placed at the beginning of the procedure heading as given in the below statement.

Static Function RunningTotal ( )

Example

The following is an example of an event procedure for a CommandButton that counts and displays the number of clicks made.

Private Sub Command1_Click ( )
Static Counter As Integer
Counter = Counter + 1
Print Counter
End Sub

The first time we click the CommandButton, the Counter starts with its default value of zero. Visual Basic then adds 1 to it and prints the result.

Module Levele Variables

A module level variable is available to all the procedures in the module. They are declared using the Public or the Private keyword. If you declare a variable using a Private or a Dim statement in the declaration section of a module—a standard BAS module, a form module, a class module, and so on—you're creating a private module-level variable. Such variables are visible only from within the module they belong to and can't be accessed from the outside. In general, these variables are useful for sharing data among procedures in the same module:

' In the declarative section of any module
Private LoginTime As Date ' A private module-level variable
Dim LoginPassword As String ' Another private module-level variable

You can also use the Public attribute for module-level variables, for all module types except BAS modules. (Public variables in BAS modules are global variables.) In this case, you're creating a strange beast: a Public module-level variable that can be accessed by all procedures in the module to share data and that also can be accessed from outside the module. In this case, however, it's more appropriate to describe such a variable as a property:

' In the declarative section of Form1 module
Public CustomerName As String ' A Public property

You can access a module property as a regular variable from inside the module and as a custom property from the outside:

' From outside Form1 module...
Form1.CustomerName = "John Smith"

The lifetime of a module-level variable coincides with the lifetime of the module itself. Private variables in standard BAS modules live for the entire life of the application, even if they can be accessed only while Visual Basic is executing code in that module. Variables in form and class modules exist only when that module is loaded in memory. In other words, while a form is active (but not necessarily visible to the user) all its variables take some memory, and this memory is released only when the form is completely unloaded from memory. The next time the form is re-created, Visual Basic reallocates memory for all variables and resets them to their default values (0 for numeric values, "" for strings, Nothing for object variables).

Public vs Local Variables

A variable can have the same name and different scope. For example, we can have a public variable named R and within a procedure we can declare a local variable R. References to the name R within the procedure would access the local variable and references to R outside the procedure would access the public variable.
»»  read more

Visual Basic 6 (VB6) Data Types, Modules and Operators

Visual Basic uses building blocks such as Variables, Data Types, Procedures, Functions and Control Structures in its programming environment. This section concentrates on the programming fundamentals of Visual Basic with the blocks specified.

Modules

Code in Visual Basic is stored in the form of modules. The three kind of modules are Form Modules, Standard Modules and Class Modules. A simple application may contain a single Form, and the code resides in that Form module itself. As the application grows, additional Forms are added and there may be a common code to be executed in several Forms. To avoid the duplication of code, a separate module containing a procedure is created that implements the common code. This is a standard Module.

Class module (.CLS filename extension) are the foundation of the object oriented programming in Visual Basic. New objects can be created by writing code in class modules. Each module can contain:

Declarations : May include constant, type, variable and DLL procedure declarations.
Procedures : A sub function, or property procedure that contain pieces of code that can be executed as a unit.

These are the rules to follow when naming elements in VB - variables, constants, controls, procedures, and so on:
  • A name must begin with a letter.
  • May be as much as 255 characters long (but don't forget that somebody has to type the stuff!).
  • Must not contain a space or an embedded period or type-declaration characters used to specify a data type; these are ! # % $ & @
  • Must not be a reserved word (that is part of the code, like Option, for example)
  • The dash, although legal, should be avoided because it may be confused with the minus sign. Instead of First-name use First_name or FirstName.

Data types in Visual Basic 6

By default Visual Basic variables are of variant data types. The variant data type can store numeric, date/time or string data. When a variable is declared, a data type is supplied for it that determines the kind of data they can store. The fundamental data types in Visual Basic including variant are integer, long, single, double, string, currency, byte and boolean. Visual Basic supports a vast array of data types. Each data type has limits to the kind of information and the minimum and maximum values it can hold. In addition, some types can interchange with some other types. A list of Visual Basic's simple data types are given below.
Data type                     Storage size                              Range

Byte                                  1 byte                           0 to 255
Boolean                             2 bytes                         True or False
Integer                              2 bytes                        -32,768 to 32,767
Long (long integer)             4 bytes                        -2,147,483,648 to 2,147,483,647
Single                                4 bytes                         (-3.4x10-38) - (+ 3.4x1038)
Double                              8 bytes                         -1.79769313486232E308 to -4.94065645841247E-324
Currency (scaled integer)    8 bytes                         -922,337,203,685,477.5808 to 922,337,203,685,477.5807
Date                                  8 bytes                         January 1, 100 to December 31, 9999
Object                               4 bytes                         Any Object reference
String (variable-length)      10 bytes + string length    0 to approximately 2 billion
String (fixed-length)            Length of string             1 to approximately 65,400
Variant (with numbers)      16 bytes                         Any numeric value up to the range of a Double
Variant (with characters)    22 bytes + string length    Same range as for variable-length String
User-defined (using Type)   Number                          The range of each element is the same as the range of its
                                                                             data  type.

In all probability, in 90% of your applications you will use at most six types: String, Integer, Long, Single, Boolean and Date. The Variant type is often used automatically when type is not important. A Variant-type field can contain text or numbers, depending on the data that is actually entered. It is flexible but it is not very efficient in terms of storage.

Operators in Visual Basic

Arithmetical Operators

Operators                          Description                         Example                            Result

    +                                      Add                                 5+5                                   10
    -                                   Substract                            10-5                                     5
    /                                      Divide                              25/5                                     5
    \                                Integer Division                       20\3                                     6
    *                                    Multiply                             5*4                                    20
    ^                             Exponent (power of)                  3^3                                    27
 Mod                          Remainder of division              20 Mod 6                                 2
&                               String concatenation        "George"& " "&"Bush"            "George Bush"


Relational Operators

Operators                      Description                          Example                              Result
     >                             Greater than                          10 > 8                                  True
     <                               Less than                            10 < 8                                  False
    >=                    Greater than or equal to                 20>=10                                 True
    <=                      Less than or equal to                   10<=20                                 True
    <>                           Not Equal to                            5<>4                                  True
     =                                Equal to                               5=7                                    False


Logical Operators

Operators                                                            Description
   OR                                          Operation will be true if either of the operands is true
  AND                                        Operation will be true only if both the operands are true
»»  read more

Getting Started with Visual Basic 6.0 II

Project Explorer

Docked on the right side of the screen, just under the tollbar, is the Project Explorer window. The Project Explorer as shown in in figure servres as a quick reference to the various elements of a project namely form, classes and modules. All of the object that make up the application are packed in a project. A simple project will typically contain one form, which is a window that is designed as part of a program's interface. It is possible to develop any number of forms for use in a program, although a program may consist of a single form. In addition to forms, the Project Explorer window also lists code modules and classes.
                                                                    Figure 3 Project Explorer


Properties Window

The Properties Window is docked under the Project Explorer window. The Properties Window exposes the various characteristics of selected objects. Each and every form in an application is considered an object. Now, each object in Visual Basic has characteristics such as color and size. Other characteristics affect not just the appearance of the object but the way it behaves too. All these characteristics of an object are called its properties. Thus, a form has properties and any controls placed on it will have propeties too. All of these properties are displayed in the Properties Window.


Object Browser 

The Object Browser allows us to browse through the various properties, events and methods that are made available to us. It is accessed by selecting Object Browser from the View menu or pressing the key F2. The left column of the Object Browser lists the objects and classes that are available in the projects that are opened and the controls that have been referenced in them. It is possible for us to scroll through the list and select the object or class that we wish to inspect. After an object is picked up from the Classes list, we can see its members (properties, methods and events) in the right column.

A property is represented by a small icon that has a hand holding a piece of paper. Methods are denoted by little green blocks, while events are denoted by yellow lightning bolt icon.

Object naming conversions of controls (prefix)

Form -frm
Label - lbl
TextBox - txt
CommandButton - cmd
CheckBox  - chk
OptionButton  - opt
ComboBox - cbo
ListBox - lst
Frame - fme
PictureBox - pic
Image - img
Shape - shp
Line - lin
HScrollBar - hsb
VScrollBar - vsb
»»  read more

Minggu, 28 Maret 2010

Getting Started with Visual Basic 6.0

Visual Basic is initiated by using the Programs option > Microsoft Visual Basic 6.0 > Visual Basic 6.0. Clicking the Visual Basic icon, we can view a copyright screen enlisting the details of the license holder of the copy of Visual Basic 6.0. Then it opens in to a new screen as shown in figure 1 below, with the interface elements Such as MenuBar, ToolBar, The New Project dialog box. These elements permit the user to buid different types of Visual Basic applications. 

The Integrated Development Environment

One of the most significant changes in Visual Basic 6.0 is the Integrated Development Environment (IDE). IDE is a term commonly used in the programming world to describe the interface and environment that we use to create our applications. It is called integrated because we can access virtually all of the development tools that we need from one screen called an interface. The IDE is also commonly referred to as the design environment, or the program.

Tha Visual Basic IDE is made up of a number of components

  • Menu Bar
  • Tool Bar
  • Project Explorer
  • Properties window
  • Form Layout Window
  • Toolbox
  • Form Designer
  • Object Browser
In previous versions of Visual Basic, the IDE was designed as a Single Document Interface (SDI). In a Single Document Interface, each window is a free-floating window that is contained within a main window and can move anywhere on the screen as long as Visual Basic is the current application. But, in Visual Basic 6.0, the IDE is in a Multiple Document Interface (MDI) format. In this format, the windows associated with the project will stay within a single container known as the parent. Code and form-based windows will stay within the main container form.


                                                  picture : the visual basic startup dialog box


Before you start to build-up the form, it will make it easier if you change the color of the form. Otherwise you will be working with grey controls on a grey background. To change the color, just click anywhere on the form, go to the properties window, find the property called BackColor and change it to the standard Window background (teal) or to any color you want in the palette.

In our first example we will need 6 labels and 2 command buttons. Each one of these objects that you put on a Form is called a control. To get a control you go to the Toolbox, click on the control you want, come back to the Form and click and drag the control to the size and position you want. Position the controls somewhat like in the diagram below.

                                                         picture : visual basic form

Menu Bar

This Menu Bar displays the commands that are required to build an application. The main menu items have sub menu items that can be chosen when needed. The toolbars in the menu bar provide quick access to the commonly used commands and a button in the toolbar is clicked once to carry out the action represented by it.

Toolbox

The Toolbox contains a set of controls that are used to place on a Form at design time thereby creating the user interface area. Additional controls can be included in the toolbox by using the Components menu item on the Project menu. A Toolbox is represented in figure  shown below.

                                picture : Toolbox window with its controls available commonly


  • Pointer               Provides a way to move and resize the controls form
  • PictureBox          Displays icons/bitmaps and metafiles.
  • TextBox             Used to display message and enter text.
  • Frame                       Serves as a visual and functional container for controls
  • CommandButton        Used to carry out the specified action when the user chooses it.
  • CheckBox                  Displays a True/False or Yes/No option.
  • OptionButton              control which is a part of an option group allows the user to select only one option even it displays mulitiple choices.
  • ListBox                      Displays a list of items from which a user can select one.
  • ComboBox                 Contains a TextBox and a ListBox. This allows the user to select an ietm from the dropdown ListBox, or to type in a selection in the TextBox.
  • HScrollBar and VScrollBar               These controls allow the user to select a value within the specified range of values
  • Timer                         Executes the timer events at specified intervals of time
  • DriveListBox               Displays the valid disk drives and allows the user to select one of them.
  • DirListBox                  Allows the user to select the directories and paths, which are displayed.
  • FileListBox                  Displays a set of files from which a user can select the desired one.
  • Shape                          Used to add shape (rectangle, square or circle) to a Form
  • Line                            Used to draw straight line to the Form
  • Image                         used to display images such as icons, bitmaps and metafiles. But less capability than the PictureBox
  • Data                            Enables the use to connect to an existing database and display information from it.
  • OLE                           Used to link or embed an object, display and manipulate data from other windows based applications.
  • Label                           Displays a text that the user cannot modify or interact with.

- - -  Next
»»  read more

Part I : Introduction


About VISUAL BASIC 6

Visual Basic 6 is not your grandfather's BASIC! If your knowledge of programming is limited to the QBASIC you toyed with in high school, you'll think you've landed on a different planet. You may still see the occasional GoTo hanging around but, for the most part you will be in unfamiliar territory. For one thing, the word Basic in Visual Basic is not an acronym anymore. It used to be. When the language was invented in the early 70's, BASIC stood for Beginners' All-purpose Symbolic Instruction Code, thus the acronym (word formed from the first letter of several words, in upper-case). It is certainly not just for beginners, and although it is quite versatile, I don't know if I'd call it exactly All-purpose. And while it is still Instruction Code, it is more than Symbolic now. But THE big difference is the Visual aspect of it where you work with windows and icons and pictures and multimedia. 

Visual basic is a high level programming language developed from the earlier DOS version called BASIC. Though, Visual Basic .NET is the latest technology introduced by Microsoft with tons of new features including the .NET framework and educational institues, Universities and Software Development companies have migrated to VB .NET, Visual Basic 6 is still widely learned and taught.

Learning Visual Basic 6 is quite easier than other programming languages such as C++, C#, Java etc. This is because Visual Basic enables you to work in a graphical user interface where you can just drag and drop controls that you want to work with where you have to write bunches of code to create in C++ or C# or even in Java. If you are new to programming and want to start it in the smoothest and easiest way, then you should start it with Visual Basic.

Before you start developing a Visual Basic 6 application you should be aware that some programming knowledge is useful. If you have used BASIC or Pascal or C before you got here, that's OK. If you did learn one of those languages, you were working in a procedural fashion: when you type RUN the program starts at the beginning and basically follows the instructions going down the list, skipping here and there according to control instructions until it finds some kind of END statement. That is not how Visual Basic operates. Rather than procedural it is event-driven. There will be more on that subject in the next lesson.

However, you do have to write Visual basic 6 code to program the events - there are loops and conditions and arrays. We will not be covering the fundamentals of programming as such - you should be familiar with the basic constructs such as the IF...THEN...ELSE or the FOR...NEXT statements.
versions
You may be aware that there are several dialects of the Visual Basic language in use. This tutorial is on standard Visual Basic. It uses the VB IDE (Integrated Development Environment) to let you create standalone Visual Basic applications that can be distributed as .EXE files. Visual Basic for Applications (VBA) is the language used to tie Microsoft Office products together. It links Word and Excel applications, for example. Although it is very similar to standard VB, it does have several particular techniques that must be learned on their own. VBScript is a small subset of Visual Basic, with limited instructions, mostly used in Internet applications.

As for version, this tutorial is based upon Visual Basic 6.0. You may have access to version 4 or 5 in your environment. Don't worry about it. Of course Mr. Gates would like us to rush out to the store and buy the latest release as soon as it hits the shelves but we are not all as, shall we say, fortunate, as Mr. Gates when it comes to spending money. Right now, when a new version is announced, most of the improvements cover Internet access or Class libraries, etc. At this level of training, we will not be using most of those facilities and so, one version is just about as good as another. A form is a form and a button is a button. There may be slight differences in the interface between versions but those will not matter much.

The only problems occur when you try to run an application on a lower version of the software. It normally doesn't work. But the hardest part of creating an application is usually in writing the code. Some scripts can run into the 100's of line. Fortunately the script is just text and you can work around the version problem with Cut and Paste operations. You will have to redraw the forms, buttons and so on but, that is a minor inconvenience when you can paste in the code for all those objects.

In order to be as accessible as possible, the code downloads at the end of the tutorial will all be in the form of text files that can be pasted into any version of VB.

Visual Basic .NET is now available. Although very similar in most ways to Visual Basic 6, Visual Basic .NET does have significant differences in its approach. For one thing, VB .NET is now completely object-oriented, which isn't the case with Visual Basic 6. An application that runs well in VB 6 will have to be converted, using a conversion wizard to run on VB .NET. Microsoft tell us that the conversion wizard will convert 95% of the code (an optimistic estimate?). Regardless, that leaves at least 5% that will have to be converted manually. That means that a lot of people will wait to see further improvements before jumping to the new version. And add to that the fact that Visual Studio .NET, the parent framework for VB has a huge infrastructure. It requires lots of system resources. For example, you need at least 128 meg of RAM. Excuse me! When I look at the real world I see thousands upon thousands of perfectly good computers with less than 128 meg of memory.

However, if you are just getting into programming or into VB, the basic stuff doesn't change. You still need to know how to create a form, how to put controls on a form, how to write a loop or a decision structure. That hasn't changed in ages and that you can still learn with Visual Basic 6. I see installations out in the real world still doing tons of interesting work with versions 4 or 5 of Visual Basic!
»»  read more

image2

»»  read more

image1

»»  read more
 

flagcounter

free counters