0
我有一个在VBA中很好的功能,但显然不是在VBS中。VBA文本文件输入/输出功能转换为VBS
我相信我必须将其转换为使用FSO? 但我真的不知道如何开始这样做。
它似乎也不喜欢指定参数和函数数据类型?
我的功能是:
Function CSV_1304_USA_date_convertor(ByVal InputFile As String, ByVal OutputFile As String) As Boolean
CSV_1304_USA_date_convertor = False 'set as failed until the end
On Error GoTo error1 'error trapping
Dim ThisString As String, vArray As Variant 'set up the variables
Open InputFile For Input As #1 'open the input file
Open OutputFile For Output As #2 'open/create the output file
Line Input #1, ThisString 'copy the first row (headings)
Print #2, ThisString
While Not EOF(1) 'loop for each row
Line Input #1, ThisString 'read in the row
vArray = Split(ThisString, ",") 'split into an array
For x = 0 To UBound(vArray) 'for each field in the array
If Mid(vArray(x), 3, 1) = "/" And Mid(vArray(x), 6, 1) = "/" Then 'if it is a date (ISDATE doesnt work as they are American!)
vArray(x) = Mid(vArray(x), 4, 2) & "/" & Left(vArray(x), 2) & "/" & Right(vArray(x), 2) 'switch the day and month around
End If
Next x
Print #2, Join(vArray, ",") 'join array back into comma delim text and put the row into the output file
Wend
Close #1 'close the input file
Close #2 'close the output file
CSV_1304_USA_date_convertor = True 'success!
Exit Function 'end
error1:
'the function will return as false
On Error Resume Next 'ignore any further errors
Close #1 'close the input file, if possible
Close #2 'close the output file, if possible
End Function
好,我没弄明白,但显然我不能回答我的问题呢。明天我会发布我的最终代码。 – Treva26