Está en la página 1de 63

July 19, 2014

PRATIKA VISUAL BASIC 6.0



Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
1

Modul I
KONESIMENTO GERAL PROGRAMASAUN
VISUAL BASIC 6.0

1. Intrudusaun
Visual Basic nee hanesan lian programasaun komputador nian. Lian
programasaun mak instrusaun sira nebe bele kompriende husi komputador atu halo
servisu espesifiku ruma. Lian programasaun Visual Basic dezemvolve husi Microsoft
iha tinan 1991, nebe sei kontinuasaun dezemvolve, sai hanesan lian programasaun
BASIC (Beginner,s) All-purpose Symbolic Instruction Code) nebe dezenvolve iha 1950 i
tal.
Visual Basic henesan Develompent Tool ida, mak intrumento auxiliar ida nebe
bele ajuda ita atu halo (kria) programa komputador nian oin-oin, especialmente ba
komputador sira nebe mak utiliza sistema operativo windows. Visual basic mos
hanesan lian programasaun komputador nian ida nebe bele suporta objeto (Object
Oriented Programming = OOP).

2. Integrated Development Integration (IDE), (ambiente servisu visual basic
nian)
Atu hahu ka ativu programa visual basic 6.0 liu husi butaun menu Start > All
Programs > Microsoft Visual Studio 6.0 > Microsoft Visual Basic 6.0, hein too mosu
jenela hanesan tuir mai nee :

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
2

Husi jenela nebe iha leten ba hili Standart EXE no klika iha butaun Open, hafoin sei
hamosu ambiente servisu visual basic nian ka IDE, hanesan tuir mai nee :

Deskripsaun kompnente husi Visual Basic :
1. Project : konjunto modulo/programa aplikasaun VB nian rasik nebe sei rai ho
extensaun ficeiro .VBP nebe sei priense husi Form sira.
2. Menubar : iha komponente/parte ida nee sei iha menu basiku sira nebe sei utiliza
durante kria programa ruma.
3. Toolbar : iha parte sei hamosu ikon sira husi menu principal nebe mak iha
menubar, hanesan imagen tuir mai nee :

4. Toolbox : iha parte ida nee sei komposto husi icon sira/ komponete sira atu
hatama objeto espesifiku ruma ba iha form laran waihira iha dezeno programa ruma.
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
3


5. Janela Formulario (Form) : area/ambiente ida nebe mak iha relasaun ho jenela ida
nebe bele haree wainhira aplikasaun lao. Iha form nee mak bele tau kontrolo no
kodigu sira atu kria programa.

6. Janela kodigu : atu hakerek source code husi programa nebe mak ita sei halo/kria.
Code Editor

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
4

7. Project Explorer : sei hamosu form sira no modul nebe iha programa nia laran
nebe ita halo. Ho project explorer ita bele muda husi form ida ba form seluk.

Deskripsaun :
1. Project Visual Basic
2. View Code : atu haree janela editor program
3. View Object :atu haree janela formulario
4. Toggle Folders : atu hare pasta rai ficheiro ba.
5. Form nebe ativo hela.
8. Janela Propriedade/properties : atu kontrola propriedade husi form.

Kontrolo sira iha propriedade nee iha mudansa tuir form ka kontrolo nebe ita hili no
presiza.

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
5

9. Jenela Form Layout : atu kontrola pozisaun form iha monitor waihira halao
exekusaun ba programa (runing program).
3. Object, Property, Event no Method
Iha programasaun orientada objetos (OOP), ita prensiza hatene kona ba termo
Object, Property, Event no Method :
Object : komponente nebe iha programa ida nia laran
Property : karateristika husi object
Event : eventu/akontesimentu
Method : aksaun
4. Ilustrasaun ba Object, Property, Event no Method
Exemplo ida husi ilustrasaun ida nee,ita bele kompara ho motor ida nebe sai
hanesan objeto (object) ida nebe iha Property, Event no Method. Atensaun ba
imajen tuir mai nee :

Object : Motor
Property : Marka (Yamaha ), Tipe (Vixion), Koor : Metan
Method : Ba oin, Ba kotuk no Para/stop
Event : Gas, Dudu no Xoke

Object : Form
Property : BackColor, BorderStyle, Caption, icon,
Event : Click, Load, Activated, DoubleClick, Unload, nst.
Method : Show, Hide, Move, nst.
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
6

MODULO II
HAHU PRATIKA DEZENHO PROGRAMA IHA VISUAL BASIC HO FORM NO KODING
OU LISTING PROGRAMA
PRATIKA VISUAL BASICO HO NIA MANEIRA NEBEE HAU PREPARADU TIHA ONA

