Home > VB6
Slide 1 / 12

Visual Basic 6

Legacy Programming Language

Complete Reference Guide

VB6 adalah bahasa pemrograman berbasis BASIC yang dikembangkan Microsoft. Dirilis tahun 1998, sekarang sudah obsolete tapi masih banyak digunakan di sistem legacy.

Setup

Environment Setup

Installation

Project Structure

Project/
├── Project.vbp          # Project file
├── Project.vbw          # Workspace file
├── Form1.frm            # Form definition
├── Module1.bas          # Module code
├── Class1.cls           # Class module
└── Resources/
    └── Resource1.res    # Resource file
Basic

Variables & Types

Declaration

Dim nama As String
Dim usia As Integer
Dim harga As Double
Dim aktif As Boolean
Dim arr() As String

Data Types

TypeDescription
StringText data
IntegerWhole number
DoubleDecimal number
BooleanTrue/False
DateDate & Time
ObjectObject reference
Basic

Control Structures

If-Then

If kondisi Then
    ' code
ElseIf kondisi2 Then
    ' code
Else
    ' code
End If

Select Case

Select Case nilai
    Case 1
        ' code
    Case 2
        ' code
    Case Else
        ' code
End Select
Basic

Loops

For Loop

For i = 1 To 10
    ' code
Next i

Do While

Do While kondisi
    ' code
Loop

For Each

For Each item In collection
    ' code
Next item
UI

Forms & Controls

Common Controls

Event Handling

Private Sub Command1_Click()
    MsgBox "Button clicked!"
End Sub

Private Sub Form_Load()
    ' Initialize form
End Sub
Database

ADODB Connection

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;"
conn.Open

rs.Open "SELECT * FROM table", conn, adOpenStatic, adLockOptimistic

Do While Not rs.EOF
    Debug.Print rs!fieldname
    rs.MoveNext
Loop

rs.Close
conn.Close
Note: Pastikan reference "Microsoft ActiveX Data Objects 2.x" sudah ditambahkan di Project → References
Advanced

Error Handling

On Error GoTo ErrorHandler
' code that might error
Exit Sub

ErrorHandler:
    MsgBox Err.Description
    Resume Next
End Sub

Err Object Properties

Advanced

Class Module

' Class1.cls
Private m_Name As String

Public Property Get Name() As String
    Name = m_Name
End Property

Public Property Let Name(value As String)
    m_Name = value
End Property

Public Sub DoSomething()
    ' code
End Sub

Usage

Dim obj As New Class1
obj.Name = "Test"
obj.DoSomething
Advanced

ActiveX DLL

Steps to Create

  1. Create ActiveX DLL project
  2. Add Class Module
  3. Write your code
  4. Compile to .dll
  5. Register with regsvr32 Project.dll

Register/Unregister

' Register
regsvr32 Project.dll

' Unregister
regsvr32 /u Project.dll
Deployment

Packaging & Deployment

Package & Deployment Wizard

Common Dependencies

FilePurpose
msvbvm60.dllVB Runtime
COMDLG32.OCXCommon Dialogs
MSCOMCTL.OCXWindows Common Controls
MSADODC.OCXData Control
Reference

Resources & Tools

Tools

References

Warning: VB6 sudah deprecated. Untuk project baru, pertimbangkan VB.NET atau bahasa modern lain.

Kuis: VB6

Apa ekstensi file project VB6?

VB6 menggunakan bahasa pemrograman apa?

Apa fungsi Form di VB6?