我的VBS上缺少什么声明?我无法找到它。它说41行的声明丢失了

时间:2018-02-15 05:22:27

标签: vbscript

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

3 个答案:

答案 0 :(得分:1)

尝试使用此工具在线缩进代码: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  

答案 1 :(得分:1)

End If而非EndIf和(在您的情况下)每个If需要一个End If。仔细缩进将有助于确定在哪里添加缺少的End Ifs。我怀疑“机械”压头会以你想要的方式格式化代码。

更新有关哪些代码导致错误的推测:

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"]'

必须先纠正编译错误,然后才能发生运行时错误。

答案 2 :(得分:1)

错误的原因是错误的条件;

ElseIf X - "feeling sad" Then

这是一个不完整的陈述,因为If语句条件需要评估为布尔TrueFalse结果。

尝试修复声明;

ElseIf X = "feeling sad" Then

很可能会给你一个

  

预期结束

由于reason pointed out

@Ekkehard导致

错误