Reputation: 481
i am declaring this variable as a date:
Dim fromdate as Date
inside a while loop when reading in a .csv file, i read this value:
Input(1, fromdate)
but if the value in the CSV file is blank i am getting an error saying
Index was outside the bounds of the array.
how can i set fromdate
as todays date in vb.net (Date.Now.ToString("dd/MM/yyyy")
) if its blank in the .csv file?
Upvotes: 0
Views: 731
Reputation: 3356
there should be a problem with the value you are trying to read. Maybe it's not there (as the error is mentioning).
Anyway you can try this code and catch the error and control it :
Try
Input(1, fromdate)
Catch ex As IOException
MessageBox.Show(ex.Message)
' try to set the date in another way or choose the default value
End Try
From MSDN
Exceptions :
- IOException [52] : FileNumber does not exist.
- IOException [54] : File mode is invalid.
See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.
Upvotes: 1