Atu Desenhu Iha Form nia Laran ihat persiza konponenti hirak nebee ita uza
hodi desenhu iha form nia laran mak hanesan; label 1 & label 2 no iha
command 1, 2, & 3 mak nia desenhu hanesan iha ona okos nee.

Klik iha komandu 2 balik nia leten mak mosu hanesan iha okos nee;


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
7

Klik dalarua iha command1 nia laran hafoin ita tau ninia kode hanesan tuir mai
nee no iha tan command 2 & 3 mak nia exemplo hanesan tuir mai nee:
Listing Program

Halo align font style & font color mak ita persiza design hanesan tuir mai nee;

Antes ita atu tau kode hirak nebee hanesan tuir mai nee, ita klik dalarua iha
check box nia leten mak ita hafoin hatama kode listing program;
KODE LISTING
Private Sub Check1_Click()
Label1.FontBold = Check1.Value
Label2.FontBold = Check1.Value
Label3.FontBold = Check1.Value
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
8

Private Sub Check2_Click()
Label3.FontItalic = Check2.Value
Label1.FontItalic = Check2.Value
Label2.FontItalic = Check2.Value
End Sub
Private Sub Check3_Click()
Label3.FontUnderline = Check3.Value
Label1.FontUnderline = Check3.Value
Label2.FontUnderline = Check3.Value
End Sub

Private Sub Check4_Click()
Label3.FontStrikethru = Check4.Value
Label1.FontStrikethru = Check4.Value
Label2.FontStrikethru = Check4.Value
End Sub
Kode ida mak keluar ninian artinya atu hamate form nebe aktif hela
Private Sub Command1_Click()
Unload Me
End Sub
Kode nee mak ho nia fungsaun hodi halo ativasaun ba iha option5 nia laran
Private Sub Form_Activate()
Option5.SetFocus
End Sub
Kode tuir mai nee ita atu ninia color bai iha label ihrak nebee ita desenho ona
iha leten nee;
Private Sub Option1_Click()
Label3.ForeColor = vbRed
Label1.ForeColor = vbRed
Label2.ForeColor = vbRed
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
9

Private Sub Option2_Click()
Label3.ForeColor = vbGreen
Label1.ForeColor = vbGreen
Label2.ForeColor = vbGreen
End Sub

Private Sub Option3_Click()
Label3.ForeColor = vbBlue
Label1.ForeColor = vbBlue
Label2.ForeColor = vbBlue
End Sub

Private Sub Option4_Click()
Label3.ForeColor = vbYellow
Label1.ForeColor = vbYellow
Label2.ForeColor = vbYellow
End Sub

Private Sub Option5_Click()
Label1.ForeColor = BVBLACK
Label2.ForeColor = vbBlack
Label3.ForeColor = vbBlack
End Sub


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
10

Hatama dadus ba iha bagian input ninian depois resultadu mosu otomatis
mosu iha parte output data nian
Ex:

Kode listing hirak nebee ami uza hodi hatama iha komandu nia laran mak
hanesan tuir mai nee;
Private Sub Command1_Click() {listing tambah nian}
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Combo1.Text = ""
End Sub

Private Sub Command2_Click() {listing simpan nian}
Text4.Text = Text1.Text
Text5.Text = Text2.Text
If Option1.Value = True Then
Text6.Text = "LAKI-LAKI"
Else
Text6.Text = "PEREMPUAN"
End If
Text7.Text = Combo1.Text
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
11

Text8.Text = Text3.Text
End Sub

Private Sub Command3_Click() {listing hapus data nian}
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
End Sub

Private Sub Command4_Click() {listing keluar ninian}
BILU = MsgBox("HAKARAK SAI HUSI FORM NE'E...?", vbQuestion + vbYesNo,
"MENSSAGEN HUSI BILU")
If BILU = vbYes Then
Unload Me
End If
End Sub
Klik dalarua iha form mamuk nia laran iha procedure ita hili load nia fungsi atu
loding ka halo prosesamentu ba dadus nebe mak ita hatama ba laran;
Private Sub Form_Load()
Combo1.AddItem "KATOLIK"
Combo1.AddItem "PROTESTANTE"
Combo1.AddItem "ISLAM"
Combo1.AddItem "BUNDAH"
End Sub


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
12

latihan

Resultadu

Kode Listing Program
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = "0"
Text1.SetFocus
End Sub

Private Sub Command2_Click()
Unload Me
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
13


Private Sub Command3_Click()
Label8.Caption = Text1.Text
Label9.Caption = Text2.Text
Label10.Caption = Text3.Text
Label11.Caption = Text4.Text
End Sub

