Untuk perintah IF atur propertiesnya seperti dibawah ini
1. Label 1, caption = jumlah barang
2. Label 2, caption = keterangan
3. command1, caption = ok
4. command2, caption = hapus
5. command3, caption = exit
Setelah itu ketikan program dibawah ini
Private Sub Command1_Click()
If Text1 = "" Then
MsgBox "JUMLAH BARANG mohon didisi"
End If
If Val(Text1) <= 1000 Then Text2 = "order" End If If Val(Text1) >= 1001 Then
Text2 = "warning"
End If
If Val(Text1) >= 2001 Then
Text2 = "lebih"
End If
If Val(Text1) >= 3001 Then
Text2 = "sangat lebih"
End If
MsgBox "Nama Barang = " & Text1 & ",Keterangan= " & Text2, vbOKOnly, "data"
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub text1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then
MsgBox "yang anda ketikan bukan angka"
KeyAscii = 0
End If
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
End Sub
Private Sub Command4_Click()
Form2.Show
End Sub
Dan Perintah CASE untuk form nya sama saja dengan perintah IF, kecuali programnya sedikit berbeda dapat sobat lihat seperti dibawah ini:
Private Sub Command1_Click()
If Text1 = "" Then
MsgBox "UMUR TIDAK BOLEH KOSONG"
End If
Select Case Val(Text1)
Case 0 To 5
Text2 = "bayi"
Case 6 To 10
Text2 = "Anak-Anak"
Case 11 To 20
Text2 = "Remaja"
Case 21 To 35
Text2 = "dewasa"
Case Is > 36
Text2 = "dewasa bangat"
End Select
MsgBox "Usia = " & Text1 & ",Keterangan= " & Text2, vbOKOnly, "data"
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub text1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then MsgBox "yang anda ketikan bukan angka" KeyAscii = 0 End If End Sub
selamat mencoba semoga bermanfaat Catatan : Jangan Lupa Baca dan Klik Dibawah ini ya
0 komentar:
Posting Komentar