Pages

Friday, 28 June 2013

Visual Basic Pertemuan X

Pertemuan X

Hari/Tanggal      : Selasa, 11 Juni 2013
Pokok Bahasan  :

                                1.    Review
                                2.    Mendalami array
                                3.    Memahami fungsi
                               
Review
1.    Start
2.    A 5    
3.    B 7
4.    C A2+B2
5.    CETAK C
6.    SELESAI

# If
1.    Mulai
2.    Total_beli

Dim A,B,C As byte
A=5
B=7
C=A^2+B^2
Print c

Private sub cmd bayar_click()
Dim total_beli as long
Dim bayar as single
Dim bonus as single

Total_beli=val (txt total.beli.text)
Bayar=val (txt bayar.text)
Bonus=val (txt bonus.text)
   If(total_beli>5000000) then
   bonus=0,05 * total_beli
Else
   Bonus=0
end if
Bayar =total_beli-bonus
Txt bayar.text=str(bayar)
End sub


# Dik     : Suatu  matriks A sbb:
                            

    Dim A (3,3) as byte
    Dim B (3,3) as byte
    A (1,1)=2
    A (1,2)=3
    A (1,3)=4
    A (1,1)=0
    A (1,2)=1
    A (1,3)=5
    A (1,1)=2
    A (1,2)=3
    A (1,3)=2
          Kolom
       Baris

    B(1,1)=2:       B(1,2)=1 :        B(1,3)=2
    B(2,1)=2:       B(2,2)=2 :        B(2,3)=2
    B(3,1)=3:       B(3,2)=2 :        B(3,3)=1

    For i =1 to 3 step 1
    For j = 1 to 3 step 1
         C (ij)=A (i,j) + B(i,j)
       Next j
    Next i

# Fungsi (function)   
     Blok kode program yang disusun secara sistem matis untuk menghasilkan suatu nilai

   Terdapat 2 jenis fungsi yaitu;
1.)    Built-in function
Fungsi yg sudah di sediakan oleh bahasa pemrogram
Cth : val, str, left, right, mid
2.)    User defined function
Fungsi yang diciptakan oleh programer

A.    User detined function
Syntax :
     Function ivame fungsi ([parameter]) as tipe data
               [deklarasi]
               [pernyataan]
                     Nama fungsi = nilai
                End function

Contoh :
Buatlah fungsi menjumlah kan 2 buah bilangan function jumlah A B (A As byte, B As byte) As integer
Dim C as integer
     C= A+B
   Jumlah AB=C
End function

# Langkah-langkah membuat program :
* deklarasi variabel
* mengkonversi teks ke angka
* oprator
* pernyataan if
* pernyataan select case
* pernyataan for-next
* pernyataan while-wend
* pernyataan do-while
* array
* fungsi
* subrutin
* file
* grafik
* database


1.    Deklarasi variabel
Cth : Dim A as byte
         Dim alamat as long
2.    MENGKONVERSI TEKS KE ANGKA
Cth : val (txt.text) ubah ke angka
         str angka ke text

Fungsi built-in
   Fungsi yang sudah di sediakan oleh VB
Jenis-jenis fungsi built-in :
1)    Fungsi keluaran
print,printf
2)    Fungsi pengubah nilai
val,str
3)    Fungsi string = left,mid,right,ucase

Contoh :
Dim kiri as string * 50
Dim kampus as string * 100
Kampus =”unika st.thomas”

Kiri=left (kampus,3)
Print kiri ‘ uni ‘
Kanan=right (kampus,3)
Print kanan ‘ mas ‘
Tengah=mid (kampus ,5,3)
Print tengah ‘a  s ‘
Besar=ucase (kampus)
Print ‘UNIKA ST THOMAS
     4)    Fungsi trigonometri
             contoh : sin,cos,tan,atan,asin,acos
     5)    Fungsi grafik
             contoh : circle,line,arc

Contoh Fungsi
1.    Contoh antar muka program
      
 1.  Buat fungsi untuk menjumlahkan nilai  A+B
        1.)     Buka kode editor  parameter
                    Function jumlah ( Dim  A,B as byte) as byte
                       Dim C as byte
                      C = A + B
                      Jumlah  = C
                    End function
        2.)    Klik ganda cmdC
                    Private sub cmdC_click()
                       Dim A,B,C As byte
                        A = val (txta.text)
                        B = val (txtb.text)
                        C = jumlah (A,B)
                        txtC.text  = str (C)
                       End sub
  2.   Buatlah fungsi untuk
           Menampilkan  strik “Unika St. Thomas”
           Jika form di klik
              1.)    Buka kode editor
                       Function kampus () As bolean
                         Msgbox (“Unika st. Thomas”)
                            Kampus = true
                       End function
             2.)    Klik ganda form
                       Private sub form-click()
                         Panggil fungsi
                          Kampus ()
                       End sub

No comments :

Post a Comment