Sunday, November 3, 2013

koding visual basic


Private Sub cmdSpin_Click()
Image1.Visible = False
Label1.Caption = Int(Rnd * 10) ' pick numbers
Label2.Caption = Int(Rnd * 10)
Label3.Caption = Int(Rnd * 10)
'if any caption is 7 display coin stack and beep
If (Label3.Caption = 7) Or (Label2.Caption = 7) Or (Label3.Caption = 7) Then
 Image1.Visible = True
 Beep
 End If
End Sub
Private Sub cmEnd_Click()
End
End Sub
Private Sub Form_Load(
End Sub
Private Sub cmdExit_Click()
 Unload Me
End Sub

Private Sub cmdOk_Click()
  txtLcase.Text = LCase(txtString)
  txtUcase.Text = UCase(txtString)
  txtLtrim.Text = LTrim(txtString)
  txtRtrim.Text = RTrim(txtString)
  txtLeft.Text = Left(txtString, 4)
  txtRight.Text = Right(txtString, 4)
  txtMid.Text = Mid(txtString, 2, 4)
  txtLen.Text = Len(txtString)
End Sub
Private Sub Form_Load()
End Sub
Private Sub Check1_Click()

End Sub

Private Sub Check2_Click()

End Sub

Private Sub Command1_Click()

End Sub

Private Sub Command2_Click()

End Sub

Private Sub chkMiring_Click()
lblNama.FontItalic = chkMiring.Value
End Sub

Private Sub chkTebal_Click()
lblNama.FontBold = chkTebal.Value
End Sub

Private Sub cmdOk_Click()
lblNama.Caption = txtNama.Text
End Sub

Private Sub cmdSelesai_Click()
Unload Me
End Sub

Private Sub Form_Load()

End Sub

Private Sub optBlue_Click()
lblNama.ForeColor = vbBlue

End Sub

Private Sub optRed_Click()
lblNama.ForeColor = vbRed
End Sub
Dim M(2, 3) As Integer
Dim N(2, 3) As Integer
Dim MN(2, 3) As Integer

Private Sub Command1_Click()
For i = 1 To 2
For j = 1 To 3
MN(i, j) = M(i, j) + N(i, j)
lstMN.AddItem "MN(" & i & "," & j & ") : " & MN(i, j)
Next j
Next i
End Sub
Private Sub Command2_Click()
lstMN.Clear
Erase MN
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
M(1, 1) = 100
M(1, 2) = 200
M(1, 3) = 300
M(2, 1) = 200
M(2, 2) = 100
M(2, 3) = 800
N(1, 1) = 8100
N(1, 2) = 2040
N(1, 3) = 3040
N(2, 1) = 2300
N(2, 2) = 1200
N(2, 3) = 4800
For i = 1 To 2
For j = 1 To 3
lstM.AddItem "M(" & i & "," & j & ") : " & M(i, j)
lstN.AddItem "N(" & i & "," & j & ") : " & N(i, j)
Next j
Next i
End Sub
Dim Kesempatan As Integer

Private Sub cmdOk_Click()
Kesempatan = Kesempatan + 1
If (LCase(Text1.Text) = "nusantara") And (Kesempatan <= 3) Then
  Picture1.Visible = True
  Text1.Enabled = False
  cmdOk.Enabled = False
Else
  MsgBox "Passwordnya Salah!"
  If Kesempatan < 3 Then
   Text1.Text = ""
   Text1.SetFocus
  Else
   End
 End If
End If

End Sub

Private Sub Form_Load()

End Sub
 ---
Private Sub Form_Load()
cmbNama.AddItem "Umar"
cmbNama.AddItem "Salman"
cmbNama.AddItem "Halimah"
cmbNama.AddItem "Shafira"
cmbNama.ListIndex = 0
End Sub
Private Sub cmdAdd_Click()
lstNama.AddItem cmbNama.Text
cmbNama.SetFocus
End Sub
Private Sub cmdDelete_Click()
If lstNama.ListIndex >= 0 Then
lstNama.RemoveItem lstNama.ListIndex
Else
 MsgBox " Pilih Dahulu item pada ListBox", vbCritical + vbOKOnly
End If
End Sub
Private Sub CmdClear_Click()
lstNama.Clear
cmbNama.SetFocus
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdTampil_Click()
txtTampil.Text = " selamat datang di visual basic "
End Sub

Private Sub cmdTutup_Click()
  Unload Me
End Sub

Private Sub Text1_Change()

End Sub

Private Sub Form_Load()

End Sub

Private Sub CmdClear_Click()
LblMessage.Caption = ""

End Sub

Private Sub cmdEnglish_Click()
LblMessage.Caption = "hello world"
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdPrint_Click()
  PrintForm
End Sub

Private Sub cmdSpanyol_Click()
LblMessage.Caption = "hola mundo "
End Sub

Private Sub Form_Load()
frmSebelas.BackColor = vbBlue
End Sub
Private Sub cmdBegin_Click()
Picture2.Visible = True
Timer1.Enabled = True
End Sub
Private Sub cmdEnd_Click()
Unload Me
End Sub

Private Sub Form_Load()

End Sub

Private Sub Timer1_Timer()
If bounces < 5 Then 'depending on bounces, we'll
If (bounces Mod 2 = 0) Then 'fall down
Picture2.Move Picture2.Left - 530, Picture2.Top + 900
Beep
bounces = bounces + 1
Else 'bounce up
Picture2.Move Picture2.Left - 530, Picture2.Top - 320
bounces = bounces + 1
End If
Else 'slide across bottom
Picture2.Move Picture2.Left - 530, Picture2.Top
bounces = bounces + 1
End If
' after bouncing start smoke cloud
If bounces = 7 Then
Picture2.Visible = False
Picture3.Visible = True
Picture4.Visible = True
Timer1.Enabled = False
cmdBegin.Enabled = False
Timer2.Enabled = True ' see Timer2_Timer for cloud
bounces = 0
End If
End Sub
Private Sub Timer2_Timer()
If bounces < 7 Then
Picture4.Move Picture4.Left + 400, Picture4.Top - 500
bounces = bounces + 1
Else
Timer2.Enabled = False
End If
End Sub
Dim var1 As Single, var2 As Single
Dim hasil As Single

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub Form_Load()
  txtVar1.Text = ""
  txtVar2.Text = ""
  lblHasil.Caption = ""
End Sub



Private Sub optTidaksamadengan_Click()
 var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = (var1 <> var2)
  lblHasil.Caption = Format(hasil, "True/False")
End Sub

Private Sub optLebihkecilsamadengan_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = (var1 <= var2)
  lblHasil.Caption = Format(hasil, "True/False")
End Sub

Private Sub optNot_Click()
  var1 = IIf(txtVar1.Text = "true", -1, 0)
  hasil = Not (var1)
  lblHasil.Caption = Format(hasil, "true/false")

End Sub

Private Sub optOr_Click()
  var1 = IIf(txtVar1.Text = "True", -1, 0)
  var2 = IIf(txtVar2.Text = "True", -1, 0)
  hasil = (var1 Or var2)
  lblHasil.Caption = Format(hasil, "True/False")

End Sub

Private Sub optAnd_Click()
  var1 = IIf(txtVar1.Text = "True", -1, 0)
  var2 = IIf(txtVar2.Text = "True", -1, 0)
  hasil = (var1 And var2)
  lblHasil.Caption = Format(hasil, "True/False")

End Sub

Private Sub optKurang_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = var1 - var2
  lblHasil.Caption = hasil
End Sub

Private Sub optKali_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = var1 * var2
  lblHasil.Caption = hasil
End Sub

Private Sub optbagi_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = var1 / var2
  lblHasil.Caption = hasil
End Sub

Private Sub optgabung_Click()
var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = var1 & var2
  lblHasil.Caption = hasil
End Sub

Private Sub optLebihbesar_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = (var1 > var2)
  lblHasil.Caption = Format(hasil, "True/False")
End Sub

Private Sub optSamadengan_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = (var1 = var2)
  lblHasil.Caption = Format(hasil, "True/False")
End Sub

Private Sub optLebihdarisamadengan_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = (var1 >= var2)
  lblHasil.Caption = Format(hasil, "True/False")
End Sub

Private Sub optKurangdari_Click()
  var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = (var1 < var2)
  lblHasil.Caption = Format(hasil, "True/False")
End Sub

Private Sub optTambah_Click()
 var1 = txtVar1.Text
  var2 = txtVar2.Text
  hasil = var1 + var2
  lblHasil.Caption = hasil
End Sub
Dim njmlbil As Integer
Dim x As Integer

Private Sub CmdClear_Click()
txtAkhir.Text = ""
txtAwal.Text = ""
txtJmlbil.Text = ""
End Sub
Private Sub cmdDoLoopWhile_Click()
njmlbil = 0
x = Val(txtAwal)
Do
njmlbil = njmlbil + x
x = x + 1
Loop While x <= Val(txtAkhir)
txtJmlbil = Str(njmlbil)
End Sub



Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdHitungFor_Click()
njmlbil = 0
For x = Val(txtAwal) To Val(txtAkhir) Step 1
njmlbil = njmlbil + x
Next
txtJmlbil = Str(njmlbil)
End Sub
Private Sub cmdHitungWhile_Click()
njmlbil = 0
x = Val(txtAwal)
Do While x <= Val(txtAkhir)
njmlbil = njmlbil + x
x = x + 1
Loop
txtJmlbil = Str(njmlbil)
End Sub
Private Sub cmdUntil_Click()
njmlbil = 0
x = Val(txtAwal)
Do
njmlbil = njmlbil + x
x = x + 1
Loop Until x > Val(txtAkhir)
txtJmlbil = Str(njmlbil)

End Sub


Private Sub Form_Load()

End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub File1_Click()
SelectedFile = File1.Path & "\" & File1.FileName
Image1.Picture = LoadPicture(SelectedFile)
End Sub

Private Sub Form_Load()

End Sub