ให้นักศึกษา ออกแบบ หน้าจอ(Output) ดังนี้
จากนั้นให้เขียน Code ดังต่อไปนี้
-----------------------------------------------------------------
Private Sub comCancel_Click()
If MsgBox("คุณต้องการยกเลิกการทำงานหรือไม่",
vbInformation + vbYesNo, "เดียวก่อนนะ...!!!") = vbYes Then
Unload Me
End If
End Sub
Private Sub comNew_Click()
txtUser.Text =
""
txtPass.Text =
""
txtUser.SetFocus
End Sub
Private Sub comOK_Click()
txtUser.SetFocus
Static count As Integer
Const password As String = "1234"
If txtPass.Text = password Then
MsgBox "สวัสดีคุณ " & txtUser.Text
& vbCrLf & "รหัสผ่านของคุณถูกต้อง"
Form2.Show
Unload Me
ElseIf count = 2 Then
MsgBox "ป้อนรหัสผิด 3 ครั้ง ออกจากโปรแกรม",
vbOKOnly, "แจ้งความผิดพลาด"
Unload Me
Else
count = count + 1
MsgBox "ป้อนรหัสผิดครั้งที่" & count,
vbOKOnly, "เตือน"
End If
End Sub
Private Sub Form_Load()
txtUser.Text = ""
txtPass.Text = ""
End Sub
Private Sub txtPass_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then Call comOK_Click
End Sub
---------------------------------------------------------------------------
ไม่มีความคิดเห็น:
แสดงความคิดเห็น