Saturday, May 28, 2011

LA4 AP2A (Database pada VB6.0) Tanggal 28 Mei 2011

Listing

Option Explicit
Dim Rs As New ADODB.Recordset

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

Private Sub Command3_Click()
With Rs
        .Delete
    End With
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text1.SetFocus
End Sub

Private Sub Command4_Click()
Unload Me
End Sub

Private Sub Form_Load()
    Dim Adodc1 As String

    'Koneksi database
    With Rs
        Adodc1 = App.Path & "\Database1.mdb"
        .ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Teknik Informatika\Latihan Pemrograman\VB 6.0\Data Base\Database1.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
      .CursorLocation = adUseClient
        .LockType = adLockOptimistic
       .CursorType = adOpenStatic
        .Source = "select * from Table1"
        .Open
    End With

    Set DataGrid1.DataSource = Rs
    DataGrid1.Refresh

End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set Rs = Nothing
End Sub
Private Sub Command2_Click()
With Rs
        .AddNew
        .Fields("nama").Value = Text1.Text
        .Fields("npm").Value = Text2.Text
        .Fields("kelas").Value = Text3.Text
        .Update
    End With
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text1.SetFocus
End Sub

Microsoft Access 2007



Design Form1 VB6.0

Adodc Properties





 


 Output


Saturday, May 21, 2011

LA3 AP2A (Menu dan PopUp Menu pada VB6.0) tanggal 21 Mei 2011

Sebelumnya gw mo ngasih tau klo LA bagian ini gw g make PopUpMenu soalnya gw lupa codingan bwt PopUpMenu tuh gimana. Jadi gw cuma ngbahas Menu Editor aja..

Listing

MDIForm1
Private Sub about_Click()
MsgBox "Design by Adjie Putra Nugraha", vbInformation, "Info"
End Sub

Private Sub exit_Click()
If MsgBox("Anda Yakin Ingin Keluar ?", vbYesNo + vbInformation, "Exit") = vbYes Then
End
End If
End Sub

Private Sub kalkulator_Click()
Form1.Show
MDIForm1.Hide
End Sub

Private Sub text_Click()
Form2.Show
MDIForm1.Hide
End Sub

Private Sub warna_Click()
Form3.Show
MDIForm1.Hide
End Sub

Form1
Private Sub Command1_Click()
Text1.text = ""
Text2.text = ""
Text3.text = ""
End Sub

Private Sub Command2_Click()
MDIForm1.Show
Form1.Hide
End Sub

Private Sub Command3_Click()
Text3.text = Val(Text1.text) + Val(Text2.text)
End Sub

Private Sub Command4_Click()
Text3.text = Val(Text1.text) - Val(Text2.text)
End Sub

Private Sub Command5_Click()
Text3.text = Val(Text1.text) * Val(Text2.text)
End Sub

Private Sub Command6_Click()
Text3.text = Val(Text1.text) / Val(Text2.text)
End Sub

Form2
Private Sub Check1_Click()
If Check1.Value = 1 Then
Label1.FontBold = True
Else
Label1.FontBold = False
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = 1 Then
Label1.FontItalic = True
Else
Label1.FontItalic = False
End If
End Sub

Private Sub Check3_Click()
If Check3.Value = 1 Then
Label1.FontUnderline = True
Else
Label1.FontUnderline = False
End If
End Sub

Private Sub Command1_Click()
MDIForm1.Show
Form2.Hide
End Sub

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

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

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

Form3
Private Sub Command1_Click()
Form1.BackColor = Text1.BackColor
Form2.BackColor = Text1.BackColor
Form3.BackColor = Text1.BackColor
MDIForm1.BackColor = Text1.BackColor
End Sub

Private Sub warna()
Text1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub Command2_Click()
Form1.BackColor = &H8000000F
Text1.BackColor = &H8000000F
End Sub

Private Sub Command3_Click()
MDIForm1.Show
Form3.Hide
End Sub

Private Sub HScroll1_Change()
warna
Label4.Caption = HScroll1.Value
End Sub

Private Sub HScroll2_Change()
warna
Label5.Caption = HScroll2.Value
End Sub

Private Sub HScroll3_Change()
warna
Label6.Caption = HScroll3.Value
End Sub

Output








LA2 AP2A (Percabangan pada VB6.0) tanggal 14 Mei 2011

Listing

