Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 29th, 2005, 10:33 AM
Authorized User
 
Join Date: Jul 2005
Location: New York, New York, .
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Syntax help: vbscript equivalent of break

Java version
for(int i=0; i<10; i++) {

  if (condition)
    continue; // that gets to next iteration
  doWhatever();
}
How about the vbscript? Any keyword for that?

For i = 0 to 10
  if (condition) then
     ????? ' what to put???
  End if
  doWhatever

Next

Reply With Quote
  #2 (permalink)  
Old July 29th, 2005, 10:42 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am not sure what you want to do with this code.

If you want to check a condition (for example, i = 1) and do something if the condition is met, then it is:

For i = 0 To 10
   If i = 1 Then
      'doWhatever
   End If
i = i + 1
Next

Is this what you want? For goodness sakes, don't for get to iterate your counter.


mmcdonal
Reply With Quote
  #3 (permalink)  
Old July 10th, 2006, 03:24 PM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You dont want to iterate the i unless you plan to step by 2 and not 1

Reply With Quote
  #4 (permalink)  
Old July 10th, 2006, 04:05 PM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

to exit a for loop like what jScript dose w/ break
it would be Exit For
for a do loop: Exit Do


Reply With Quote
  #5 (permalink)  
Old April 22nd, 2009, 05:34 AM
Authorized User
Points: 126, Level: 2
Points: 126, Level: 2 Points: 126, Level: 2 Points: 126, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Post

"For...Next" Loop looks like this.

Code:
 
Dim Counter
 
For Counter = 1 to 10
     MsgBox Counter
Next     'Counter
To [BREAK] out of the "For...Next" Loop, you will want to insert a Code Sequence. Most likely with some sort of User Input Sequence such as with the InputBox Statement.

Code:
 
Dim Counter
Dim strCounter
 
For Counter = 1 to 10
     MsgBox Counter
     strCounter = InputBox("?Do you want to Continue?")
          If strCounter = "" Then
               Counter = 11
          End If
Next     'Counter
A better method would be to use a MsgBox "?Do you want to Continue?" with the "VbYesNo" Constant; as well as, the "VbYes" and "VbNo" Constants in place of the InputBox Sequence; but, I'm not familiar enough with VBScript to write such a sequence at this time.

I am new to VBScript; thus, I only know how to use InputBox for User Inputs in VBScript Codes at this time.

With GW-BASIC, all you needed was a GOTO Statement to [BREAK] out of the "For...Next" Loops because all the Command Lines were numbered.

With GW-BASIC, you could also use the INKEY$ Statement to [BREAK] out of the "For...Next" Loop.

I haven't tested out my Input Sequence; thus, if you get a "Subscript Out Of Range" Error, you should change the Counter = 11 Command Line to Counter = 10.

Last edited by Tandy1000SL GW-BASIC; April 22nd, 2009 at 05:43 AM.
Reply With Quote
  #6 (permalink)  
Old April 22nd, 2009, 06:01 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Don't answer posts that are FOUR YEARS OLD. All you do is clutter up the forums.

Also, your answer is wrong. Or at least not as simple and not as correct as the prior post by spark86
Reply With Quote
  #7 (permalink)  
Old April 30th, 2009, 08:57 PM
Authorized User
Points: 126, Level: 2
Points: 126, Level: 2 Points: 126, Level: 2 Points: 126, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ONE
I am new to these forums.

It is apparent to me that I have to edit my Forum Settings so that the Newest Topic Threads are listed first.

TWO
What the Original Poster wanted was to be able to Press a [KEY] to Break a "For...Next" Loop.

"Spark86" suggestion isn't that; as far as I know. I am new to VBScript myself; but, I am very familiar with GW-BASIC, which has the Press a [KEY] To Break out of a "For...Next" Loop feature.

The reason I suggested an InputBox is because the Computer User can Press [ENTER] to Break Out of a "For...Next" Loop. Pressing anything else, will result in the "For...Next" Loop to continue.

Last edited by Tandy1000SL GW-BASIC; April 30th, 2009 at 09:01 PM.
Reply With Quote
  #8 (permalink)  
Old May 1st, 2009, 05:04 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
What the Original Poster wanted was to be able to Press a [KEY] to Break a "For...Next" Loop.
I'm sorry, but you are showing your ignorance of other programming languages when you say that.

I understand you think he was talking about pressing some kind of "break" key, but no, he wasn't.

In C and C++ and Java and JavaScript and C# and PHP and various other languages, the keyword break is used to prematurely exit from a loop (as it turns out, from any kind of loop).

Example in javascript:
Code:
for ( var i = 1; i <= 100; ++i )
{
    document.write("This is iteration " + i + "<br />" );
    if ( i > 17 ) break;
}
That loop will *NOT* execute 100 times, as you might think from reading the for line.

Instead, it will execute 18 times, because on the 18th iteration the variable i is indeed greater than 17 and the break keyword says "exit from the enclosing loop."

And *THAT* is what the original poster in this thread meant when he asked if there is any VBScript equivalent of the JAVA keyword break. (And Java also has a continue keyword which he was asking about, at the same time.)

And, yes, the EXIT FOR and EXIT DO keywords are the closest equivalents, in VBScript and in VB6 and in VB.NET, of the Java break keyword.
Reply With Quote
  #9 (permalink)  
Old May 1st, 2009, 08:06 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Don't answer posts that are FOUR YEARS OLD. All you do is clutter up the forums.
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote
  #10 (permalink)  
Old May 1st, 2009, 03:42 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Well, that's what I first said to Tandy. But, really, this hopefully *IS* serving to make him rethink what he thought he knew about VBScript. So in that sense, it's up-to-date. Clearly he needs help learning the fundamentals of the language.
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the Equivalent Syntax in VB.NET r_taduri VB.NET 2002/2003 Basics 1 June 2nd, 2006 12:49 PM
Unable to Break at Break point Girishbk VB.NET 2002/2003 Basics 0 January 18th, 2005 07:29 AM
VBScript error 0x800A03EA Syntax error edbkegan3 Classic ASP Databases 2 March 29th, 2004 12:57 PM
javascript equivalent lcsgeek Classic ASP Basics 0 September 22nd, 2003 07:17 AM
ASP Equivalent U.N.C.L.E. Classic ASP Basics 3 July 8th, 2003 03:05 AM



All times are GMT -4. The time now is 02:14 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.