2014-01-14 3 views
1

, 나는 즉시 다른 값 목록에 대한 값을 비교할 수있는 경우 :VBS에서 여러 조건이 중첩 된 If 문을 만들려면 어떻게해야합니까? PHP에서

$extension = "pdf"; 
if (!in_array($extension, array("docx", "xlsx", "txt")) { 
    // do stuff to the pdf 
} 

어떻게 수 I 포트이 VBS에? 내가 PHP와 같이 즉시 배열을 생성하는 방법을 알아낼 수 없었기 때문에, 나는 시도하고 3 조건 if 문 :

extension = objFso.GetExtensionName(objFile.Path) 
If Not (extension = "docx") OR (extension = "xlsx") OR (extension = "txt") Then 
    // do stuff to the pdf 
End If 

하지만이 작동하지 않습니다. 조건은 무시됩니다. 두 가지 질문 :

  1. 왜 조건이 무시됩니까?
  2. If 명세서 또는 If 문을 여러 개 사용하는 대신 비교할 수 있도록 배열을 즉시 만들 수 있습니까?

모든 두뇌는 크게 감사하겠습니다.

답변

3

내가 아는 가장 짧은 방법입니다 (부울 유형)

UBound(Filter(Array("docx", "xlsx", "txt"), "pdf")) > -1 반환 False

UBound(Filter(Array("docx", "xlsx", "txt"), "txt")) > -1 반환 True

당신은 Array("doc", "xlsx", "txt")가 즉석을 을 생성하고 난 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

끝내 주셔서 고맙습니다. – Pr0no

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) ... 
+1

+1 OP의 접근 방식이 작동하지 않는 이유는 무엇입니까? –

관련 문제