在PHP中,如果我可以动态地将值与其他值列表进行比较:
$extension = "pdf";
if (!in_array($extension, array("docx", "xlsx", "txt")) {
// do stuff to the pdf
}
我怎么能把它移植到VBS?由于我无法弄清楚如何在php中动态创建数组,我尝试了if语句有3个条件:
extension = objFso.GetExtensionName(objFile.Path)
If Not (extension = "docx") OR (extension = "xlsx") OR (extension = "txt") Then
// do stuff to the pdf
End If
但这不起作用。条件被忽略了。两个问题:
If
条件或If
语句,动态创建一个数组来进行比较?非常感谢任何healp。
答案 0 :(得分:4)
我知道的最短路径是(布尔类型)
UBound(Filter(Array("docx", "xlsx", "txt"), "pdf")) > -1
返回False
和
UBound(Filter(Array("docx", "xlsx", "txt"), "txt")) > -1
返回True
你可以看到Array("doc", "xlsx", "txt")
已经 on> ,我已经用原来的问题用两个不同的字符串替换了extension
"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}}和{{1}})
<小时/> 所以,例如
{{1}}
答案 1 :(得分:3)
select case
:
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 ...
和
If Not (True Or True) ...