Private Sub Command4_Click()
Label8.Caption = ""
Label9.Caption = ""
Label10.Caption = ""
Label11.Caption = ""
End Sub

Private Sub Form_Activate()
Label6.Caption = "INFORMASI HITUNGAN DARI MANE-MESAK"
Label7.Caption = "Copy@right dari X-Only-One"
Label12.Caption = "Input-Data"
Label13.Caption = "Output-Data"
End Sub

Private Sub Label6_Click()
Label6.Caption = "DATE"
End Sub

Private Sub Text2_Change()
Text4.Text = Val(Text2.Text) * Val(Text3.Text)
End Sub

Private Sub Text3_Change()
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
14

Text4.Text = Val(Text2.Text) * Val(Text3.Text)
End Sub
Search jalur nebee mak iha kota laran, hatam kode iha kode jalur ninian nia
reselutadu sei mosu omatikamente iha jalur ninian
Form desenhu

Resultado

Kode program
Private Sub Command1_Click() {kode remata ka selesai nian}
End
End Sub
Klik dua kali iha form mamuk nia laran ita hili procedure load;
Private Sub Form_Load()
Text1 = ""
End Sub


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
15

Private Sub Text1_Change()
If Val(Text1.Text) >= 4 Then
Text2.Text = "Jalur ne'e salah"
ElseIf Val(Text1.Text) = 1 Then
Text2.Text = "Comoro Bidau"
ElseIf Val(Text1.Text) = 2 Then
Text2.Text = "Becora Mercado lama"
ElseIf Val(Text1.Text) = 3 Then
Text2.Text = "Bidau Has Laran"
End If
End Sub

Listing programa
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
16



LATIHAN 4

Form Resultado

LISTING PROGRAM
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
17

Private Sub Combo1_Click()
If Combo1.Text = "merah" Then
Me.BackColor = vbRed
ElseIf Combo1.Text = "kuning" Then
Me.BackColor = vbYellow
ElseIf Combo1.Text = "hijau" Then
Me.BackColor = vbGreen
ElseIf Combo1.Text = "biru" Then
Me.BackColor = vbBlue
Else
Me.BackColor = vbWhite
End If
End Sub

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Form_Load()
Combo1.AddItem "merah"
Combo1.AddItem "kuning"
Combo1.AddItem "hijau"
Combo1.AddItem "biru"
Combo1.AddItem "putih"
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
18

Latihan Input Nama
Form desenho

Form resultadu


Listing programa

Private Sub Command1_Click()
Dim PROMPT, FULLNAME, MSG
PROMPT = "MASUKAN NAMA LENGKAP ANDA"
FULLNAME = InputBox(PROMPT)
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
19

MSG = " HELLO...!!! " + FULLNAME
Text1.Text = FULLNAME
MsgBox (MSG), , "INPUT HASIL"
End Sub

Private Sub Command1_KEYPRESS(KEYASCII As Integer)
Dim PROMPT, FULLNAME, MSG
PROMPT = " MASUKAN NAMA LENGKAP ANDA "
FULLNAME = InputBox(PROMPT)
MSG = " HELLO " + FULLNAME
Text1.Text = FULLNAME
MsgBox (MSG), , "INPUT HASIL"
End Sub

Private Sub Command2_Click()
Text1.Text = Empty
End Sub

Private Sub Form_Activate()
Text1.Text = Empty
End Sub

Private Sub sy_Click()
End
End Sub


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
20

Form Nilai Mahasiswa
Form Desenho

Form Resultado


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
21

Listing Program

LATIHAN 5

LISTING PROGRAM
Private Sub Command1_Click()
MsgBox " nama anda " & txtnama.Text & " alamat " & txtalamat.Text & "
telephon " & txttlp.Text, vbInformation, "informasaun husi Abilio Ximenes"
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
22

Private Sub Command2_Click()
Unload Me
End Sub

LATIHAN 6

LISTING PROGRAM
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text5.Enabled = False 'Menonaktifkan objek text5
Text6.Enabled = False 'menonaktifkan objek text6
Text7.Enabled = False 'menonaktifkan object text7
Text1.SetFocus
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
23

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Text4_Change()
Dim total, bayar, DISKON As Single
total = Val(Text3.Text) * Val(Text4.Text)
If total >= 100000 Then
DISKON = 0.3 * total
ElseIf total >= 75000 Then
DISKON = 0.2 * total
ElseIf total < 500000 Then
DISKON = 0
End If
bayar = DISKON - total
Text5.Text = Format(total, "###,###,###")
Text6.Text = Format(DISKON, "###,###,###")
Text7.Text = Format(bayar, "###,###,###")
End Sub