Form1
Private Sub Command1_Click()
If Text1.Text = "vb" And Text2.Text = "ia13" Then
MsgBox "Correct", vbInformation, "Login"
Form2.Show
Form1.Hide
Else
MsgBox "Incorrect", vbInformation, "Login"
End If
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub Command3_Click()
End
End Sub

Form2
Private Sub Check1_Click()
If Check1.Value = 1 Then
Label1.FontBold = True
Else
Label1.FontBold = False
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = 1 Then
Label1.FontItalic = True
Else
Label1.FontItalic = False
End If
End Sub

Private Sub Check3_Click()
If Check3.Value = 1 Then
Label1.FontUnderline = True
Else
Label1.FontUnderline = False
End If
End Sub

Private Sub Check4_Click()
If Check1.Value = 1 Then
Label1.FontStrikethru = True
Else
Label1.FontStrikethru = False
End If
End Sub

Private Sub Check5_Click()
If Check4.Value = 1 Then
Label1.Caption = UCase(Text1.Text)
Else
Label1.Caption = LCase(Text1.Text)
End If
End Sub

Private Sub Combo1_Click()
Label1.FontName = Combo1.Text
End Sub

Private Sub Command1_Click()
Form1.Show
Form2.Hide
End Sub

Private Sub Command2_Click()
Form2.BackColor = QBColor(Rnd() * 15)
End Sub

Private Sub Form_Load()
Combo1.AddItem "Algerian"
Combo1.AddItem "Times New Roman"
Combo1.AddItem "Comic Sans Ms"
Combo1.AddItem "Courier New"
Combo1.AddItem "Verdana"
End Sub

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

Private Sub Option2_Click()
Label1.ForeColor = vbBlack
End Sub

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

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

Private Sub Option5_Click()
Label1.ForeColor = vbGreen
End Sub

Private Sub Text1_Change()
Label1.Caption = Text1.Text
End Sub

Output


Monday, May 9, 2011

LA3 AP2B (Pengunaan Fungsi def pada Ruby) Tanggal 9 Mei 2011

Listing

def persegi()
      print "Masukan Panjang Sisi: "
      x=gets.to_i
      l = x**2
      puts "Luasnya Adalah: #{l}"
      puts ""
end
def prima()
      print "Masukkan Angka: "
      y=gets.to_i
      b=0
      for i in 1..y
            if y%i==0
                 b=b+1
            end
      end
      if b==1 then
            puts "#{y} adalah Bilangan Prima"
            puts ""
      elsif b==2 then
            puts "#{y} adalah Bilangan Prima"
            puts ""
      else
            puts "#{y} adalah Bukan Bilangan Prima"
            puts ""
      end
end
def menu()
      pil=1
      until pil==3
            puts "="*24
            puts "==========Menu=========="
            puts "1.Luas Persegi"
            puts "2.Seleksi Bilangan Prima"
            puts "3.Selesai"
            puts "="*24
            print "Masukan Pilihan Anda [1/2/3]: "
            pil=gets.to_i
            if pil==1
                  persegi()
            elsif pil==2
                  prima()
            else
                  puts "Selesai"
                  puts ""
            end
      end
end
menu()


Output

Sunday, May 1, 2011

Contoh Program If Bersarang pada Python

Listing Program

