Vba 如何在VBS中创建具有多个条件(不是嵌套的多个语句)的If语句?
在PHP中,如果我可以动态地将一个值与其他值列表进行比较:Vba 如何在VBS中创建具有多个条件(不是嵌套的多个语句)的If语句?,vba,vbscript,Vba,Vbscript,在PHP中,如果我可以动态地将一个值与其他值列表进行比较: $extension = "pdf"; if (!in_array($extension, array("docx", "xlsx", "txt")) { // do stuff to the pdf } 如何将其移植到VBS?因为我不知道如何像在php中那样动态创建数组,所以我尝试了带有3个条件的and if语句: extension = objFso.GetExtensionName(objFile.Path) If Not
$extension = "pdf";
if (!in_array($extension, array("docx", "xlsx", "txt")) {
// do stuff to the pdf
}
如何将其移植到VBS?因为我不知道如何像在php中那样动态创建数组,所以我尝试了带有3个条件的and if语句:
extension = objFso.GetExtensionName(objFile.Path)
If Not (extension = "docx") OR (extension = "xlsx") OR (extension = "txt") Then
// do stuff to the pdf
End If
但这是行不通的。这些条件被忽略了。两个问题:
If
confirations或If
语句,而是动态创建一个数组进行比较非常感谢您的帮助。关于
选择案例如何
:
extension = lcase(objFso.GetExtensionName(objFile.Path))
select case extension
case "docx", "xlsx", "txt"
' is one of the above
' do something
case "zzz"
' its a .zzz
case else
' its something else
end select
在你当前的逻辑对比中
If Not True Or True ...
及
怎么样
选择案例
:
extension = lcase(objFso.GetExtensionName(objFile.Path))
select case extension
case "docx", "xlsx", "txt"
' is one of the above
' do something
case "zzz"
' its a .zzz
case else
' its something else
end select
在你当前的逻辑对比中
If Not True Or True ...
及
我知道的最短路径是(布尔型)
UBound(过滤器(数组(“docx”、“xlsx”、“txt”、“pdf”))>-1
返回False
及
UBound(过滤器(数组(“docx”、“xlsx”、“txt”)、“txt”)>-1
返回True
如您所见,数组(“doc”、“xlsx”、“txt”)
是动态创建的,我用两个不同的字符串(“pdf”
和“txt”
)替换了您在原始问题中使用的扩展名
比如说
extension = objFso.GetExtensionName(objFile.Path)
' extension is pdf
' the below produces false which in your logic means YES it's none of them
If (UBound(Filter(Array("docx", "xlsx", "txt"), extension)) > -1) Then
' you assume it's pdf
' do stuff to the pdf
End If
我知道的最短路径是(布尔型)
UBound(过滤器(数组(“docx”、“xlsx”、“txt”、“pdf”))>-1
返回False
及
UBound(过滤器(数组(“docx”、“xlsx”、“txt”)、“txt”)>-1
返回True
如您所见,数组(“doc”、“xlsx”、“txt”)
是动态创建的,我用两个不同的字符串(“pdf”
和“txt”
)替换了您在原始问题中使用的扩展名
比如说
extension = objFso.GetExtensionName(objFile.Path)
' extension is pdf
' the below produces false which in your logic means YES it's none of them
If (UBound(Filter(Array("docx", "xlsx", "txt"), extension)) > -1) Then
' you assume it's pdf
' do stuff to the pdf
End If
+1表示OP方法不起作用的实际解释+1表示OP方法不起作用的实际解释。