LATIHAN 7


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
24

LISTING PRIGRAMA
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Text1_Change()
Text3.Text = Val(Text1) * Val(Text2)
End Sub

Private Sub Text2_Change()
Text3.Text = Val(Text1) * Val(Text2)
End Sub

Halo Programa Menssagen
LATIHAN 8

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
25




LISTING PROGRAM
Private Sub Command1_Click()
MsgBox "Maluk Sira Imi Diak Ka Lae..? Agora Situasaun Iha Dilli LaranNe'e
Manas Lo'os....Kontak No Tlp : +670 76180050"
End Sub
Private Sub Command2_Click()
MsgBox "Main menu terdiri dari dua komponen utama yaitu menu bar dan title
bar. Menu bar" & "menampilkan menu yang berisi perintah-perintah pada
Visual Basic 6.0, sedangkan title bar akan" & "menampilkan judul proyek Visual
Basic yang sedang dikerjakan"
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
26

Private Sub Command3_Click()
only = MsgBox("Do you like sign out form here...???", vbQuestion +
vbRetryCancel, "only")
If only = vbRetry Then
Unload Me
End If
End Sub

LATIHAN 9

LISTING PROGRAM
Private Sub Combo1_Change()
If Combo1.Text = "Perumahan" Then
Text3.Text = 1000
ElseIf Combo1.Text = "Perkantoran" Then
Text3.Text = 1500
ElseIf Combo1.Text = "Bisnis" Then
Text3.Text = 2000
End If
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
27

Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Combo1.Text = ""
Text1.SetFocus
Text3.Enabled = False 'Menonaktifkan Objek Text3
Text5.Enabled = False 'Menonaktifkan Objek Text5
Text6.Enabled = False 'Menonaktifkan Objek Text6
Text7.Enabled = False 'Menonaktifkan Objek Text7
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Activate()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Combo1.Text = ""
Text1.SetFocus
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
28

Private Sub Text4_Change()
Dim total, ppn, bayar As Single
total = Val(Text4.Text) * Val(Text3.Text)
ppn = total * 0.1
bayar = total + ppn
Text5.Text = Format(total, "###,###,###")
Text6.Text = Format(ppn, "###,###,###")
Text7.Text = Format(bayar, "###,###,###")
End Sub

LATIHAN 10

LISTING PROGRAM
Private Sub Check1_Click()
Label2.FontBold = Check1.Value
End Sub

Private Sub Check2_Click()
Label2.FontItalic = Check2.Value
End Sub
rivate Sub Check3_Click()
Label2.FontUnderline = Check3.Value
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
29

End Sub
Private Sub Check4_Click()
Label2.Font = vbresetcolor
End Sub

Private Sub Check5_Click()
Label2.AutoSize = True
End Sub

Private Sub Command1_Click()
Label2.Caption = Text1.Text
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Option1_Click()
Label2.ForeColor = vbRed
End Sub

Private Sub Option2_Click()
Label2.ForeColor = vbBlue
End Sub

Private Sub Option3_Click()
Label2.ForeColor = vbGreen
End Sub
Private Sub Option4_Click()
Label2.ForeColor = vbYellow
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
30

Private Sub Option5_Click()
Label2.ForeColor = vbBlack
End Sub

Private Sub Option6_Click()
Label2.ForeColor = vbWhite
End Sub

Private Sub Option7_Click()
Label2.ForeColor = vbtan
End Sub

Private Sub Option8_Click()
Label2.ForeColor = vbBlue
End Sub

LATIHAN 11

LISTING PROGRAM
Private Sub Command1_Click()
Text3.Text = Val(Text1) + Val(Text2)
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
31

Private Sub Command2_Click()
Text3.Text = Val(Text1) - Val(Text2)
End Sub

Private Sub Command3_Click()
Text3.Text = Val(Text1) * Val(Text2)
End Sub

Private Sub Command4_Click()
Text3.Text = Val(Text1) / Val(Text2)
End Sub

Private Sub Command5_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub

Private Sub Command6_Click()
MSG = MsgBox("Ita hakarak sai husi form ida ne'e ?", vbQuestion + vbYesNo,
"Mensajen")
If MSG = vbYes Then
Unload Me
End If
End Sub

Private Sub Form_Activate()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
32

Text1.SetFocus
End Sub
LATIHAN 12


