26
Private Sub Command1_Click() Dim P1, P2, P3, I1, I2, I3, m As Single V = 220 P1 = Val(txt_l1.Text) P2 = Val(txt_l2.Text) P3 = Val(txt_l3.Text) I1 = Round(P1 / V, 6) I2 = Round(P2 / V, 6) I3 = Round(P3 / V, 6) If I1 > I2 Then If I1 >= I3 Then m = I1 Else m = I3 End If If I2 >= I3 Then m = I2 Else

# Algoritma Dalam bidang komputer, algoritma sangat diperlukan dalam menyelesaikan berbagai masalah pemrograman, terutama dalam komputasi numeris. Tanpa algoritma yang dirancang baik

Embed Size (px)

DESCRIPTION

Citation preview

Private Sub Command1_Click()Dim P1, P2, P3, I1, I2, I3, m As Single

V = 220P1 = Val(txt_l1.Text)P2 = Val(txt_l2.Text)P3 = Val(txt_l3.Text)

I1 = Round(P1 / V, 6)I2 = Round(P2 / V, 6)I3 = Round(P3 / V, 6)

If I1 > I2 Then If I1 >= I3 Then m = I1 Else m = I3 End If If I2 >= I3 Then m = I2 Else m = I3 End IfEnd IfL_1.BackColor = RGB(I1 / m * 255, 0, 0)

L_2.BackColor = RGB(I2 / m * 255, 0, 0)L_3.BackColor = RGB(I3 / m * 255, 0, 0)End Sub

Private Sub Check1_Click()lbl_nama.FontBold = Check1.ValueEnd Sub

Private Sub Check2_Click()lbl_nama.FontItalic = Check2.ValueEnd Sub

Private Sub Command1_Click()lbl_nama.Caption = txt_nama.Text

End Sub

End Sub

Private Sub Command4_Click()List1.Clear List1.Index

End Sub

Private Sub Option1_Click()lbl_nama.ForeColor = vbBlueEnd Sub

Private Sub Option2_Click()lbl_nama.ForeColor = vbRedEnd Sub

Dim angka(1 To 2) As SingleDim operator As String

Private Sub cmdangka_Click(Index As Integer) Text1.Text = Text1.Text & cmdangka(Index).Caption End Sub

Private Sub cmdhapus_Click() Text1.TextEnd Sub

Private Sub cmdhitung_Click()Dim hasil As SingleIf Text1.Text = "" Then Exit Subangka(2) = CSng(Text1.Text)

Select Case operatorCase "+" hasil = angka(1) + angka(2)Case "-" hasil = angka(1) - angka(2)

Case "*" hasil = angka(1) * angka(2)Case "/" hasil = angka(1) / angka(2)End SelectText1.Text = hasil

End Sub

Private Sub cmdoperator_Click(Index As Integer)If Text1.Text = "" Then Exit Subangka(1) = CSng(Text1.Text)operator = cmdoperator(Index).CaptionText1.Text = ""End Sub

'Deklarasi variable globalDim xpos As Single, ypos As Single

Private Sub Form_Load() 'pindahkan posisi roket ke tengah form xpos = (Me.ScaleWidth - PicRoket.Width) / 2 ypos = (Me.ScaleHeight - PicRoket.Height) / 2 PicRoket.Move xpos, yposEnd Sub

Private Sub form_keyDown(KeyCode As Integer, Shift As Integer) 'cek tombol keyboard yang ditekan Select Case KeyCode Case vbKeyLeft 'Tombol panah kiri Call RoketKekiri Case vbKeyRight 'Tombol panah kanan Call RoketKeKanan End SelectEnd Sub

Private Sub form_KeyUp(KeyCode As Integer, Shift As Integer) 'Cek tombol keyboard yang ditekan Select Case KeyCode Case vbKeyUp 'Tombol panah atas Call RoketKeatas Case vbKeyDown 'tombol panah bawah Call RoketKebawah End SelectEnd Sub

Private Sub form_keyPress(KeyAscii As Integer) 'Cek Tombol keyboard yang ditekan If KeyAscii = vbKeyEscape Then 'Tombol Escape If MsgBox("Tutup program ?", vbQuestion + vbYesNo, _ Me.Caption) = vbYes Then Unload Me End IfEnd Sub

Private Sub RoketKekiri() xpos = xpos - 10 'Geser ke kiri 10 pixel If xpos < 0 Then 'Cek bila melewati batas kiri xpos = 0 End If PicRoket.Move xpos 'Pindahkan posisi roketEnd Sub

