Monday, January 5, 2009

Basic Techniques Of VB Part Three

DoEvents
DoEvents method will return control to the operating system for a while so that the operating system can process the events that may occur. This method is appropriate if the code is implemented in a program that requires long process so that another event that could have waited precedence.

Examples of the process DoEvents Iterations (loop) can be seen below:

For i = 1 To 300
Text1.Text = i
DoEvents
'Inner loop a long time
For j = 1 To 100000
Next j
Next i
Text1.Text = "ok"

However, DoEvents is not a solution without potential problems. For example, if you call a method, you must ensure that the method is not called back until the execution is returned.

Basic Techniques Of VB Part Two

UDT
In Visual Basic, we can create your own type of data, which is known by the term UDT (User-Defined Type). Generally do when we need specific data types that are not available in Visual Basic.

In principle, UDT can be declared as Public or Private. However, in Visual Basic 6, all the modules can include the definition of Public UDT, except form. Therefore, if you define the form in the UDT, use the Private access modifier. Example of implementation as follows:


Private Type Supplier
Name As String
Address As String
End Type

Once we finished defining the structure of the UDT, we can declare a variable and then assign the item or the attribute. How to access them using a period as follows:

'Declare a variable with the type UDT
Dim Spl As Supplier

Spl.Name = "PT. AUBISOFT"
Spl.Address = "Jl. Cipinang Pisangan Timur No. 12"

With Spl
Print.Name
Print.Address
End With

Friday, November 14, 2008

Basic Techniques Of VB Part One

The Naming Of The Leading Variable

Consistency is often associated with the writing program code that standard. This is quite baseless because the writing code that makes the program more consistent, easy to read and understand.
For example, in the naming of variables, it is recommended that you refer to the standards that have been set. For example, such as the following:

'If there is only one string in a variable scope

Dim str As String
'If there are more than one
Dim strNama as String
Dim strAlamat As String

Avoid Data Type Variants
Data type variants will automatically be set at a variable when you do not specify the type of the data explicitly.

'Variable intX with type variants
Dim intX, intY As Integer
'Type Integer for intA and intB
Dim As intA Integer, intB As Integer

The main reasons to avoid the data type variants is due to the execution time. It will make program run slow and consume more memory.

Scope Of Variables
When the variables you only needed by a method (procedure / function), should declare at the local level. This technique is closely related to the performance of the application, where the local variables will be executed faster than global variables.