LISTING PROGRAM
Private Sub Command1_Click()
If Check1.Value = 1 Then hg_buku = 6000
If Check2.Value = 1 Then hg_pena = 4500
If Check3.Value = 1 Then hg_pencil = 1200
If Check4.Value = 1 Then hg_penghapus = 500
Total = hg_buku + hg_pena + hg_pencil + hg_penghapus
Text1.Text = " Rp " & Total
End Sub

Private Sub Command2_Click()
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
33

Check1.Value = 0
Check2.Value = 0
Check3.Value = 0
Check4.Value = 0
Text1.Text = ""
End Sub

Private Sub Command3_Click()
Unload Me
End Sub

Private Sub Form_Activate()
MsgBox "Hello Kolega sira Diak kal lae..?", vbInformation, "only"
End Sub

LATIHAN 13

LISTING PROGRAM
Private Sub Command1_Click()
c = Text1
r = 4 / 5 * c
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
34

k = c + 273
f = (9 / 5 * c) + 32
Text2 = r
Text3 = k
Text4 = f
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text1.SetFocus
End Sub

Private Sub Command3_Click()
Unload Me
End Sub

LATIHAN 14

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
35

LISTING PROGRAM

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""

Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text1.SetFocus
End Sub

Private Sub Text5_Change()
na = (0.1 * Text2) + (0.2 * Text3) + (0.3 * Text4) + (0.4 * Text5)
Text6 = na

If Val(Text6.Text) >= 80 Then
Text7 = "A"
Text8 = "Sangat Baik"
ElseIf Val(Text6.Text) >= 65 Then
Text7 = "B"
Text8 = "Baik"
ElseIf Val(Text6.Text) >= 55 Then
Text7 = "C"
Text8 = "Cukup"
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
36

ElseIf Val(Text6.Text) >= 45 Then
Text7 = "D"
Text8 = "Kurang"
Else
Text7 = "E"
Text8 = "Sangat Kurang"
End If
End Sub

PROGRAM MENHAMATIKAN
DESIGN FORM

HASIL FORM


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
37

LISTING PROGRAM

LATIHAN 15

LISTING PROGRAM
Private Sub Combo1_Click()
Shape1.BorderWidth = True
End Sub

Private Sub Combo2_Click()
If Combo2.Text = "merah" Then
Shape1.BackColor = vbRed
ElseIf Combo2.Text = "kuning" Then
Shape1.BackColor = vbYellow
ElseIf Combo2.Text = "hijau" Then
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
38

Shape1.BackColor = vbGreen
ElseIf Combo2.Text = "biru" Then
Shape1.BackColor = vbBlue
Else
Shape1.BackColor = vbBlack
End If
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
Combo2.AddItem "merah"
Combo2.AddItem "kuning"
Combo2.AddItem "hijau"
Combo2.AddItem "biru"
Combo2.AddItem "hitam"
End Sub

Private Sub Option1_Click()
If Option1.Value = True Then Shape1.Shape = 0
End Sub

Private Sub Option2_Click()
If Option2.Value = True Then Shape1.Shape = 1
End Sub

Private Sub Option3_Click()
If Option3.Value = True Then Shape1.Shape = 2
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
39

Private Sub Option4_Click()
If Option4.Value = True Then Shape1.Shape = 3
End Sub
Private Sub Option5_Click()
If Option5.Value = True Then Shape1.Shape = 4
End Sub

Private Sub Option6_Click()
If Option6.Value = True Then Shape1.Shape = 5
End Sub

LATIHAN

LISTING PROGRAM

Private Sub cmd_Click()
End
End Sub

Private Sub Form_Activate()
Text1.Text = ""
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
40

Private Sub Text1_Change()
List1.Clear
jumlah = 1
While jumlah <= Val(Text1.Text)
List1.AddItem "pengulangan ke" & jumlah
jumlah = jumlah + 1
Wend
End Sub

LATIHAN

LISTING PROGRAM
Private Sub Command1_Click()
Text3 = 2014 - Text2
Text3 = Text3
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
41

LATIHAN 17


Private Sub cmd_Click()
Text1.Text = ""
Text1.SetFocus
List1.Clear
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
List1.AddItem Text1.Text
Text1.Text = ""
Text1.SetFocus
End If
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
42

Latihan
PERHITUNGAN PENILAIAN MAHASISWA DAN MAHASISWI YANG
MENGUNAKAN PADA PEMOGRAMAN VISUAL BASICO 6.0

Form Designer I

Form Resultadu II



July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
43

Box Sai Nian


Listing Pemogram Yang Munsulkan Sebagai Berikut :
Kode Prossesu Nian
Private Sub cmd1_Click()
Dim Rata As String
Dim Mutu As String

