Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VBS - GOTO Do Loop


  • Please log in to reply

#1
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
Hi again.

I tried to do a new way of looping, that even after an exit, the loop can be entered again, without having to copy the whole do...loop area.

I've been googling on this, but nothing really worked out.
People tell me it's not possible, but that's hard to believe.

Is it possible to enter a loop after exiting it?
  • 0

Advertisements


#2
Granz00

Granz00

    Member

  • Member
  • PipPipPip
  • 226 posts
My first comment would be to Loop to a point where the loop starts right before your do loop that you want to reenter. If that doesn't work for your situation, then do a Goto. However, Goto is a frowned upon practice, since it provides more then one entrance to a loop on a flowchart.

When you say VBS, do you mean VBScript, or are they two different languages?
  • 0

#3
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts
VBS is short for Visual Basic Scripting.

What the [bleep] do you mean with that comment... o.O I asked if it's possible...
Your just suggesting another one, but is it really possible with a goto... and if so, how.
  • 0

#4
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Make a label in front of the loop and place the Goto after exiting the loop. :whistling:

But that just messes things up, either use a second do...loop wrapped around the first one or place the do...loop in a subprocedure and call it again somewhere else.
  • 0

#5
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts
That's a good idea.
I'll use that when I do bigger projects, but I just needed a goto do-loop fast, for a few simple lines of script.

Thnx for the tip.

With "label" do you mean something like this?


'Start

AB Do

Set A = CreateObject("wscript.Shell")

Boot = InputBox("Enter program name or variable:", "Name Entry")

If IsEmpty(Boot) Then
Wscript.quit(1)
ElseIf Len(Boot) = 0 Then
Wscript.quit(1)
Else
A.Run ""&Boot
End If

Loop

GOTO AB
'End

Ah and Ganz, your post is appreciated, don't get me wrong, I was just a little bit angry at myself. I hope your feelings aren't hurt.

Edited by IO-error, 05 December 2006 - 02:22 AM.

  • 0

#6
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
AB: 

Do

Set A = CreateObject("wscript.Shell")...

Labels get recognised as labels if you put a colon after the name :whistling:. THat should work. BTW, how did you get the syntax colouring?

Cya

Edited by Hai Mac, 05 December 2006 - 08:10 AM.

  • 0

#7
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts
Hehe, how I got the syntax colouring? That's easy man :whistling:. It's about logics.

Anyway, thnx for the help, in return, the least I can do in return is explain that colour coding.

When you write a new post, you can colour your text, right? You know that, well, that's what I did, I selected the parts that needed colourcoding and gave it the correct colour. Notice that the brackets, ( ) and comma, are Bold.

It makes it easier for you to read and understand, so that's why I do that when I show my codes. It's so I can get better orientated help about the subject. And maybe give some inspiration to the Forum board, to do automatic Colourcoding for the most frequent languages on these boards.

Ok, I got the Label, but how do I call the label?
I try this, but it's not working.

'Start

AB:

Do

Set A = CreateObject("wscript.Shell")

Boot = InputBox("Enter program name or variable:", "Name Entry")

If IsEmpty(Boot) Then
Exit Do
ElseIf Len(Boot) = 0 Then
Exit Do
Else
do while InStr (1,Boot, ""&Chr(32), 1) > 1
Boot = replace(Boot, " ", "")
'Note that the inStr example has four parameters, which control the start point, string to search, value to compare and whether it should be case sensitive
loop
A.Run ""&Boot
Exit Do
End If

Loop

GOTO
&AB
'I also tried these:
GOTO AB:
GOTO AB
'End

Edited by IO-error, 06 December 2006 - 04:17 AM.

  • 0

#8
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Aah, thanks then. Doesn't it take a long time, doing that manually? And did the fix work anyways? :whistling:
  • 0

#9
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts

Ok, I got the Label, but how do I call the label?
I try this, but it's not working.

'Start

AB:

Do

Set A = CreateObject("wscript.Shell")

Boot = InputBox("Enter program name or variable:", "Name Entry")

If IsEmpty(Boot) Then
Exit Do
ElseIf Len(Boot) = 0 Then
Exit Do
Else
do while InStr (1,Boot, ""&Chr(32), 1) > 1
Boot = replace(Boot, " ", "")
'Note that the inStr example has four parameters, which control the start point, string to search, value to compare and whether it should be case sensitive
loop
A.Run ""&Boot
Exit Do
End If

Loop

GOTO
&AB
'I also tried these:
GOTO AB:
GOTO AB
'End



Does that answer your question?
  • 0

#10
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Sorry, misread your post :whistling:

GoTo AB should work. If not, may be VBS does not allow GoTo. You can also try If 1=1 GoTo AB.

If that does not work either, put On Error GoTo AB at the start of the code (even before the label AB:) and then make some error at the end, like divide by zero.

Edited by Hai Mac, 07 December 2006 - 08:18 AM.

  • 0

Advertisements


#11
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts
Lol, funny tricks, thanks for the inspiration, you just solved a problem of a very old script of mine. (About that dividing by zero)

K, I'll see if it'll help my current problem too. Thnx.

***EDIT***
Sorry, didn't work, I'll drop the project, redo the code to something else, maybe something like this:


Set A = CreateObject("wscript.Shell")

Boot = InputBox("Enter program name or variable:", "Name Entry")

If IsEmpty(Boot) Then
Wscript.quit(1)
ElseIf Len(Boot) = 0 Then
A.Run "Restart_Taskbooter.vbs"
Wscript.quit(1)
Else
A.Run ""&Boot
A.Run ("Restart_Taskbooter.vbs")
End If

Edited by IO-error, 07 December 2006 - 09:07 AM.

  • 0

#12
dsm

dsm

    Member

  • Member
  • PipPip
  • 98 posts
Hai Mac

I don't think goto is valid syntax within VBS
I tried many variations without success

The following link claims to list the valid keywords available in VBS
http://www.htmlgoodi...cle.php/3458631


dsm
  • 0

#13
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Shoot, I give up then. All my cards are on the table...
  • 0

#14
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts
Control Flow
DoEvents Yields execution to Windows
GoSub...Return Branches to a label in a procedure
GoTo Goes to a label in a procedure
On Error GoTo Goes to a label on an error
On...GoSub Branches to a label on an index
On...GoTo Goes to a label on an index


That's on that website. So it SHOULD be possible...
I haven't seen any official example of a created and working label, so I'm afraid that a label has to be defined different than
:AB
or
AB:

Then I still don't know how to do it.... :whistling:
  • 0

#15
Ctrl_Alt_Del

Ctrl_Alt_Del

    Member

  • Member
  • PipPip
  • 74 posts
I'm not real sure exactly what you are trying to do but if you put a loop in a procedure or in a function you can then call that procedure or function from inside the loop. It's called recursion and you have to be be very careful or you'll end up using up all of your resources and infinitely looping.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP