美文网首页
VBscript:控制流 - 条件判断 If/ElseIf/El

VBscript:控制流 - 条件判断 If/ElseIf/El

作者: 喷射的熔浆 | 来源:发表于2017-08-31 22:36 被阅读0次
    magic-rock-by-lou-lu

    ➿ 条件

    🤞 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
    

    Reference

    1. WScript.echo without a Carriage Return
    2. Windows batch: echo without new line
    3. VBScript - Overview

    相关文章

      网友评论

          本文标题:VBscript:控制流 - 条件判断 If/ElseIf/El

          本文链接:https://www.haomeiwen.com/subject/wzscjxtx.html