Option Explicit
Dim oldLocale, testCount
oldLocale=SetLocale(1033)
testCount=0
Sub AssertEq(label, actual, expected)
If IsNull(actual) Then Err.Raise 513,"MBSKY","Unexpected Null: " & label
If actual<>expected Then Err.Raise 514,"MBSKY",label & " expected=" & CStr(expected) & " actual=" & CStr(actual)
testCount=testCount+1
WScript.Echo "PASS" & vbTab & label & vbTab & CStr(actual)
End Sub
Function SampleCallback(value)
SampleCallback=value+1
End Function
Dim i, result, choices, n, expected, d, boolValue
For i=9 To 11
If i<10 Then result="early" Else result="later"
If i=9 Then expected="early" Else expected="later"
Call AssertEq("if_boundary_" & i,result,expected)
Next
choices=Array(10,11,12,16,0)
expected=Array("start","hungry","lunch","home","other")
For n=0 To UBound(choices)
i=choices(n)
If i=10 Then
result="start"
ElseIf i=11 Then
result="hungry"
ElseIf i=12 Then
result="lunch"
ElseIf i=16 Then
result="home"
Else
result="other"
End If
Call AssertEq("elseif_" & i,result,expected(n))
Next
For d=1 To 7
Select Case d
Case 1: result="Sunday"
Case 2,3,4,5,6: result="weekday"
Case Else: result="Saturday"
End Select
If d=1 Then expected="Sunday" Else If d=7 Then expected="Saturday" Else expected="weekday"
Call AssertEq("select_" & d,result,expected)
Next
Call AssertEq("null_comparison_is_null",IsNull(Null=1),True)
Call AssertEq("weekday_tuesday",Weekday(DateSerial(2026,11,3),vbMonday),2)
Call SetLocale(oldLocale)
WScript.Echo "COMPLETE" & vbTab & testCount & vbTab & "MBSKY mbsky.com"
本例需在 Windows CScript / VBScript10.8.16384 / locale1033临时还原 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows CScript / VBScript10.8.16384 / locale1033临时还原
入口文件:projects/vbs-lab/vbscript-conditionals.vbs
预期结果与验证条件观察提示
- 本章具名断言全部通过,并输出COMPLETE与MBSKY mbsky.com
- 历史IE/ASP、人工模态及外部COM依赖另为待运行,不把WSH语言适配冒称同环境验收
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联10章) · 含当前章节或实例 · mbskycom202611a549.zip