值没有被赋值给vbscript中的变量

时间:2016-12-19 05:25:56

标签: vbscript

if ( IsPEnabled = "TRUE" AND IsPChecked = 1) Then
    canRemove = "true"
elseif (IsPEnabled = "FALSE" AND IsPChecked = 0) Then
    canRemove = "true"
else 
    canRemove = "false"
End If

我似乎无法在上面的代码中找到任何错误,但每当canRemove始终保持为false,即使if和else都满足条件。注意:声明所有变量并具有正确的值。

2 个答案:

答案 0 :(得分:1)

为了进一步扩展这一点,在检查字符串以强制它们为大写或小写时这是一个很好的做法,以便您可以确定它们是否匹配正确。

显然,如果您需要检查字符串是否与特定区分大小写的格式匹配,那么这不是一种合适的方法!

您可以使用:

If (UCase(IsPEnabled) = "TRUE" AND IsPChecked = 1) Then
    canRemove = "true"
ElseIf (UCase(IsPEnabled) = "FALSE" AND IsPChecked = 0) Then
    canRemove = "true"
Else 
    canRemove = "false"
End If

这样,您可以强制对IsPEnabled变量进行更改,仅用于比较,而不是实际更改其值。如果您想使用小写,请使用以下代码:

If (LCase(IsPEnabled) = "true" AND IsPChecked = 1) Then
    canRemove = "true"
ElseIf (LCase(IsPEnabled) = "false" AND IsPChecked = 0) Then
    canRemove = "true"
Else 
    canRemove = "false"
End If

通常,最好不要将strings用于TrueFalse值。如果您将这些设为Boolean类型,则根本不需要字符串比较:

If (IsPEnabled AND IsPChecked = 1) Then
    canRemove = True
ElseIf (Not IsPEnabled AND IsPChecked = 0) Then
    canRemove = True
Else 
    canRemove = False
End If

答案 1 :(得分:0)

我在控制台中尝试使用大写与小写

这很有用

if ( IsPEnabled = "true" AND IsPChecked = 1) Then
    canRemove = "true"
elseif (IsPEnabled = "false" AND IsPChecked = 0) Then
    canRemove = "true"
else 
    canRemove = "false"
End If