打印乘法口诀表:在C盘建立文件test.vbs,代码如下
'调用示例:'用 c: 和 cd / 命令到位置 C:\>'输入命令 cscript test.vbs 9 //Nologo'可以计算 1-9 的乘法口诀表Option Explicit '所有变量必须声明后再使用'输入参数:口诀表上线数字,默认为9Dim NumberNumber = 9If WScript.Arguments.Count > 0 Then Number = WScript.Arguments(0)End If '输入参数不为正整数则直接退出If Not IsNumeric(Number) Then WScript.Echo "参数必须为正整数" WScript.Quit End IfIf Number <= 0 Then WScript.Echo "参数必须为正整数" WScript.Quit End If '每行的文字Dim Line Line = ""'口诀表标题WScript.Echo WScript.Echo "乘法表 (1 - " & Number & ")"WScript.Echo '输出口诀表Dim i, jFor i = 1 To Number Line = "" For j = 1 To Number Line = Line & i & "*" & j & "=" & (i * j) Line = Line & Chr(9) 'Chr(9):水平制表符 Next WScript.Echo LineNext
运行结果为
1)9为输入参数,意为打印1*1到9*9的乘积
2)//Nologo意为不打印Microsoft版权信息
END