Anda di halaman 1dari 34

Visual Basic 6

Oleh : Mukhlis Amien

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment ) 2. Membuat "Hello World" 3. Tipe file dan penamaan 4. Variable dan Type 5. Conditional statement 6. Loop 7. Function dan subroutine

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment )
2. Membuat "Hello World" 3. Tipe file dan penamaan 4. Variable dan Type 5. Conditional statement 6. Loop 7. Function dan subroutine

Membuat Project
Setiap memulai project baru di VB6 kita akan selalu mendapat pertanyaan tentang project apa yang akan kita buat. Umumnya kita membuat "standard EXE". Pilihan ini akan membuatkan kita form baru kosong yang standar.

Tinjauan IDE
1. Kotak Menu : Berisi menumenu yang memiliki bermacam-macam pilihan. 2. Toolbox : Berisi object yang bisa ditempatkan di form 3. Window ini berisi object grafis seperti form atau user control 4. Object Grafis : Berisi object yang nantinya merupakan bagaimana tampilan program saat dijalankan

5. Project Toolbar : Tempat navigasi file-file project kita 6. Properties Window : digunakan untuk mengubah properti dari object-object.

Mengganti Properties

Jika kita klik pada object yang ada di form atau form-nya sendiri, kita akan bisa merubah properties dari item tersebut dan kita bisa mengubahnya pada panel propertis pada sisi kanan layar IDE.

Control dan UserControl


Ikon pada panel (2) merepresentasikan user control / komponen yang bisa kita letakkan di form. Object ini bisa berisi macam-macam elemen grafis seperti TextBox, ListBox dan segala sesuatu yang digunakan untuk berinteraksi dengan program. DEMO! : Meletakkan user control / komponen

Berpindah Dari Tampilan Object ke Source


Kita bisa mengakses mode "View Code" dan "View Object" dengan berbagai cara : Klik kanan dimanapun pada object kemudian pilih "View Code" Dobel klik pada object Klik kanan pada Project Explorer kemudian pilih "View Code"

Run, Pause, Stop, Breakpoint, Compile, Debug

DEMO!

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment )

2. Membuat "Hello World"


3. Tipe file dan penamaan 4. Variable dan Type 5. Conditional statement 6. Loop 7. Function dan subroutine

Membuat "Hello World!"

DEMO!

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment ) 2. Membuat "Hello World"

3. Tipe file dan penamaan


4. Variable dan Type 5. Conditional statement 6. Loop 7. Function dan subroutine

Tipe File di VB6


Tipe File Project Form Modul Bas Class Module Prefix frm mod cls Ekstensi .VBP .FRM .BAS .CLS Deskripsi File project umum Informasi tampilan form / GUI Berisi modul-modul fungsi Berisi modul-modul subroutine

Contoh penamaan File : OddCalc.vbp frmMain.frm frmAbout.frm frmPrintInvoice.frm modMain.bas modSettings.bas modDeclares.bas clsWinsock.cls

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment ) 2. Membuat "Hello World" 3. Tipe file dan penamaan

4. Variable dan Type


5. Conditional statement 6. Loop 7. Function dan subroutine 8. Dasar GUI di VB6

Variable
Syarat penamaan variable : Maksimal 255 karakter Tidak boleh ada spasi Tidak boleh dimulai dengan angka Tidak boleh ada titik Contoh :
Dim strName as String ' Declares a string called strName strName = "Billy Bob" ' Sets the value of strName strName = strName & " Thornton" ' Appends " Thornton" to strName MsgBox strName ' Outputs the value of strName to a Message Box

Variable Scope

Tipe Data Numeris

Tipe Data Non Numeris

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment ) 2. Membuat "Hello World" 3. Tipe file dan penamaan 4. Variable dan Type

5. Conditional statement
6. Loop 7. Function dan subroutine

Operator Pembanding
Equality "=" Syntax: P = Q

Returns: True if P is equal to Q, and False if it is not.


Inequality "<>" Syntax: P <> Q Returns: True if P is not equal to Q, and False if P is equal to Q. Greater Than ">" Syntax: P > Q Returns: True if P is greater Q, and False if P is less than or equal to Q. Less Than "<" Syntax: P < Q Returns: True if P is less than Q, and False if P is greater than or equal to Q. Greater Than Or Equal To ">=" Syntax: P > Q Returns: True if P is greater than or equal to Q, and False if P is less than Q. Less Than Or Equal To "<=" Syntax: P < Q Returns: True if P is less than or equal to Q, and False if P is greater than Q.

