The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > Visual Basic


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: , , , ,

Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 09-30-2007, 09:53 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,109
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Icon9 What's Exit Sub for???

I'm looking at this code and wondering on what's "Exit Sub" is for..

Code:
  If (document.frmExample5a.txtAge.value < 0) Or _

     (document.frmExample5a.txtAge.value > 100) Then

    MsgBox "The age you entered is invalid."

    Exit Sub

  End If
Thanx pals~

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #2 (permalink)  
Old 10-01-2007, 02:23 AM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 615
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Well, if you had the code:
Code:
Sub madeup()
  If (document.frmExample5a.txtAge.value < 0) Or _

     (document.frmExample5a.txtAge.value > 100) Then

    MsgBox "The age you entered is invalid."

    Exit Sub

  End If

'
'
'Information for processing information without checking things are valid.
'
'

End Sub
This i have made up a sub called "madeup", if i wanted to process some information, i may wish to check a value, the if statement does this, when it checks, say i put 101 in the box it will the start showing me the message box, when you click ok in the message box it will continue processing the rest of the code, Exit Sub comes next which means it will Exit the sub rather than it continuing to process the information regardless. (this means where i have put a comment in my code for more statements it wont read there.

Hope that helps, if i have confused you let me know lol.
Lee.
Reply With Quote
The Following User Says Thank You to Lee For This Useful Post:
TeraTask (12-24-2007)
  #3 (permalink)  
Old 10-01-2007, 07:10 AM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 308
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
Also works for other loops - like if you wanted to be optimized you could do
Code:
For Each DR as DataRow in DataTable
  If DR.ProductID = 34
    MsgBox(DR.ProductName)
    Exit For
  End If
Next
This woulid exit out of the for and save all yoru cpu cycles

Last edited by TeraTask : 12-24-2007 at 06:45 PM. Reason: Added code tags
Reply With Quote
  #4 (permalink)  
Old 10-01-2007, 04:08 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,109
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
so it's kind of break; statement in the loop..? but this one is for a method..? Hey, Sub madeup() isn't a method isn't it? what is it then..? The way we call sub is different than calling a method..? or is it just the same thing? if it's the same, then what's the difference..? XD sorry, tons of question.. lol.. this scripting language is kind of weird to me at first

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #5 (permalink)  
Old 10-01-2007, 05:04 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 615
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
i used the sub made up as an example, to run the sub you may put "madeup()" inside a buttons sub and it will run the madeup sub...i would say it is like break yes... not sure what you mean for the rest.
Reply With Quote
  #6 (permalink)  
Old 12-24-2007, 03:47 PM
chrishirst chrishirst is offline
Jr. Programmer
Join Date: Jun 2007
Location: Blackpool UK
Posts: 87
iTrader: (0)
chrishirst will become famous soon enoughchrishirst will become famous soon enough
A "method" is simply a sub or function that is part of a class or an object.

in the same way that a property is simply a variable that is encapsulated in a class.

__________________
Chris
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to chrishirst For This Useful Post:
TeraTask (12-24-2007)
  #7 (permalink)  
Old 12-24-2007, 09:24 PM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 308
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
yes, exit [for, sub, etc...] is like break; - it exits out of the local loop
Reply With Quote
  #8 (permalink)  
Old 04-24-2008, 09:47 AM
dminder dminder is offline
Novice
Join Date: Apr 2008
Posts: 1
iTrader: (0)
dminder is on a distinguished road
Icon13 Don't Forget

This is my first time posting, happened across the boards when searching for something else. So Hello All!

Anyways, one thing that I find most useful especially when using Exit Sub is that if you have it within a Try...Catch...Finally statement, whatever is in the Finally part of the block will happen regardless of anything else. So, if you wanted to dispose of objects, disconnect from data sources, reset buttons, etc. before you exit the sub/function then you can put this all in the finally block and make sure it is done. However with exit do, while, for - unless the try...catch..finally block is encapsulated within them, the finally will not be triggered right away, it will complete whatever code is beyond them then once it either finishes with the sub/function or hits the exit sub/function command.

This can also be a deficit for the exact same reason, so be sure of what you put in there!!

Good Luck and Happy Coding!!

D

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by dminder : 04-24-2008 at 09:50 AM.
Reply With Quote
  #9 (permalink)  
Old 04-24-2008, 08:56 PM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 308
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
Just to keep you in th eloop thats for .NET+ - classic ASP/VBScript doesn't have a try catch
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 05:05 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50