我的VBS上缺少什么声明?我找不到它。它说41行的声明丢失了
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我的VBS上缺少什么声明?我找不到它。它说41行的声明丢失了相关的知识,希望对你有一定的参考价值。
X=inputbox("Hello there (Hello/Hi/What's up?)")
If X = "Hello" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
ElseIf X = "hello" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
ElseIf X = "Hi" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
ElseIf X = "hi" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
End If
If X = "Feeling Awesome" Then
X=inputbox("Great! Can we play Question and Answer with Yes and No?
(Yes/No)?")
ElseIf X = "Feeling Normal" Then
X=inputbox("Okay! Can we play Question and Answer with Yes and No?
(Yes/No)?")
ElseIf X = "Feeling Sad" Then
X=inputbox("Oh no! Maybe playing a game will make you happy. Can we play
Question and Answer with Yes and No? (Yes/No)?")
ElseIf X = "feeling awesome" Then
X=inputbox("Great! Can we play Question and Answer with Yes and No?
(Yes/No)?")
ElseIf X = "feeling normal" Then
X=inputbox("Okay! Can we play Question and Answer with Yes and No?
(Yes/No)?")
ElseIf X - "feeling sad" Then
X=inputbox("Oh no! Maybe playing a game will make you happy. Can we play
Question and Answer with Yes and No? (Yes/No)?")
End If
If X = "Yes" Then
B=Msgbox("Do you have secrets?",vbYesNo+vbQuestion)
If B = vbYes Then
B=MsgBox("Are they super secrets that only you know, Or they also know your best
friend(s)?",vbYesNo+vbQuestion)
ElseIf B = vbNo Then
B=MsgBox("Great that means you are a nice guy.",vbInformation)
B = MsgBox("Do you have a Sister/Brother?",vbYesNo+vbQuestion)
If B = vbYes Then
A = inputbox("What's his/her name?")
B = msgbox("From now my favorite name is" + A)
ElseIf B = vbNo Then
B = MsgBox ("Okay then!")
B = MsgBox("Is Ice Cream better than Chocolate?",vbYesNo+vbQuestion)
If B = vbYes Then
B = MsgBox("But for me chocolates are much better")
ElseIf B = vbNo Then
B = MsgBox("Cool I like for me chocolates are better too.")
EndIf
ElseIf Y = vbNo Then
msgBox("Bye!")
EndIf
答案
错误的原因是错误的条件;
ElseIf X - "feeling sad" Then
这是一个不完整的陈述,因为If
语句条件需要求值为布尔值(True
或False
)。
尝试修复声明;
ElseIf X = "feeling sad" Then
很可能会给你一个
预期结束
由于reason pointed out的@Ekkehard导致的错误
另一答案
尝试使用此工具在线缩进代码:http://www.vbindent.com/
为了更好地阅读和调试您的问题:
X=inputbox("Hello there (Hello/Hi/What's up?)")
If X = "Hello" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
ElseIf X = "hello" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
ElseIf X = "Hi" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
ElseIf X = "hi" Then
X=inputbox("What's up?? (Feeling Awesome/Feeling Normal/Feeling Sad)")
End If
If X = "Feeling Awesome" Then
X=inputbox("Great! Can we play Question and Answer with Yes and No? (Yes/No)?")
ElseIf X = "Feeling Normal" Then
X=inputbox("Okay! Can we play Question and Answer with Yes and No? (Yes/No)?")
ElseIf X = "Feeling Sad" Then
X=inputbox("Oh no! Maybe playing a game will make you happy. Can we play Question and Answer with Yes and No? (Yes/No)?")
ElseIf X = "feeling awesome" Then
X=inputbox("Great! Can we play Question and Answer with Yes and No? (Yes/No)?")
ElseIf X = "feeling normal" Then
X=inputbox("Okay! Can we play Question and Answer with Yes and No? (Yes/No)?")
ElseIf X - "feeling sad" Then
X=inputbox("Oh no! Maybe playing a game will make you happy. Can we play Question and Answer with Yes and No? (Yes/No)?")
End If
If X = "Yes" Then
B=Msgbox("Do you have secrets?",vbYesNo+vbQuestion)
If B = vbYes Then
B=MsgBox("Are they super secrets that only you know, Or they also know your best friend(s)?",vbYesNo+vbQuestion)
ElseIf B = vbNo Then
B=MsgBox("Great that means you are a nice guy.",vbInformation)
B = MsgBox("Do you have a Sister/Brother?",vbYesNo+vbQuestion)
End If
If B = vbYes Then
A = inputbox("What's his/her name?")
B = msgbox("From now my favorite name is" + A)
ElseIf B = vbNo Then
B = MsgBox ("Okay then!")
B = MsgBox("Is Ice Cream better than Chocolate?",vbYesNo+vbQuestion)
End If
If B = vbYes Then
B = MsgBox("But for me chocolates are much better")
ElseIf B = vbNo Then
B = MsgBox("Cool I like for me chocolates are better too.")
ElseIf Y = vbNo Then
msgBox("Bye!")
End If
End If
另一答案
这是End If
而不是EndIf
和(在你的情况下)每个If
需要一个End If
。仔细缩进将有助于确定在哪里添加缺少的End Ifs
。我怀疑“机械”压头会以你想要的方式格式化代码。
更新wrt关于什么代码导致什么错误的猜测:
48800410-1.vbs
If X Then
WScript.Echo "EndIf throws 'Expected statement' error"
EndIf
output:
cscript 48800410-1.vbs
...48800410-1.vbs(3, 1) Microsoft VBScript compilation error: Expected statement
48800410-2.vbs
If False Then
WScript.Echo "Trying to substract string throws a type mismatch error"
ElseIf X - "feeling sad" Then
WScript.Echo "xxx"
End If
cscript 48800410-2.vbs
...48800410-2.vbs(3, 1) Microsoft VBScript runtime error: Type mismatch: '[string: "feeling sad"]'
必须先纠正编译错误,然后才能发生运行时错误。
以上是关于我的VBS上缺少什么声明?我找不到它。它说41行的声明丢失了的主要内容,如果未能解决你的问题,请参考以下文章