Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Halting code

Status
Not open for further replies.

mike777

Programmer
Jun 3, 2000
387
0
0
US
I need to halt code when the user selects "cancel" in a msgbox. I try
Code:
End
,
and the code halts, but the program also exits itself. Same with
Code:
Stop
,
but with "Stop", first there is a dialog box stating "Stop encountered".
Code:
Exit Sub
no good, since the procedure is nested inside another. The nested procedure halts, but the 'parent' procedure does not.
Thanks for your help. [sig][/sig]
 
Change your sub into a function:

Public Function <CurrentSubName>() As Boolean

and then if you want to cancel the routine, set the function name to False, and in the parent, instead of just calling the sub do:

If Not <CurrentSubName> Then
Exit Sub
End if
<other code that should run if child sub did not fail>

Simon [sig][/sig]
 
If I understand your question right;

Dim intReply as Integer
intReply = MsgBox(&quot;Some Prompt,vbOKCancel,&quot;Title&quot;)
If intReply = vbOK then
[Do something]
Else
[Dont do something]
End If

Would work out better for you

Collin [sig][/sig]
 
Hi, well this is what i understand is ur problem and please correct me if i am wrong. What i think is that you are using nested procedures something like

parent proc
child proc
child proc
- - -
some statements
- - -
reply = msgbox &quot;- - -&quot;
if reply = cancel
--try using goto labelname--
end if
end of child
end of child
labelname:
end of parent

(or)
The best way would be to use functions instead of procedures. The same functionality of procedures could be manipulated using functions with little effort and situations like urs could be handled effectively. Please try using them and meanwhile i will try for a perfect solution for this. You could help me by mailing the code to gantibabu@yahoo.com. I can reply with solution...all the best...vijay
[sig][/sig]
 
Hi, well this is what i understand is ur problem and please correct me if i am wrong. What i think is that you are using nested procedures something like
(This may not be the perfect solution at all as i myself hadnt tried before)

parent proc
child proc
child proc
- - -
some statements
- - -
reply = msgbox &quot;- - -&quot;
if reply = cancel
--try using goto labelname--
end if
end of child
end of child
labelname:
end of parent

(or)
The best way would be to use functions instead of procedures. The same functionality of procedures could be manipulated using functions with little effort and situations like urs could be handled effectively. Please try using them and meanwhile i will try for a perfect solution for this. You could help me by mailing the code to gantibabu@yahoo.com. I can reply with solution...all the best...vijay
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top