Jumat, 07 Oktober 2016

Procedure dan Function



MATERI 1
 
Private Sub TulisTeks(teks As String, warna As ColorConstants)
With Label1
.Caption = teks
.ForeColor = warna
End With
End Sub

Private Function JumlahAngka() As String
Dim angka1 As String, angka2 As String
Dim hasil As Single
angka1 = InputBox("Tulis angka 1 :", "Jumlah Angka")
angka2 = InputBox("Tulis angka 2 :", "Jumlah Angka")
If angka1 <> "" And angka2 <> "" Then
hasil = CSng(angka1) + CSng(angka2)
JumlahAngka = Cstr(hasil)
End If
End Function

Private Sub Command1_Click()
Call TulisTeks("Hallo", vbRed)
End Sub

Private Sub Command2_Click()
Label1.Caption = "Jumlah = " & JumlahAngka()
End Sub



MATERI 2

Private Function Penjumlahan (ByVal a As Integer, ByVal b As Integer) As Integer
    Hitung = a + b
End Function
 
Private Sub Command1_Click()
 
    Dim a As Single
    Dim b As Single
    Dim hasil As Integer
    
    a = 10.5
    b = 5.25
 
    hasil = Penjumlahan (a, b)
 
    MsgBox hasil 
 
End Sub


Private Sub Penjumlahan(Nilai1 As Single, Nilai2 As Single)
 
    Dim HasilPerhitungan As Single
    
    HasilPerhitungan = Nilai1 + Nilai2
    MsgBox HasilPerhitungan
 
End Function
 
Private Sub Button1_Click()
    HasilPerhitungan = Penjumlahan(100, 200)
End Sub




Tidak ada komentar:

Posting Komentar