|
-
Jan 4th, 2011, 08:14 AM
#1
Thread Starter
New Member
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
-
Jan 4th, 2011, 08:36 AM
#2
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.
-
Jan 4th, 2011, 08:45 AM
#3
Re: Compile error: type mismatch
Yes you are getting Line Input & Input confused.
Visit the forum's FAQ section regarding file input/output
-
Jan 4th, 2011, 09:53 AM
#4
Thread Starter
New Member
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
-
Jan 4th, 2011, 11:33 AM
#5
Re: Compile error: type mismatch
 Originally Posted by Bluen
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|