Operator Logika
Not
P True False Not P False True

And

Or

Contoh Operator Pembanding dan Logika


Private Sub Command1_Click() Dim B, C As Boolean Dim P As Integer, Q As Integer P=5 Q=5 B = (P = Q) C = (P or Q) MsgBox B MsgBox C End Sub

Statemen IF
If - Then

If <Expression> Then <Line of code to execute> --OR-- If <Expression> Then <Multiple lines of code to execute> End If

Statemen IF
If - Then - Else

If <Expression> Then <Code to execute if True> Else <Code to execute if False> End If

Statemen IF
If - Then - Elseif If <Expression1> Then <Code to execute if Expression1 is True> ElseIf <Expression2> Then <Code to execute if Expression1 is False and Expression2 is True> ElseIf <Expression3> Then <Code to execute if Expression1 and Expression2 are False, but Expression3 is True> Else <Code to execute if neither Expression1, Expression2 nor Expression3 is True> End If

Statemen IF
Contoh Public Sub Main() Dim S1 As String, S2 As String S1 = "Foo" S2 = "BAR" Dim X As Integer X = 0 If X < 5 Then Debug.Print "X is less than 5" If X > 3 Then Debug.Print "X is greater than 3." Else X = 3 Debug.Print "The value of X was changed from 0 to 3" End If If S1 = "FOO" Then If S2 <> "BAR" Then Debug.Print "S2 is not BAR." ElseIf (X > 0 And X <= 3) And (S2 = "BAR") Then Debug.Print "X is greater than 0 and less than or equal to 3, and _ S2 = 'BAR'." ElseIf X = 3 Then Debug.Print "X is 3 and S2 is not BAR." Else End End If End If End Sub

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment ) 2. Membuat "Hello World" 3. Tipe file dan penamaan 4. Variable dan Type 5. Conditional statement

6. Loop
7. Function dan subroutine

Loops
Do - Loop / Exit Do
Do <Code to execute> Loop

Contoh :
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do Debug.Print X X = Y + X Y = X - Y If cnt >= 8 Then Exit Do Else cnt = cnt + 1 End If Loop End Sub

Loops
Do - Until Do Until <Expression> <Code to execute> Loop

Contoh
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do Until cnt >= 8 Debug.Print X X = Y + X Y = X - Y cnt = cnt + 1 Loop End Sub

Loops
Do - While Do While <Expression> <Code to execute> Loop

Contoh
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do While cnt < 8 Debug.Print X X = Y + X Y = X - Y cnt = cnt + 1 Loop End Sub

Loops
For - Next / Exit For / Step Dim I As Integer For I = <Integer> To <Integer> <Code to execute> Next

Contoh
Public Sub Main()

Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. For cnt = 1 To 8 Debug.Print X X = Y + X Y = X - Y Next For I = 20 To 0 Step -2 Debug.Print I Next IEnd Sub

Dasar-Dasar Visual Basic 6


1. IDE ( Integrated Development Environment ) 2. Membuat "Hello World" 3. Tipe file dan penamaan 4. Variable dan Type 5. Conditional statement 6. Loop

7. Function dan subroutine

Function and Subroutine


Function
Private Integer Private Integer Sub Function Add(ByVal x As Integer, ByVal y As Integer) _As Dim Res as integer Res = x + y Add = Res End Function Sub Form_Load() Dim a As Integer Dim b As Integer Dim c As a = 32 b = 64 c = Add(a, b) MsgBox ("Sum is : " & c) End

Function and Subroutine


Subroutine
Sub TestSub() MsgBox "Code in TestSub()" End Sub Private Sub Form_Load() MsgBox "Code in Form_Load()" TestSub MsgBox "Back in Form_Load()" End Sub You can also use the Call keyword, as mentioned above: Sub TestSub() MsgBox "Code in TestSub()" End Sub Private Sub Form_Load() MsgBox "Code in Form_Load()" 'This line is functionally equal as the line in the previous example Call TestSub MsgBox "Back in Form_Load()" End Sub

Anda mungkin juga menyukai