Goto function

  • Thread starter Thread starter mark
  • Start date Start date
M

mark

can a goto statement be used to skip some lines in the
code. i have an if statement here like this. thanks for
all your help.

If Lrows > 500 Then
YesNo = MsgBox("....", vbYesNo +
vbQuestion , "Caution")

Select Case YesNo
Case vbYes
'MsgBox "Yes"
GoTo Line45
Case vbNo
MsgBox "No"
Exit Sub
End Select 'Line 45
Else
End If
 
Hi
in your example there's no need for this. You should avoid using Goto
statements (not good coding practice)
 
hi

yes i am aware of that. but i dont know any other way. my
main code appears after the end if statement. i want the
code to run when there are less than 500 rows and if there
are more then i want to ask the user whether he/she wants
to continue? any other way to achieve this?thanks
 
Wouldn't this do the trick?

Code
-------------------
If Lrows > 500 Then
YesNo = MsgBox("....", vbYesNo + vbQuestion , "Caution")
If YesNo = vbNo Then Exit Sub
End If

'Main Code Goes Her
 
Hi
yes but your code would do this without the 'goto statement'. If the
user choose 'no' you are exiting this procedure. If you choose 'Yes'
the code continues
 
hi
sorry, i think i am not making myself clear here. yes wht
you said is right. but what if there are less than 500
rows. the user will not get any message then i want to run
the same code as when the user press 'Yes'. Without the
goto (if it works, wht i have here doesn't works!!) I will
have to copy the same code after 'Case vbYes'. i hope you
got what i am trying to say here.
 
Hi
try something like the following:

sub foo()
Dim Lrows
Dim ret_val
'.. your code to determine LRows

If Lrows > 500 Then
ret_val = MsgBox("....", vbYesNo + vbQuestion , "Caution")
If ret_val = vbNo Then
msgbox "Stop execution"
Exit Sub
End If
end if
'put your main code here
end sub
 
can a goto statement be used to skip some lines in the
code. i have an if statement here like this. thanks for
all your help.

If Lrows > 500 Then
YesNo = MsgBox("....", vbYesNo +
vbQuestion , "Caution")

Select Case YesNo
Case vbYes
'MsgBox "Yes"
GoTo Line45
Case vbNo
MsgBox "No"
Exit Sub
Line45 End Select
Else
End If

should do it
 
Hi
though this would work it's (IMHO) totally unnecessary and not a good
programming style :-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Loop back to Case vbNo '#2 7
Print Macro 5
Master reset code bug - stumped again 1
Case Statment in Err trapping 3
Check Box macro 1
messagebox macro 1
Newbie: MsgBox, etc 3
Rounding Ranges 1

Back
Top