Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

(sorta) OT: VBS Language Question


Recommended Posts

Just throwing this out there...

 

Does anybody know of a VBS equivalent of the 'continue' keyword in C/C++/Java/etc to go to the next iteration of a loop? VB has never had it but I could fake it by throwing in a "zip nada nothing" block before the end of the loop like this:

 

code:

Do While (bSomeCondition <> False)

' do some stuff

 

' do some more stuff

 

' this might be by itself or nested really deep so that Exit won't work

If (bFreakyCase = True) Then GoTo ContinueLoop

 

' do even more kewl stuff

 

' mimic the continue keyword of C/C++/Java/etc

ContinueLoop:

Loop

But for some reason, VBS hates my GoTo. I know that GoTo's are bad programming practice and all, but that was pretty much the only time I ever needed them (thanks VB wink.gif ). Is the GoTo statement depreciated in VBS now...like really depreciated?

Link to comment
Share on other sites

pip, I want to continue iterating and not bail on the loop (which is what wend's and until's will do).

 

Matt, I get a "statement expected" type of error. This happens external to Mastercam, too. Load up this code in notepad and save it as whatever. Then run it.

 

code:

Dim nCount

 

For nCount = 0 To 20

MsgBox nCount

 

' 13....oooh, scary...let's skip it

If (nCount MOD 13 = 0) Then GoTo ContinueLoop

 

ContinueLoop:

Next

Yes, I know that something like this would do the trick:

 

code:

For nCount = 0 To 20

' 13....oooh, scary...let's skip it

If (nCount MOD 13 <> 0) Then MsgBox nCount

Next

But I just wanted to illustrate it. Put my first snippet into, say, VB6 and you'll see that it works fine.

 

Mastercam's VBS interpreter produces a similar error. That's why I'm thinking that Microsoft depreciated GoTo in VBS to the point that it's un-usable.

Link to comment
Share on other sites

None that I know of but then vbscript isn't my language of choice. You'll probably have to restructure your code or use some kind of fake do..loop tied in with a continue variable. frown.gif

 

pseudo code

code:

  

do loop1

continue = true

(fake) loop2

 

.....

if something break loop2

 

do loop 3 while continue

....

if err, continue = false; break loop3

loop3

 

do loop4 while continue

....

if err, continue = false; break loop4

loop4

 

break loop 2

loop2

 

loop1

Bryan smile.gif

Link to comment
Share on other sites

quote:

None that I know of but then vbscript isn't my language of choice. You'll probably have to restructure your code or use some kind of fake do..loop tied in with a continue variable.


Bryan, your psuedocode snippet is completely and totally hideous, and I mean that in the nicest possible way wink.gif

Link to comment
Share on other sites

There is no 'break' statement in VBS. Either way, a break would exit the loop entirely. A 'continue' statement just skips the current loop iteration and moves on to the next one. If you know some C/C++, check this. Even if you don't, check this wink.gif

 

code:

for (int i = 0; i <= 20; i++)

{

if (i % 13 == 0) // 13 is too scary to print

continue;

 

cout << i << " ";

}

This is a very basic example. This loop will attempt to print the integers running from 0 to 20. What happens here is that when the loop comes across a value of i (between 0 and 20) that is evenly divided by 13 it executes the 'continue' statement. 'continue' statements essentially skip any following statements and move to the next iteration of the loop. So when i = 13, it evenly divides into 13, and the loop skips the call to cout and goes to i = 14. I know that this example is very easy bypass printing 13 with a simple 'if' statement, but 'continue' is very handy when you have plenty of nested logic statements and want to "skip" an iteration. So the following is the result:

 

0 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20

 

Conversely, if I used 'break' instead of 'continue', the loop would end and 14 to 20 wouldn't be displayed. The result would look like this:

 

0 1 2 3 4 5 6 7 8 9 10 11 12

 

I'm bummed that I can't fake the 'continue' keyword in VBS like I could in VB, but I'll get over it (already have, actually, after some refactoring). There's always plenty of ways to accomplish something wink.gif

Link to comment
Share on other sites

quote:

almost seems like you need to evaluate everything

by putting a

If

end if

 

Please let me know how you handle this problem because I want to learn this too. Thanks


That's pretty much what it came down to. A little bit of a change of flow and subsequent refactoring and I'm back to the task at hand. Not as clean as I imagined but it's not that bad and I would probably have to go back to the drawing board if I were deep inside of logic statments but I was only two levels in, which isn't bad. So I'm not complaining wink.gif Good on Microsoft for axing 'goto' but I would like to see a 'continue' at some point, for those times when I'm in a logic swamp wink.gif The 'continue' quandry even forced me to take a look at a class that I wrote and I managed to trim some members that I thought I needed but realized I didn't wink.gif Two birds with one stone smile.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...