蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

VBScript实例索引与逐项目标:独立核心实例

VBSCRIPTWindows CScript / VBScript10.8.16384 / locale1033临时还原vbscript-examples.vbs
vbscript-examples.vbs58 行
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 fixedDate, count, val, i, n, seconds, errorCode, r, links, chosen
fixedDate=DateSerial(2026,11,3)+TimeSerial(14,20,30)
Call AssertEq("current_date_time",IsDate(Now()),True)
Call AssertEq("weekday_name",WeekdayName(Weekday(fixedDate,vbMonday),False,vbMonday),"Tuesday")
Call AssertEq("month_name",MonthName(Month(fixedDate),False),"November")
Call AssertEq("current_month_name",Len(MonthName(Month(Date())))>0,True)
Call AssertEq("current_weekday_name",Len(WeekdayName(Weekday(Date()),False))>0,True)
seconds=CDbl(DateDiff("d",DateSerial(2026,11,3),DateSerial(3000,1,1)))*86400
Call AssertEq("year3000_double_seconds",seconds>2147483647,True)
On Error Resume Next
r=DateDiff("s",DateSerial(2026,11,3),DateSerial(3000,1,1))
errorCode=Err.Number:Err.Clear
On Error GoTo 0
Call AssertEq("year3000_datediff_no_error",errorCode,0)
Call AssertEq("year3000_datediff_double",TypeName(r),"Double")
Call AssertEq("year3000_actual_seconds",r,seconds)
On Error Resume Next
val=CLng(r):errorCode=Err.Number:Err.Clear
On Error GoTo 0
Call AssertEq("year3000_clng_overflow",errorCode,6)
Call AssertEq("date_add",Day(DateAdd("d",2,fixedDate)),5)
Call AssertEq("formatted_time",Len(FormatDateTime(fixedDate,3))>0,True)
Call AssertEq("not_a_date",IsDate("mbsky"),False)
Call AssertEq("case",LCase(UCase("mbsky")),"mbsky")
Call AssertEq("trim",Trim(" sky "),"sky")
Call AssertEq("reverse",StrReverse("sky"),"yks")
Call AssertEq("integer_down",Int(-2.4),-3)
Call AssertEq("integer_toward_zero",Fix(-2.4),-2)
Call AssertEq("banker_even",Round(2.5),2)
Call AssertEq("banker_odd",Round(3.5),4)
Randomize 42
links=Array("/tutorials/","/tools/","/news/")
For i=1 To 100
 val=Rnd():Call AssertEq("random_range_" & i,val>=0 And val<1,True)
 n=Int(100*val):Call AssertEq("random_0_99_" & i,n>=0 And n<=99,True)
 chosen=links(Int(3*val)):Call AssertEq("random_link_" & i,Left(chosen,1),"/")
Next
Call AssertEq("left",Left("mbsky.com",5),"mbsky")
Call AssertEq("right",Right("mbsky.com",3),"com")
Call AssertEq("mid",Mid("mbsky.com",3,3),"sky")
Call AssertEq("replace",Replace("mbsky.net","net","com"),"mbsky.com")

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-examples.vbs

预期结果与验证条件观察提示
  • 本章具名断言全部通过,并输出COMPLETE与MBSKY mbsky.com
  • 历史IE/ASP、人工模态及外部COM依赖另为待运行,不把WSH语言适配冒称同环境验收

请结合实际环境逐项观察。

附件与关联工程包下载

下载课程关联工程包:VBScript

课程关联工程包(登记关联10章) · 含当前章节或实例 · mbskycom202611a549.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习