VBS: Goto

Hallo,

in einem VBS Script habe ich eine MsgBox und man soll, wenn man auf Nein klickt, wieder zurück an den Anfang kommen. Wenn ich das Script starte kommt die Fehlermeldung Zeile8: Anweisung erwartet. Das ist die Zeile, inder der GOTO Befehl steht

Das script sieht dann zum Beispiel so aus:


FRAGE:

antwort=MsgBox („Hallo, gehts dir gut?“, vbYesNo + vbQuestion, „wie gehts“)
If antwort = vbYes then
msgbox („Das ist gut.“),(„ok“)
end if
goto end

If antwort = vbNo then
msgbox („Schade.“),(„aha“)
goto FARGE
end if

end


Kennt VBs das GOTO nicht, oder gibt es da noch einen anderen Befehl.
Ich habe schon mal von Do…Loop gehört.

Ich bin um jede Antwort dankbar.

Pascal

Hallo,

in einem VBS Script habe ich eine MsgBox und man soll, wenn
man auf Nein klickt, wieder zurück an den Anfang kommen. Wenn
ich das Script starte kommt die Fehlermeldung Zeile8:
Anweisung erwartet
. Das ist die Zeile, inder der
GOTO Befehl steht

Das script sieht dann zum Beispiel so aus:


FRAGE:

antwort=MsgBox („Hallo, gehts dir gut?“, vbYesNo + vbQuestion,
„wie gehts“)
If antwort = vbYes then
msgbox („Das ist gut.“),(„ok“)
end if
goto end

End ist eine Anweisung, Goto End wird nicht funktionieren, da fehlt die Sprungmarke.

If antwort = vbNo then
msgbox („Schade.“),(„aha“)
goto FARGE

Tippfehler, Buchstabendreher, Die Sprungmarke heißt Frage, der Sprung soll nach ‚Farge‘ erfolgen.

Aber hier her kommt das Programm nie, wenn das erste Goto funktioniert.

end if

end


Kennt VBs das GOTO nicht, oder gibt es da noch einen anderen
Befehl.
Ich habe schon mal von Do…Loop gehört.

Ja, richtig. :smile: Wenn es möglich ist, soll man Goto vermeiden, einfach, weil der Code dann übersichtlicher wird. :smile:

Für zwei Alternativen zwei ‚If‘ ist auch etwas unübersichtlich.

Wie gefällt dir das?

Option explicit

Dim Antwort 

Do
 Antwort=MsgBox ("Hallo, gehts dir gut?", vbYesNo + vbQuestion, "wie gehts")
 If Antwort = VbYes Then
 MsgBox ("Das ist gut."),,("ok")
 Else
 MsgBox ("Schade."),,("aha")
 End If
Loop While Antwort = VbNo

Vielen Dank!
Hat super funktioniert!!

Pascal

Wie gefällt dir das?

Option explicit

Dim Antwort

Do
Antwort=MsgBox („Hallo, gehts dir gut?“, vbYesNo +
vbQuestion, „wie gehts“)
If Antwort = VbYes Then
MsgBox („Das ist gut.“),(„ok“)
Else
MsgBox („Schade.“),(„aha“)
End If
Loop While Antwort = VbNo