vbscript 字符串到目前为止

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 字符串到目前为止相关的知识,希望对你有一定的参考价值。

Function StringToDate(strDate As String) As Variant
'Description: converts date string to date (long)
'             applicable formats: "yyyy.(m)m.(d)d(.)", "yyyy/(m)m/(d)d(/)", "yyyymmdd"
'Inputs:      date as string
'Outputs:     date as long if conversion is successful, otherwise FALSE
'Dependency:  CountCharacter; IsCorrectDate

'*** Deklarációk ***
Dim intYr       As Integer
Dim intMo       As Integer
Dim intDay      As Integer
Dim arrDate     As Variant
Dim S           As Variant
Dim Separators  As Collection
Const Separator1 As String = "."
Const Separator2 As String = "/"
'*******************
    
    Set Separators = New Collection
    With Separators
        .Add Separator1
        .Add Separator2
    End With
    
 '	examine pre-defined separator characters
    For Each S In Separators
        If CountCharacter(strDate, Format(S, "@")) >= 2 And CountCharacter(strDate, Format(S, "@")) <= 3 Then
            arrDate = Split(strDate, S)
            intYr = arrDate(0)
            intMo = arrDate(1)
            intDay = arrDate(2)
            If IsCorrectDate(intYr, intMo, intDay) = True Then
                StringToDate = DateSerial(intYr, intMo, intDay)
                Exit Function
            Else
                StringToDate = False
            End If
        End If
    Next S
    
'	  if no separator was found check if date is valid without separator 
    If Len(strDate) = 8 Then
        intYr = Left(strDate, 4)
        intMo = Mid(strDate, 5, 2)
        intDay = Right(strDate, 2)
        If IsCorrectDate(intYr, intMo, intDay) = True Then
            StringToDate = DateSerial(intYr, intMo, intDay)
            Exit Function
        End If
    End If
    StringToDate = False
    
End Function

以上是关于vbscript 字符串到目前为止的主要内容,如果未能解决你的问题,请参考以下文章

VBscript创建数组但省略空白变量

VBSCRIPT PPT转换脚本

使用 vbscript 填充预先存在的 Excel 表单

如何使用 PowerShell 或 VBScript 获取正在运行的应用程序列表

HTA中的外部VBScript

在没有记录集循环的情况下使用 ado 和 vbscript 从 csv 更新数据库?