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