VB62

 21/06/2006                                                                                    Page: 3

VISUAL BASIC 6

Event Programming using Event Procedures:  Events supported by Objects. We can write event procedures for any of the events occurring in a program. Example A List Box Object supports Click, DblClick, DragDrop, DragOver, GotFocus, etc.

Decision making:  The If Then .. statement.. Else .. statement.. End If. or it can be If Then ..statement ... ElseIf Then ...statement Else statement End If.

For Variable = Start to ... Step .. End  Next Variable (Can use Exit if given condition is true)

Do While <> Variable Loop (or) Do Loop While (Variable >=0) (or) Do Loop Until Variable=" ".

Program lines can be 1023 characters long in VB code window. We can divide long program statement by using a line continuation character - at the end of each line.

Comparison Operators:  =, <>, <, >, <=, >=.

Logical Operators:  And is used if both conditions are true. Or is used if either condition is true, Not is used if a condition is false, Xor is used if one and only one condition is true.

In a complex expression the program first evaluates mathematical operators, then comparison operators and last the logical operators.

If AutoDraw Property is set to True in a form then output is created automatically when the form is displayed again and again.

Print method supports ; and , symbols to separate elements in an expression.  The ; places elements side by side. The , symbol places elments one tab field apart.

Using modeless forms given flexibility. The user can close it if not needed. Modal form retains focus until user clicks or responds with OK. We can add new form in an existing project and then use it by calling Load Form2 .. Form2.Show... Unload.Form2 or Form2.Hide.  Minimising forms by Form1.windowstate=1, Maximising forms by Form1.windowstate=2. The default view is Form1.windowstate=0.

Setting tap stop propertyu of text box to false keeps text box from getting the focus when user presses tab key.

Multiple document interface MDI forms are distinguished by their roles as parent and child forms. Add MDI parent form by clicking MDI form on project menu. create MDI child form by clicking Add form on project menu. All child forms are displayed within a parent window. when the child form is minimised it appears as a small title bar on MDI form. When parent form is minimised it appears on the taskbar. Child menus appear on parent menubar and child caption appears on parent titlebar.

Standard Module: Separate container in a program that contains global, public variables, functions, sub procedures. Create a module by adding it from Add Module on project menu. A standard module or code module is a special file having an extension of .bas and contains variables or procedures tobe used globally in a program. In this only code can be displayed and edited using code window.

When setting properties from a procedure in a standard module prefix each object name with the form name and a period to let VB know which form is referenced. Call sub procedure by using a literal string(call by value) Add List Box "abc" or by using a variable(call by reference) AddNametoListBox.NewName$

Form Module: Stores objects and event procedures associated with a form and creates a new object in a class module.

General purpose procedures used in a standard module are similar to built-in VB statements and functions and they are called by name and can receive arguments and perform a specific task.  This procedures saves time, reduces possibility of errors, makes program smaller, easier to handle, makes even procedures easier to read, avoids repetitive statements and is reusable.

Function Procedures:  These are called by name from event procedures, can receive arguments and always return a value in the function name. Typically used for complex calculations. Declared in standard module and by default is public.

Sub Procedures: These are called by name from other procedures, can receive arguments and return values but through a variable.  Typically used to receive or process input, display output or set properties.

Property Procedures: Used to create  and manipulate user defined properties in a program; can extend VB by creating new objects, properties and methods.

Passing a Variable: To a procedure is called passing an argument by reference since a variable can be modified by a procedure and returned to the program.

Passing a Literal Value:  (Example: String in quotes " ") to a procedure is called passing an argument by Value since a value cannot be modified by a procedure. Variables can be passed by value by a special notation.                   Example: Sub AddNametoListBox(Person$) if Person$ <> " " then Form1.List1.AddItem Person$ Msg$=Person$ & "added to list box" else Msg$="Name not specified" End If. MsgBox(Msg$),  , "add name" End Sub.

 

Home |  VB6-1 |  VB6-2 |  VB6-3 |  VB6-4 |  VB6-5 |  HTML-1 |  HTML-2 |

This site was last updated 06/21/06