Hello everyone,

I am after some help from more experienced programmers. I have used other
scripts as examples from here and ones i have found on google.

The script I have provided below is quite basic, but at this stage I am having
some issues with my looping code.

When I ask the user for a Blue or Red team name with an Input box they are
presented with an OK and a cancel box. A cancel exits the script, however
how do I loop a cancel to then loop all the way to the top of the script
so they now seeing the Msgbox asking again if they are part of blue or red
team with a Yes or No response ? I have looked at loops but if there is something
else I can use please let me know.

I hope someone can provide me some assistance.

Thanking you in advance.




***************************************************************************
Dim team, BTeam, RTeam, pick, choice

pick = Msgbox("Are you part of Blue Team, Otherwise your on Red Team",vbYesNoCancel)

If pick = vbYes Then
team = "Blue"
ElseIf pick = vbNo Then
team = "Red"
Else pick = vbCancel
Wscript.Quit
End If

select case Team
case "Blue"
Do Until choice = vbYes
BTeam = InputBox ("What is your Blue Team name ?")
msgbox "Blue Team Name is " & BTeam
Wscript.Quit
Loop

case "Red"
Do Until choice = vbYes
RTeam = InputBox ("What is your Red Team name ?")
msgbox "Red Team Name is " & RTeam
Wscript.Quit
Loop
end select

Re: help with loops by Pegasus

Pegasus
Fri Mar 14 05:39:19 CDT 2008


"Steve Jacobs" <sjacobs21@hotmail.com> wrote in message
news:7d7bba6b1cb38ca542aff1e9a32@msnews.microsoft.com...
> Hello everyone,
>
> I am after some help from more experienced programmers. I have used other
> scripts as examples from here and ones i have found on google.
>
> The script I have provided below is quite basic, but at this stage I am
> having some issues with my looping code.
>
> When I ask the user for a Blue or Red team name with an Input box they are
> presented with an OK and a cancel box. A cancel exits the script, however
> how do I loop a cancel to then loop all the way to the top of the script
> so they now seeing the Msgbox asking again if they are part of blue or red
> team with a Yes or No response ? I have looked at loops but if there is
> something else I can use please let me know.
>
> I hope someone can provide me some assistance.
>
> Thanking you in advance.
>
>
>
>
> ***************************************************************************
> Dim team, BTeam, RTeam, pick, choice
>
> pick = Msgbox("Are you part of Blue Team, Otherwise your on Red
> Team",vbYesNoCancel)
>
> If pick = vbYes Then
> team = "Blue"
> ElseIf pick = vbNo Then
> team = "Red"
> Else pick = vbCancel
> Wscript.Quit
> End If
>
> select case Team
> case "Blue"
> Do Until choice = vbYes
> BTeam = InputBox ("What is your Blue Team name ?")
> msgbox "Blue Team Name is " & BTeam
> Wscript.Quit
> Loop
>
> case "Red"
> Do Until choice = vbYes
> RTeam = InputBox ("What is your Red Team name ?")
> msgbox "Red Team Name is " & RTeam
> Wscript.Quit
> Loop
> end select
>

I'm not sure if I completely understand the desired flow of
your program but the following code should get you started.
BTW, your programs become much more readable if you
indent the code, either with spaces or with tabs.

Do
cancel = False
pick = MsgBox("Are you part of Blue Team, Otherwise your on Red
Team",vbYesNoCancel)

If pick = vbYes Then
team = "Blue"
ElseIf pick = vbNo Then
team = "Red"
Else Exit Do
End If

Select Case team
Case "Blue"
Do Until choice = vbYes
BTeam = InputBox ("What is your Blue Team name ?")
If BTeam = Empty Then
cancel = True
Else
MsgBox "Blue Team Name is " & BTeam
End If
Exit Do
Loop

Case "Red"
Do Until choice = vbYes
RTeam = InputBox ("What is your Red Team name ?")
If RTeam = Empty Then
cancel = True
Else
MsgBox("Red Team Name is " & RTeam)
End If
Exit Do
Loop
End Select
if cancel then Exit Do