1

This solutions below seems to work when the value is in quotes below. For some reason when I try to use my variable called OGcalendarDate instead (same exact string that is in the input variable below) I get the mismatch error. Is there something I'm doing wrong? My source file is a CSV and the vbscript is reading that file and outputting another file. I don't understand the difference between the input variable and the OGcalendarDate variable which i'm pulling from the CSV.

Dim input: input = "Sun Apr 05 00:00:00 CDT 2020"
Dim data: data = Split(input, Chr(32))
'Ignore first and sixth element in the array and build our date value
Dim output: output = CDate(data(1) & " " & data(2) & " " & data(5)) & " " & TimeValue(data(3))
Call Wscript.Echo(output)
Kevin
  • 33
  • 4
  • 1
    As I mentioned in [the comments](https://stackoverflow.com/questions/67548387/cannot-convert-my-variables-to-cdate-or-serial-date-getting-mismatch-error#comment119440843_67548697) in my [previous answer](https://stackoverflow.com/a/67548697/692942) you need to determine what the format is in the source data. If it's a CSV file instead of opening it Excel use Notepad to see what the raw data looks like. – user692942 May 17 '21 at 17:54
  • Thank you for replying again. It looks the exact same. The CSV does include quotes wrapped around each field that's the only difference i can see. – Kevin May 17 '21 at 17:56
  • So basically: "value1","value2","Sun Apr 05 00:00:00 CDT 2020","value5",etc. – Kevin May 17 '21 at 18:03
  • 2
    I don't think the code is necessarily the problem, but your input data. With that being said, your input data is not something we can see or have access to and therefore I am unsure if your question is answerable in its current state. – K.Dᴀᴠɪs May 17 '21 at 18:17
  • 1
    @Kevin is it possible that one of the records doesn't match that format, I'm assuming there is more than one record in the CSV? – user692942 May 17 '21 at 18:26
  • @user692942 I thought that as well but i limited the CSV file to the one record that contains that value I was testing with and i get the "Subscipt out of range: [number: 1] – Kevin May 17 '21 at 18:29
  • 1
    @Kevin that's a different error than last time that's related to the `Split()` generation of the array `data()`. Is it possible that it includes non-printable characters other than space (`Chr(32)`) like tab or non-breaking space? You could try something like `input = Replace(input, Chr(32), "-")` and then output `input` to see if all the spaces are replaced, which should help determine if other non-printable characters are in the string. – user692942 May 17 '21 at 18:33
  • @user692942 not that i can see. Is it possible for me to upload the CSV here with the one record to review? I must not be seeing something? – Kevin May 17 '21 at 18:37
  • 2
    I figured this out thanks for reaching out again. The issue was due to the script looping to a blank record. Had to check the split(0) and see what it was outputting and make sure it was skipping the last record. – Kevin May 18 '21 at 00:08

0 Answers0