Rata = (Val(Text4.Text) * 0.3) + (Val(Text6.Text) * 0.4) + (Val(Text5.Text) * 0.2) +
(Val(Text7.Text) * 0.1)

If Rata >= 80 Then
Mutu = "A"
ElseIf Rata >= 70 Then
Mutu = "B"
ElseIf Rata >= 60 Then
Mutu = "C"
ElseIf Rata >= 40 Then
Else
Mutu = "D"
End If

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
44

List1.AddItem "Nim=" + Text1.Text
List1.AddItem "Nama=" + Text2.Text
If Option1.Value = True Then
List1.AddItem "Jenis Kelamin=" + Option1.Caption
Else
List1.AddItem "Jenis Kelamin=" + Option2.Caption
End If

List1.AddItem ""
List1.AddItem "jurusan=" + Combo1.Text
List1.AddItem "kelas=" + Text3.Text
List1.AddItem "semester=" + Combo2.Text
List1.AddItem ""

List1.AddItem "mata kuliah=" + Text8.Text
List1.AddItem "Nilai UTS=" + Text4.Text
List1.AddItem "Nilai TUGAS=" + Text5.Text
List1.AddItem "Nilai UAS=" + Text6.Text
List1.AddItem "Nilai Absent=" + Text7.Text
List1.AddItem ""

List1.AddItem "Total Nilai=" + Str(Rata)
List1.AddItem "mutu=" + Mutu
List1.AddItem ""
If Mutu = "A" Then
List1.AddItem "Diak Ona maibe'e tenke estuda maka'as!!!"
ElseIf Mutu = "B" Then
List1.AddItem "Diak tuan na estuda maka'as tan!!!"
ElseIf Mutu = "C" Then
List1.AddItem "Ladun diak, esforsu an maka'as!!!"
Else
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
45

List1.AddItem "A'at lo'os...!!!"
End If
MsgBox "Ita bo'ot nia valor Mata kuliah ida ne'e mak :" + Mutu
End Sub

