|
-
Feb 26th, 2000, 01:37 PM
#1
Thread Starter
Member
:confused:
I am working on an assignment that requires a procedure to ask the user when clicking the command button - if he really wants to quit.
I am able to do the if then work but having no help file I cannot find the command to give when they really want to quit the program. (I realize that "end" works with the exit button.
This is what I have:
Dim Response As String
Option Explicit
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdQuit_Click()
'confirm quitting program
picBox.Cls
Response = Val(InputBox("Are you sure you want to quit " & _
"this program (Y/N)?"))
If (UCase(Response)) = "N" Then
picBox.Print "Program returned."
If (UCase(Response)) = "Y" Then
End
Else
End If
End If
End Sub
of course - it isn't working I need help.
MomOf3CollegeStudentTooMuchToDoNeverEnoughTime
Using VB6 Working Model Edition
-
Feb 26th, 2000, 01:53 PM
#2
Frenzied Member
Try this...
Code:
Option Explicit
Private Sub cmdQuit_Click()
Dim nResponse As Integer
nResponse = MsgBox("Are you sure you want to quit?", _
vbYesNo + vbQuestion, "Exit Program")
If nResponse = vbYes Then
Unload Me
End If
End Sub
This will unload the form if the user clicks the "Yes" button. If they click "No" then the program resumes. If unloading the form doesn't exit the program, you can replace "Unload Me" with "End". This is just the way I was taught to do it.
Hope that helps!
~seaweed
Edited by seaweed on 02-27-2000 at 01:55 AM
-
Feb 26th, 2000, 01:58 PM
#3
New Member
Why don't you use the msgbox function ?
Dim msgRep As VbMsgBoxResult
msgRep = MsgBox("Are you sure you want to quit ?", vbYesNo)
If msgRep = vbYes Then
End
End If
If you really want to use the other method well the correct syntax is :
Dim sRep As String
sRep = InputBox("Are you sure you want to quit ?")
If UCase(sRep) = "Y" Then
End
End If
-
Feb 26th, 2000, 02:05 PM
#4
Frenzied Member
P.S...
If you want to use an Input box, as you had in your code, here is the fix. You had your Else and End If's in the wrong place, and you don't need to use Val. Input boxes return the string the user typed in. Val returns the numeric represenation of a string.
Also, just so you know, you should try to stay away from declaring form-level variables like you did for "Response". Since the value of the variable is only used in the sub-procedure, you should declare it there.
Another good idea is, when looking at the string the user typed in, just look at the first letter. That way, "N", "No", "Nope", and "Not for all the tea in China" will be handled the same way. Use the Left$ function for this.
Here is how you can fix what you had:
Code:
Private Sub cmdQuit_Click()
'confirm quitting program
Dim sResponse as String
picBox.Cls
sResponse = InputBox("Are you sure you want to quit " & _
"this program (Y/N)?")
If (UCase(Left$(sResponse, 1))) = "N" Then
picBox.Print "Program returned."
ElseIf (UCase(Left$(sResponse, 1))) = "Y" Then
End
End If
End Sub
I would still go with the message box, though, like most windows programs. Less checking has to be done than with an input box (what if the user just types in garbage?).
Good luck,
~seaweed
Edited by seaweed on 02-27-2000 at 02:22 AM
-
Feb 26th, 2000, 02:15 PM
#5
Thread Starter
Member
Wonderful, now it works. I used the vb boxes.
Take a gander at my previous question.
I am a mom and internet support tech trying to take my CIS courses. I have the working edition which provides no help. When I click on the help file - the response is no help on the VB working model edition. I cannot learn this way!!!
-
Feb 26th, 2000, 02:20 PM
#6
Frenzied Member
For VB help...
Check out Microsoft's MSDN online site. It has the entire MSDN library of help files there on the internet (it just takes a little patience to find what you are looking for).
The address is:
http://msdn.microsoft.com/library/
On the left, click on "Visual Studio 6.0 Documentation", and under that click on "Visual Basic Documentation". From there, explore away!
Good luck,
~seaweed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|