Private Sub RoketKeKanan() xpos = xpos + 10 'Geser ke kanan 10 pixel

If xpos > Me.ScaleWidth - PicRoket.Width Then 'Cek bila melewati batas kanan xpos = Me.ScaleWidth - PicRoket.Width End If PicRoket.Move xpos 'Pindahkan posisi rocketEnd Sub

Private Sub RoketKeatas() ypos = ypos - 10 'Geser ke atas 10 pixel If ypos < 0 Then 'Cek bila melewati batas atas ypos = 0 End If PicRoket.Move xpos, ypos 'Pindahkan posisi rocketEnd Sub

Private Sub RoketKebawah() ypos = ypos + 10 'Geser ke bawah 10 pixel If ypos > Me.ScaleHeight - PicRoket.Height Then 'Cek bila melewati batas bawah ypos = Me.ScaleHeight - PicRoket.Height End If PicRoket.Move xpos, ypos 'pindahkan posisi roketEnd Sub

Private Sub PicRoket_Click()

End Sub

Private Sub Command1_Click() Dim i As Double Dim o As String i = Val(txt_input.Text) If i < 3.5 Then o = "D" ElseIf i < 5.1 Then o = "C" ElseIf i < 7.1 Then o = "B" Else o = "A" End Iflbl_hasil.Caption = oEnd Sub

Private Sub Command2_Click()If Text1.Text = "A" ThenImage1.Visible = TrueImage1.Picture = LoadPicture("C:\A.JPG")

ElseIf Text1.Text = "B" Then

End If

End Sub

Private Sub list1_DragOver(Source As Control, X As Single, Y As Single, state As Integer) Me.Cls Me.Print "Source : " & Source.Name

Me.Print "X,Y: " & X & "," & Y Me.Print "State: " & stateEnd Sub

Private Sub list1_DragDrop(Source As Control, X As Single, Y As Single) If Source.Name = "Text1" Then List1.AddItem Text1.Text End If Me.ClsEnd Sub

Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, state As Integer) Me.ClsEnd Sub

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single) Me.ClsEnd Sub

Dim test2 As Integer

Private Sub Command1_Click()Dim test2 As String

test1 = "nusantara"

Label1.Caption = test1Label2.Caption = test2Label3.Caption = test3End Sub

Private Sub Command2_Click()test2 = 10Label1.Caption = test1Label2.Caption = test2Label3.Caption = test3End Sub

Private Sub Command3_Click()Const test3 As Single = 90.55

tes3 = 50.22

Label1.Caption = test1Label2.Caption = test2Label3.Caption = test3

End Sub

End Sub

Dim var1 As Single, var2 As SingleDim hasil As Single

End Sub

Private Sub Option1_Click()var1 = Text1.Textvar2 = Text2.Texthasil = var1 + var2Label3.Caption = hasilEnd Sub

Private Sub Option10_Click()var1 = Text1.Textvar2 = Text2.Texthasil = (var1 >= var2)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Option11_Click()

var1 = Text1.Textvar2 = Text2.Texthasil = (var1 <= var2)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Option12_Click()var1 = IIf(Text1.Text = "true", -1, 0)hasil = Not (var1)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Option13_Click()var1 = IIf(Text1.Text = "true", -1, 0)var2 = IIf(Text2.Text = "true", -1, 0)hasil = (var1 Or var2)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Option14_Click()var1 = IIf(Text1.Text = "true", -1, 0)var2 = IIf(Text2.Text = "true", -1, 0)hasil = (var1 And var2)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Option2_Click()var1 = Text1.Textvar2 = Text2.Texthasil = var1 - var2Label3.Caption = hasilEnd Sub

Private Sub Option3_Click()var1 = Text1.Textvar2 = Text2.Texthasil = var1 * var2Label3.Caption = hasilEnd Sub

Private Sub Option4_Click()var1 = Text1.Textvar2 = Text2.Texthasil = var1 / var2Label3.Caption = hasilEnd Sub

Private Sub Option5_Click()var1 = Text1.Textvar2 = Text2.Texthasil = var1 & var2Label3.Caption = hasilEnd Sub

Private Sub Option6_Click()var1 = Text1.Textvar2 = Text2.Texthasil = (var1 > var2)'Label3.Caption = hasilLabel3.Caption = Format(hasil, "true/false")

End Sub

Private Sub Option7_Click()var1 = Text1.Textvar2 = Text2.Texthasil = (var1 < var2)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Option8_Click()var1 = Text1.Textvar2 = Text2.Texthasil = (var1 = var2)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Option9_Click()var1 = Text1.Textvar2 = Text2.Texthasil = (var1 <> var2)Label3.Caption = Format(hasil, "true/false")End Sub

Private Sub Command1_Click()If LCase(Text1.Text) = "nusantara" ThenImage1.Visible = TrueText1.Enabled = FalseCommand1.Enabled = False

ElseIf Label2.Caption >= 3 Then MsgBox "habis"ElseMsgBox "paswordnya salah"Label2 = Label2.Caption + 1Command1.Enabled = True

End If

End Sub

Private Sub Command1_Click()Dim hrg As Currency, total As CurrencyDim jmlh As IntegerDim dskn As SingleDim satuan As StringIf List1.Text = "" Then MsgBox "anda belum memilih barang!!" List1.ListIndex = 0 Exit SubEnd IfSelect Case List1.TextCase "disket" harga = 35000 satuan = "Box"Case "buku" harga = 20000 satuan = "lusin"Case "kertas" harga = 25000 satuan = "Rim"Case "Pulpen" harga = 10000

satuan = "Pak"End Selectlbl_brg.Caption = "barang:" & List1.Textlbl_hrg.Caption = "harga:" & Format(harga, "Currency") & "/" & satuanlbl_jmlh.Caption = "Jmlh:" & Text1.Text & " " & satuanjmlh = Text1.Text

Select Case jmlhCase Is < 10 diskon = 0Case 10 To 20 diskon = 0.15Case Else diskon = 0.2End Select

total = jmlh * (harga * (1 - diskon))lbl_dskn.Caption = "diskon:" & Format(diskon, "0%")lbl_tot.Caption = "total bayar:" & Format(total, "currency")End Sub Private Sub Form_Load()List1.AddItem "disket"List1.AddItem "buku"List1.AddItem "kertas"List1.AddItem "pulpen"End Sub

Private Sub Command1_Click()Dim filename As String

Image1.Picture = Nothingfilename = InputBox("ketikkan path dan nama file gambar:", "open picture file", filename)If filename <> "" Then Image1.Picture = LoadPicture(filename)End IfEnd Sub

Private Sub Tulisteks(teks As String, Optional warna As ColorConstants = vbMagenta) With Label1 .Caption = teks .ForeColor = warna End WithEnd 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("hello", vbRed)End Sub

Private Sub Command2_Click() Label1.Caption = "jumlah =" & jumlahangka()End Sub

End Sub

Private Sub Label1_DblClick() Call Tulisteks("hello")End Sub

Dim i As Integer

Private Sub Command1_Click()List1.Clear

For i = 1 To 100 List1.AddItem "angka" & i If i = 50 Then Exit ForNextEnd Sub

Private Sub Command2_Click()List1.ClearFor i = 100 To 1 Step -2List1.AddItem "angka" & iNext iEnd Sub

Private Sub Command3_Click()List1.Cleari = Asc("A")Do Until i > Asc("Z") List1.AddItem "huruf" & Chr(i) If Chr(i) = "m" Then Exit Do i = i + 1 LoopEnd Sub

Private Sub Command4_Click()List1.Cleari = Asc("Z")Do While i >= Asc("A")List1.AddItem "huruf" & Chr(i)i = i - 1LoopEnd Sub

End Sub

Dim namasiswa() As String

Private Sub Command1_Click() Dim no As Integer, i As Integer no = CInt(Combo1.Text) namasiswa(no) = InputBox("tuliskan nama siswa no : " & no, " inputnama siswa") If namasiswa(no) <> "" Then List1.Clear For i = 1 To UBound(namasiswa) List1.AddItem "namasiswa (" & i & ")=" & namasiswa(i) Next i End If End Sub

Private Sub Command2_Click()Dim num As Integer, i As IntegerIf Not IsNumeric(Text1.Text) Then Exit Subnum = CInt(Text1.Text)

ReDim namasiswa(1 To num)Combo1.ClearList1.ClearFor i = 1 To UBound(namasiswa)Combo1.AddItem iList1.AddItem "namasiswa(" & i & ")=" & namasiswa(i)Next iCombo1.ListIndex = 0

End Sub

Private Sub Form_Load()Dim i As IntegerReDim namasiswa(1 To 5)For i = 0 To 5 Combo1.AddItem iNext i Combo1.ListIndex = 0 End Sub