➿ 条件
🤞 If/ElseIf/Else
⚽ structure
If conditional Then
...
ElseIf conditional2 Then
...
Else
...
End If
⚽ 举例说明
例如显示当前的时间(小时),添加12/24格式的选择
> CSCRIPT if-conditional.vbs 12
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
现在是下午10点
> CSCRIPT if-conditional.vbs 24
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
现在是22点
'filename: if-conditional.vbs
'get hour of 12/24 format
Function getHour(style)
hours = Hour(Time)
If style = 12 Then
If hours < 13 Then
hours_say = hours
Else
hours_say = hours MOD 12
End If
getHour = hours_say
ElseIf style = 24 Then
getHour = hours
End If
End Function
'Main Part
argo = Wscript.Arguments.Item(0)
hourf = Hour(Time)
If argo = 12 Then
If hourf > 11 Then
ng = "下午"
Else
ng = "上午"
End If
WScript.Echo "现在是" & ng & getHour(12) & "点"
ElseIf argo = 24 Then
WScript.Echo "现在是" & hourf & "点"
End If
网友评论