e.cancel simple problem??

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2007
Posts: 11
Reputation: Fritzeh is an unknown quantity at this point 
Solved Threads: 0
Fritzeh Fritzeh is offline Offline
Newbie Poster

e.cancel simple problem??

 
0
  #1
Apr 1st, 2008
Hey people, just a quick one here, as its getting quite annoying. Basically i want the form to only be closed when a correct password is entered using the form closing event. i have tried the following methods but they all seem to crash... any ideas?

They all start with the following initial code:
  1. Dim strPass As String = "123" ' The default password for exit
  2.  
  3. Dim givenPass = InputBox("Please enter password to quit", "Quit?")

  1. If MsgBoxResult.Ok Then
  2. Select Case givenPass = strPass
  3. Case givenPass = Not strPass Or givenPass = ""
  4. e.Cancel = True
  5. End Select
  6.  
  7. ElseIf MsgBoxResult.Cancel Then
  8. e.Cancel = True
  9.  
  10. End If

  1. If (givenPass = "" Or givenPass = Not strPass) And MsgBoxResult.Ok Then
  2. ' MsgBox("Password incorrect, please try again or consult user guide")
  3. ' e.Cancel = True
  4. ' ElseIf Windows.Forms.DialogResult.Cancel = True Then
  5. ' ElseIf givenPass = strPass Then
  6. ' End
  7. 'Else
  8. ' MsgBox("Unknown error, please try again")
  9. 'End If

  1. Try
  2.  
  3. 'Select Case MsgBoxResult.Ok And givenPass = strPass
  4. 'Do Nothing
  5. ' Case MsgBoxResult.Ok And givenPass = Not strPass Or givenPass = ""
  6. ' e.Cancel = True
  7. ' Case MsgBoxResult.Cancel
  8. ' e.Cancel = True
  9. ' End Select
  10.  
  11. ' Catch ee As Exception
  12. 'Throw ee
  13. ' End Try

any ideas? Thanks for any help in advance
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: e.cancel simple problem??

 
0
  #2
Apr 1st, 2008
i think this code is alright.
Last edited by Jx_Man; Apr 1st, 2008 at 4:51 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 11
Reputation: Fritzeh is an unknown quantity at this point 
Solved Threads: 0
Fritzeh Fritzeh is offline Offline
Newbie Poster

Re: e.cancel simple problem??

 
0
  #3
Apr 1st, 2008
I have tried all 3, hence the commenting out, VB JIT debugger tried to handle it.

Basically ok works if the password is correct or there isnt one, if its wrong i think it crashes or if i hit cancel.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3
Reputation: johnny3d is an unknown quantity at this point 
Solved Threads: 1
johnny3d's Avatar
johnny3d johnny3d is offline Offline
Newbie Poster

Re: e.cancel simple problem??

 
0
  #4
Apr 1st, 2008
Try this:

  1. Dim strPass As String = "123" ' The default password for exit
  2. Dim givenPass = InputBox("Please enter password to quit", "Quit?")
  3. If givenPass = strPass Then
  4. 'do nothing.. let them leave
  5. ElseIf givenPass = "" Then
  6. 'user click the cancel button
  7. MsgBox("You must enter a password.")
  8. e.Cancel = True
  9. Else
  10. 'password is wrong
  11. MsgBox("Your password is not correct. Please try again.")
  12. e.Cancel = True
  13. End If

Hope this helps,

Johnny
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 11
Reputation: Fritzeh is an unknown quantity at this point 
Solved Threads: 0
Fritzeh Fritzeh is offline Offline
Newbie Poster

Re: e.cancel simple problem??

 
0
  #5
Apr 2nd, 2008
Thank you Johnny, it works! I think my problem was I wasnt keeping it simple enough.. Thank you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC