modify existing vb 6 code
I have a vb6 program that checks for reminders. the files are saved with the due date as the file name
i am trying to modify it to create a file 1 year later when the file is deleted
if ckEveryYear is checked the filename would then be eg: Yr01-03-2017.rtf
It loads the listbox fine, but trying to check them for due dates gives an error(type mismatch)
ckEveryYear
Dim TaskDate As Date
myDate = Date
listbox contents
01-03-2017.rtf
02-20-2016.rtf
03-10-2016.rtf
06-23-2016.rtf
07-26-2016.rtf
08-06-2015.rtf
09-25-2015.rtf
11-18-2015.rtf
11-29-2015.rtf
12-01-2015.rtf
12-26-2015.rtf
Yr01-03-2017.rtf
For i = 0 To cboTasks.ListCount - 1
this line now has error (Type mismatch) when it tries to process Yr01-03-2017.rtf:
TaskDate = CDate(Left$(cboTasks.List(i), Len(cboTasks.List(i)) - 4)) - miFirstReminderDays '4
How can this be corrected ?
Re: modify existing vb 6 code
It doesn't look right.
CDate(Left$(cboTasks.List(i), Len(cboTasks.List(i)) - 4)) - miFirstReminderDays
Left of "Yr01-03-2017.rtf" - 4 is "Yr01-03-2017"
"Yr01-03-2017" - miFirstReminderDays doesn't make any sense as you are trying to subtract something (miFirstReminderDays) from a text string which will cause Type Mismatch
What does miFirstReminderDays contain?
If what you want is NN-NN-NNNN from either NN-NN-NNNN.rtf or from YrNN-NN-NNNN.rtf
then you should first do this:
SomeString = Left$(cboTasks.List(i), Len(cboTasks.List(i)) - 4)
which now leaves you this:
SomeString = "NN-NN-NNNN" or SomeString = "YrNN-NN-NNNN"
then do this:
SomeString = Right(cboTasks.List(i), 10)
which now leaves you this:
"NN-NN-NNNN"
Now take that and convert to date
Code:
For i = 0 To cboTasks.ListCount - 1
SomeString = Left$(cboTasks.List(i), Len(cboTasks.List(i)) - 4)
SomeString = Right(cboTasks.List(i), 10)
TaskDate = CDate(SomeString)
Next i
otherwise I don't know what you are doing as I have no idea about miFirstReminderDays since subtracting it will always cause a Type Mismatch
Re: modify existing vb 6 code
The last entry in that list would be a problem because once you trim off those last four characters you still are left with a string that is not a valid date.
You would need to add additional code to check for that yr in the first two positions and skip or remove it when present before you would be left with a valid date
Re: modify existing vb 6 code
Something like this:
Code:
Dim taskdate As Date
Dim i As Integer
' Dim miFirstReminderDays As Integer
' miFirstReminderDays = ??? 'Don't forget to declare i and miFirstReminderDays and set miFirstReminderDays
For i = 0 To cboTasks.ListCount - 1
If Mid(cboTasks.List(i), 1, 2) <> "Yr" Then
taskdate = CDate(Left$(cboTasks.List(i), Len(cboTasks.List(i)) - 4)) ' - miFirstReminderDays
Debug.Print taskdate
Else
Debug.Print CDate(Mid$(cboTasks.List(i), 3, Len(cboTasks.List(i)) - 6)) ' - miFirstReminderDays
End If
Next i
Re: modify existing vb 6 code
Code:
Dim sTaskDate As String
Dim TaskDate As Date
sTaskDate = UCASE(cboTasks.List(i))
sTaskDate = Replace(sTaskDate, "YR","")
sTaskDate = Replace(sTaskDate, ".RTF","")
TaskDate = cDate(sTaskDate)