Results 1 to 5 of 5

Thread: modify existing vb 6 code

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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 ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
    Last edited by jmsrickland; Aug 4th, 2015 at 09:38 AM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    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

  5. #5
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    694

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width