Results 1 to 5 of 5

Thread: Compile error: type mismatch

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    10

    Compile error: type mismatch

    Actually this is from text book.
    My code is:

    Code:
    Private Sub mnuCheck_Click()
    Dim TempDate As Date
    CheckFile = Dir(ThisDir, vbNormal)
    
    Do While CheckFile <> ""
    
        If Right(CheckFile, 3) = "cqu" Then
        Open CurDir + "\Car Quotes\" + CheckFile For Input As #1
        Line Input #1, TempDate
    
        If Date - TempDate > 30 Then
        txtDate = TempDate
        End If
        End If
    CheckFile = Dir
    Loop
    End Sub
    when I tested running it, error code appear and the 'TempDate' is highlighted yellow.
    could someone please tell where my mistake is..?

    p/s:Just tell me if I need to add more information if the code above is not enough

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Compile error: type mismatch

    If you read the help files, you will find that Line Input# wants a string or a variant.
    So change TempDate accordingly.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Compile error: type mismatch

    Yes you are getting Line Input & Input confused.
    Visit the forum's FAQ section regarding file input/output
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    10

    Re: Compile error: type mismatch

    I changed a bit and it works
    Code:
    Private Sub mnuCheck_Click()
    Dim TempDate As Date
    Dim TempDa as String
    CheckFile = Dir(ThisDir, vbNormal)
    
    Do While CheckFile <> ""
    
        If Right(CheckFile, 3) = "cqu" Then
        Open CurDir + "\Car Quotes\" + CheckFile For Input As #1
        Line Input #1, TempDate
        txtDate = TempDate
        If Date - TempDate > 30 Then
    
        End If
        End If
    CheckFile = Dir
    Loop
    End Sub
    thanks a lot

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Compile error: type mismatch

    Quote Originally Posted by Bluen View Post
    I changed a bit and it works
    Code:
    Private Sub mnuCheck_Click()
    Dim TempDate As Date
    Dim TempDa as String
    CheckFile = Dir(ThisDir, vbNormal)
    
    Do While CheckFile <> ""
    
        If Right(CheckFile, 3) = "cqu" Then
        Open CurDir + "\Car Quotes\" + CheckFile For Input As #1
        Line Input #1, TempDate
        txtDate = TempDate
        If Date - TempDate > 30 Then
    
        End If
        End If
    CheckFile = Dir
    Loop
    End Sub
    thanks a lot
    You declared a new variable and never used it in the code, and you are still using a Date variable for reading instead of using a string !

    What VBClassicRocks & LaVolpe suggested is that, you could use a String variable to read the date (ie. in Line Input) and convert that string obtained to an appropriate Date and use it in the rest of the code.

    For converting string to date, you could use the CDate() function.

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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