|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

July 29th, 2005, 11:33 AM
|
|
Authorized User
|
|
Join Date: Jul 2005
Location: New York, New York, .
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

July 29th, 2005, 11:42 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

July 10th, 2006, 04:24 PM
|
|
Registered User
|
|
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You dont want to iterate the i unless you plan to step by 2 and not 1
|

July 10th, 2006, 05:05 PM
|
|
Registered User
|
|
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
to exit a for loop like what jScript dose w/ break
it would be Exit For
for a do loop: Exit Do
|

April 22nd, 2009, 06:34 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
"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 06:43 AM.
|

April 22nd, 2009, 07:01 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 Posts
|
|
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
|

April 30th, 2009, 09:57 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 10:01 PM.
|

May 1st, 2009, 06:04 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 Posts
|
|
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.
|

May 1st, 2009, 09:06 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

May 1st, 2009, 04:42 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |