Welcome to Abdul Malik Ikhsan's Blog

memanggil Function

Posted in Tutorial VB by samsonasik on October 1, 2007

Kita ambil contoh, aplikasi menghitung luas persegi panjang dengan function bentukan misalnya luaspp, contoh sebagai berikut :
vb.jpg
Berikut source code-nya :
‘function hitung luas persegi panjang
Public Function luaspp(panjang As Integer, lebar As Integer) As Integer
luaspp = panjang * lebar
End Function

‘procedure button diklik
Private Sub Command1_Click()
If (Text1.Text = “”) Then
MsgBox “panjang harus diisi”
Text1.SetFocus
ElseIf (Text2.Text = “”) Then
MsgBox “lebar harus diisi”
Text2.SetFocus
Else

Dim panjang As Integer
Dim lebar As Integer
panjang = Int(Text1.Text)
lebar = Int(Text2.Text)
If (panjang < lebar) Then
MsgBox “panjang tidak boleh kurang dari lebar”
Text2.SetFocus
Else
‘panggil function
Label3.Caption = “Hasil Perhitungan = ” & luaspp(panjang, lebar)
End If
End If
End Sub

‘procedure text ditulisi
Private Sub Text1_keypress(keyascii As Integer)
‘tanda underscore untuk tampilkan seterusnya, tapi terusinnya
‘dibawah

If Not (keyascii >= Asc(“0”) And _
keyascii <= Asc(“9”)) Then
If keyascii <> vbKeyBack Then
keyascii = 0
End If
End If
End Sub

‘procedure text ditulisi

Private Sub Text2_keypress(keyascii As Integer)
‘tanda underscore untuk tampilkan seterusnya, tapi terusinnya
‘dibawah

If Not (keyascii >= Asc(“0”) And _
keyascii <= Asc(“9”)) Then
If keyascii <> vbKeyBack Then
keyascii = 0
End If
End If
End Sub

Advertisements

4 Responses

Subscribe to comments with RSS.

  1. ika said, on December 27, 2007 at 8:45 am

    Pak kalo di PHP bgmn? terimakasih

  2. samsonasik said, on December 28, 2007 at 2:37 am

    Kalau di php kaya’ gini 🙂

    function hitungluas($panjang,$lebar){
    return $panjang*$lebar;
    }
    echo hitungluas(10,2);

  3. sofyan said, on October 4, 2011 at 9:55 am

    mantap

  4. tiwiwidianti23 said, on May 8, 2017 at 9:47 pm

    thanks infonya.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: