Reputation: 51
Here is my code(partial), when a guest guessed 3 times.
If (counter = 3) And (rx.EOF = True) Then
MsgBox "You guessed too many times! Intruder alert!"
End
.
.
.
Is there a best way to end/freeze this user to protect the program? Any idea will help.
Upvotes: 1
Views: 1683
Reputation: 30398
End is evil, which claims:
... if your program does not exit cleanly without an
End
Statement, then your program contains a bug or bugs. Take out the end statement, and do whatever testing it takes to clean up whatever you had failed to clean up previously.
End
is deprecated in the VB6 manual because it suppresses cleanup events like Form_Unload
and Class_Terminate
. Here's an excerpt from the VB6 manual End
topic:
Note The End statement stops code execution abruptly. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed...
The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms.
Upvotes: 3
Reputation: 2951
You can unload all forms
for example a project which lets you load extra forms, and unload them all
'1 form with:
' 2 command buttons: name=Command1 name=Command2
Option Explicit
Private Sub Command1_Click()
Dim frm As New Form1
frm.Caption = CStr(Now)
frm.Show
End Sub
Private Sub Command2_Click()
UnloadAll
End Sub
Private Sub Form_Load()
Command1.Caption = "load extra"
Command2.Caption = "unload all"
End Sub
Private Sub UnloadAll()
Dim frm As Form
For Each frm In Forms
If frm.hWnd <> Me.hWnd Then
Unload frm
End If
Next frm
Unload Me
End Sub
Be careful though if you have any (neverending) loops running. You need to make sure those are finished first. Also pay attention to controls which are connected to other devices/applications/...
Upvotes: 1