2010-02-20 80 views

回答

6

一個可操作的答案(對於其他人可能需要它)是定義該功能,從Rosetta Code

sub Assert(boolExpr, strOnFail) 
     if not boolExpr then 
      Err.Raise vbObjectError + 99999, , strOnFail 
     end if 
    end sub 

調用:

Set obj2 = Nothing 
    Assert Not obj2 Is Nothing, "obj2 is Nothing!" 

輸出:

someScript.vbs(17, 3) (null): obj2 is Nothing! 
+0

Rosetta Code是一個非常有趣的網站。感謝和鏈接的+1。 – Knox 2010-02-20 18:25:49

+0

@Knox:我直到今天才發現Rosetta Code。我同意:這似乎是一個非常有趣的網站。 – 2010-02-20 18:47:32

3

不幸的是,我不相信VBScript有任何內置的東西。您需要定義自己的Assert方法,並可能使用預處理器構建腳本或其他東西在構建腳本的發行副本時將其刪除。 (實際上除去 - 至少註釋掉 - Assert呼叫是最好的,而不僅僅是使得Assert的主體在發佈的代碼中不做任何事情。)