x=0
while x!=3:
    print '===================='
    print '====== Log In ======'
    print '===================='
    a=raw_input('Username: ')
    b=raw_input('Password: ')
    if a == 'Adjie' and b == 'blank':
        print 'Login Successed'
        print ''
        print ''
        print ''
        print ''
        y=0
        while y!=1:
            print '=============================='
            print '============ Menu ============'
            print '=============================='
            print '= 1. Luas Segitiga ='
            print '= 2. Luas Persegi ='
            print '= 3. Luas Lingkaran ='
            print '= 4. Kalkulator ='
            print '= 5. Array Nama ='
            print '= 6. Deret Fibonacci ='
            print '= 7. Deret Bilangan Ganjil ='
            print '= 8. Deret Bilangan Genap ='
            print '= 9. Deret Bilangan Asli ='
            print '= 10. Keluar ='
            print '=============================='
            c=raw_input('Masukkan Menu Pilihan di Atas: ')
            if c == '1':
                 alas=float(input('Masukkan Alas Segitiga: '))
                 tinggi=float(input('Masukkan Tinggi Segitiga: '))
                 print 'Luas Segitiga:',alas*tinggi/2
                 print ''
                 if y!=1:
                    bb=raw_input('Do You Want to Exit (y/n)? ')
                    if bb=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '2':
                 sisi=input('Masukkan Sisi Persegi: ')
                 print 'Luas Persegi:',sisi**2
                 print ''
                 if y!=1:
                    bc=raw_input('Do You Want to Exit (y/n)? ')
                    if bc=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '3':
                 jari_jari=float(input('Masukkan Jari-jari Lingkaran: '))
                 print 'Luas Lingkaran:',3.14*jari_jari*jari_jari
                 print ''
                 if y!=1:
                    bd=raw_input('Do You Want to Exit (y/n)? ')
                    if bd=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '4':
                 ab=float(input('Masukkan Angka Pertama: '))
                 ac=float(input('Masukkan Angka Kedua: '))
                 print 'Hasil Penjumlahan:',ab+ac
                 print 'Hasil Pengurangan:',ab-ac
                 print 'Hasil Perkalian:',ab*ac
                 print 'Hasil Pembagian:',ab/ac
                 print 'Hasil Modulus:',int(ab%ac)
                 print ''
                 if y!=1:
                    be=raw_input('Do You Want to Exit (y/n)? ')
                    if be=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '5':
                 data=input('Masukkan Banyak Data: ')
                 base=[]
                 loop=0
                 while loop!=data:
                    print 'Masukkan Nama ke ',loop+1,': ',
                    nama=raw_input()
                    base.append(nama)
                    loop=loop+1
                 if loop == data:
                    print 'Nama-nama yang Telah Dimasukkan:', base
                 print ''
                 if y!=1:
                    bf=raw_input('Do You Want to Exit (y/n)? ')
                    if bf=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '6':
                 angka=input('Masukkan Panjang Deret: ')
                 d = [0,1]
                 for z in range (angka):
                    if z>1:
                         print d[z-1]+d[z-2],
                         d.append(d[z-1]+d[z-2])
                    else:
                         print d[z],
                 print ''
                 print ''
                 if y!=1:
                    bg=raw_input('Do You Want to Exit (y/n)? ')
                    if bg=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '7':
                 ganjil=input('Masukkan Angka Deret yang Terakhir: ')
                 def bilanganganjil(af):
                    while af!=ganjil:
                         print af,
                         af=af+2
                    print ganjil
                 bilanganganjil(1)
                 print ''
                 if y!=1:
                    bh=raw_input('Do You Want to Exit (y/n)? ')
                    if bh=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '8':
                 genap=input('Masukkan Angka Deret yang Terakhir: ')
                 def bilangangenap(ag):
                    ag=ag-1
                    while ag!=genap:
                         print ag,
                         ag=ag+2
                    print genap
                 bilangangenap(1)
                 print ''
                 if y!=1:
                    bi=raw_input('Do You Want to Exit (y/n)? ')
                    if bi=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '9':
                 asli=input('Masukkan Panjang Deret: ')
                 def bilanganasli(az):
                    az=az-1
                    while az!=asli:
                         az=az+1
                         print az,
                    print ''
                    print ''
                 bilanganasli(1)
                 if y!=1:
                    bj=raw_input('Do You Want to Exit (y/n)? ')
                    if bj=='y':
                         print 'Program Close'
                         print ''
                         break
                    else:
                         print 'Back to Menu'
                         print ''
            elif c == '10':
                 ex=raw_input('Are You Sure to Exit (y/n)? ')
                 if ex == 'y':
                    print 'Program Exit'
                    print ''
                    break
                 else:
                    print 'Program Back to Menu'
                    print ''
            else:
                 print 'Program Back to Menu'
                 print ''
    elif a == 'exit' and b == 'exit':
        e=raw_input('Are You Sure to Cancel Login (y/n)? ')
        if e == 'y':
            print 'Program Close'
            print ''
            break
        else:
            print 'Please Try Again to Login'
            print ''
    elif a == 'Adjie' or b == 'blank':
        print 'Username or Password is Incorrect'
        print 'Please Try Again'
        print ''
    else:
        print 'Please Try Again'
        print ''
    x=x+1
if x==3:
    print 'You Have Three Times to Login'

Output Program

Latihan Bahasa Pemrograman