Kode Mulai Nian
Private Sub cmd2_Click()
Text1.Text = Empty
Text2.Text = Empty
Option1.Value = False
Option2.Value = False
Combo1.Text = ""
Text3.Text = Empty
Combo2.Text = ""
Text8.Text = Empty
Text4.Text = Empty
Text5.Text = Empty
Text6.Text = Empty
Text7.Text = Empty
List1.Clear
Text1.SetFocus
End Sub
Kode Sai Nian
Private Sub cmd3_Click()
X = MsgBox("Hakarak Sai Husi Form Ne'e..?", vbQuestion + vbYesNo, "Info Husi
Biliu")
If X = vbYes Then
Unload Me
End If
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
46


Listing program
Private Sub Command1_Click()
Label14.Caption = ""
Label15.Caption = ""
Text1.Text = ""
Label16.Caption = ""
Label17.Caption = ""
Label18.Caption = ""
Option1.Value = False
Option2.Value = False
Option3.Value = False
Option4.Value = False
Option5.Value = False
End Sub

Private Sub Option1_Click()
Label14.Caption = Option1.Caption
End Sub
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
47

Private Sub Option2_Click()
Label14.Caption = Option2.Caption
End Sub

Private Sub Option3_Click()
Label15.Caption = Option3.Caption
If Option3.Value = True And Option1.Value = True Then
Label16.Caption = "$10.00"
ElseIf Option3.Value = True And Option2.Value = True Then
Label16.Caption = "$20.00"
End If
End Sub

Private Sub Option4_Click()
Label15.Caption = Option4.Caption
If Option4.Value = True And Option1.Value = True Then
Label16.Caption = "$15.00"
ElseIf Option4.Value = True And Option2.Value = True Then
Label16.Caption = "$25.00"
End If
End Sub

Private Sub Option5_Click()
Label15.Caption = Option5.Caption
If Option5.Value = True And Option1.Value = True Then
Label16.Caption = "$25.00"
ElseIf Option5.Value = True And Option2.Value = True Then
Label16.Caption = "$35.00"
End If
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
48

Private Sub Text1_Change()
Dim Peserta As Integer
Dim Tiket, Diskon, Total As Integer
Peserta = Val(Text1.Text)
Tiket = text16
If Peserta <= 50 And Option1.Value = True And Option3.Value = True Then
Label18.Caption = "$" & (Tiket * Peserta)
Diskon = "$" & 0
ElseIf Peserta >= 50 And Option1.Value = True And Option3.Value = True Then
a = Val(Peserta - 50) * 0.25
Label18.Caption = "$" & (Tiket * Peserta) - ((a) * 10)
Diskon = "$" & a
End If
'-----------------------------------------------------------------
If Peserta <= 50 And Option1.Value = True And Option3.Value = True Then
Label18.Caption = "$" & (Tiket * Peserta)
Diskon = "$" & 0
ElseIf Peserta >= 50 And Option1.Value = True And Option3.Value = True Then
b = Val(Peserta - 50) * 0.25
Label18.Caption = "$" & (Tiket * Peserta) - ((b) * 10)
Diskon = "$" & b
End If
'-----------------------------------------------------------------
If Peserta <= 50 And Option1.Value = True And Option3.Value = True Then
Label18.Caption = "$" & (Tiket * Peserta)
Diskon = "$" & 0
ElseIf Peserta >= 50 And Option1.Value = True And Option3.Value = True Then
c = Val(Peserta - 50) * 0.25
Label18.Caption = "$" & (Tiket * Peserta) - ((c) * 10)
Diskon = "$" & c
End If
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
49

'-----------------------------------------------------------------
If Peserta <= 50 And Option1.Value = True And Option3.Value = True Then
Label18.Caption = "$" & (Tiket * Peserta)
Diskon = "$" & 0
ElseIf Peserta >= 50 And Option1.Value = True And Option3.Value = True Then
d = Val(Peserta - 50) * 0.25
Label18.Caption = "$" & (Tiket * Peserta) - ((d) * 10)
Diskon = "$" & d
End If
'-----------------------------------------------------------------
If Peserta <= 50 And Option1.Value = True And Option3.Value = True Then
Label18.Caption = "$" & (Tiket * Peserta)
Diskon = "$" & 0
ElseIf Peserta >= 50 And Option1.Value = True And Option3.Value = True Then
e = Val(Peserta - 50) * 0.25
Label18.Caption = "$" & (Tiket * Peserta) - ((e) * 10)
Diskon = "$" & e
End If
'-----------------------------------------------------------------
If Peserta <= 50 And Option1.Value = True And Option3.Value = True Then
Label18.Caption = "$" & (Tiket * Peserta)
Diskon = "$" & 0
ElseIf Peserta >= 50 And Option1.Value = True And Option3.Value = True Then
f = Val(Peserta - 50) * 0.25
Label18.Caption = "$" & (Tiket * Peserta) - ((f) * 10)
Diskon = "$" & f
End If
Label17.Caption = Diskon
End Sub


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
50

Private Sub xt_Click()
Unload Me
End Sub

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
51

Modul III
KONEKSAUN DATABASSE MAHASISWA PADA
PEMOGRAMA VISUAL BASICO 6.0
Databasse nebee ita kria nee hodi atu fo koneksaun ba microsoft visual basic
6.0;

Form desenho nebee mak hanesan turi mai nee;



July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
52

Form nebe ita desenho iha leten nee mak ita ba Run, nee nia resultadu mak
hanesan tuir mai nee

LISTING PROGRAM
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
Adodc1.Recordset!NIM = Text1.Text
Adodc1.Recordset!NAMA = Text2.Text
Adodc1.Recordset!KELAS = Combo1.Text
Adodc1.Recordset!MT_KLH = Combo2.Text
Adodc1.Recordset!DOSEN = Combo3.Text
Adodc1.Recordset!ABSEN = Text3.Text
Adodc1.Recordset!TUGAS = Text4.Text
Adodc1.Recordset!UTS = Text5.Text
Adodc1.Recordset!UAS = Text6.Text
Adodc1.Recordset!RT_RT = Text7.Text
Adodc1.Recordset!NL_HRF = Text8.Text
Adodc1.Recordset!PREDIKAT = Text9.Text
Adodc1.Recordset.Update
DataGrid1.Refresh
Text1.Text = ""
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
53

Text2.Text = ""
Combo1.Text = ""
Combo2.Text = ""
Combo3.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub

Private Sub Command2_Click()
Adodc1.Recordset.Update
Adodc1.Recordset!NIM = Text1.Text
Adodc1.Recordset!NAMA = Text2.Text
Adodc1.Recordset!KELAS = Combo1.Text
Adodc1.Recordset!MT_KLH = Combo2.Text
Adodc1.Recordset!DOSEN = Combo3.Text
Adodc1.Recordset!ABSEN = Text3.Text
Adodc1.Recordset!TUGAS = Text4.Text
Adodc1.Recordset!UTS = Text5.Text
Adodc1.Recordset!UAS = Text6.Text
Adodc1.Recordset!RT_RT = Text7.Text
Adodc1.Recordset!NL_HRF = Text8.Text
Adodc1.Recordset!PREDIKAT = Text9.Text
DataGrid1.Refresh
Text1.Text = ""
Text2.Text = ""
Combo1.Text = ""
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
54

Combo2.Text = ""
Combo3.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub

Private Sub Command4_Click()
Text1.Text = ""
Text2.Text = ""
Combo1.Text = ""
Combo2.Text = ""
Combo3.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text8.Text = ""
Text9.Text = ""
Text1.SetFocus
End Sub

Private Sub Command5_Click()
Adodc1.Recordset.Delete
Adodc1.Refresh
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
55

Text1.Text = ""
Text2.Text = ""
Combo1.Text = ""
Combo2.Text = ""
Combo3.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub

Private Sub Command6_Click()
BILU = MsgBox("ITA HAKARAK SAI HUSI FORM NE'E...", vbQuestion + vbYesNo,
"INFORMASAUN HUSI MANE-MESAK")
If BILU = vbYes Then
Unload Me
End If
End Sub

Private Sub Command7_Click()
AB = Text3.Text
TU = Text4.Text
UT = Text5.Text
UA = Text6.Text

RSLT = (AB * 0.02) + (TU * 0.2) + (UT * 0.25) + (UA * 0.45)

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
56

If RSLT >= 80 Then
NL_HRF = "A"
OBS = "DIAK"
ElseIf RSLT >= 70 Then
NL_HRF = "B"
OBS = "DIAK OTN"
ElseIf RSLT > 65 Then
NL_HRF = "C"
OBS = "LA DUN DIAK"
Else
NL_HRF = "D"
OBS = "AT LOOS"
End If
Text7.Text = RSLT
Text8.Text = NL_HRF
Text9.Text = OBS
End Sub

Private Sub Form_Deactivate()
Dim AB, TU, UT, UA As String
Dim NL_HRF, OBS As String
End Sub


July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
57

Modul IV
HALO REPORT
Report ho laporan mak dokumentu ka data nebe mak hatama iha
tabela, atu detaile liu ba ita atu hare momos no ita atu print.

Maneira Atu Halo Reportagen Databasse nia prossesu mak hanesan tuir
mai nee :
1. Klick Iha Menu Project, no hili Add Data Enviromment ho nia img mak
hanesan tuir mai nee :

Klik liman los iha command mak nia imagen hanesan tuir mai nee

Hili properties mak nia imagen hanesan tuir mai nee
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
58


Hili miscrosoft Jet 4.0 OLE DB Proviedor nia imagen mak hanesan tuir mai nee


Hili database nebe mak ohin ita kria tiha ona, no rai iha lokasi mak hanesan tuir
mai nee:

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
59

Depois tuir mai ita sei klik iha test connection hili ok ho nia imagen mak
hanesan tuir mai nee

Klik liman los iha command, hili add command ho nia imagen mak hanesan tuir
mai nee

Depoi tuir mai klik liman los iha command1, ita sei hili properties ho nia imagen
mak hanesan tuir mai nee

July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
60

Depois ita hili tiha properties tuir mai hili tan connection mk nx img hnesn
tuir mai nee

Tuir mai ita sei hili tan conection1 nia iha box ida ita hili connection1

Database object ita hili table

Object name ita iha seleksaun ba table nebe iha kria tiha ona klik apply ok nia
imagen mak hanesan tuir mai nee
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
61


Prosesu dadauk liu ne nia resultadu mak hanesan iha leten nee.
Depois tuir mai ita sei hili fali menu project.

Hili Add Data Report ho nia imagen mak hanesan tuir mai nee

Forma tiha imagen hanesan iha okos nee mak ita Aktivu tiha iha command1
nia leten mak dada tama deit ba iha report nia laran maka resultado hanesan
tuir mai nee
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
62


Depois ita aktivu Data Report mak ita sei hilita seleksaun hanesan tuir mai nee

Tuir mai tan iha DatareMember nia ita sei tau tan commando1 no iha
DataSource ita hili data environment, ho nia img mk hnsn tuir mai nee

Klik Run mak nia resultado ikus hanesan tuir mai nee
July 19, 2014
PRATIKA VISUAL BASIC 6.0

Preparado Husi Abilio Ximenes | Treino Dasar Pemogram
Visual Basic 6.0
63



Nama : abilio ximenes

Departamento : Programao

Obrigado Barak Ba Ita Boot Sira Nia Atensaun

MOTO
Koko Rasik Buat Nebee Mak Ita Hare No Rona Tiha Ona.
Prepara Agora Hahu Aban
Keta Halokon Ita Nia Oportunidade Tanba Tempu Nee Osan
Mean

También podría gustarte