tags:

views:

209

answers:

4

Original:

Using VB6

If rsCardEvent(4).Value = Str Then TimOut = rsCardEvent(4) Else TimeOut = Left(TimOut, 2) & ":" & Mid(TimOut, 3, 2) & ":" & Right(TimOut, 2) End If

Getting Type MisMatch Error. How To Find Record Set Value is String or Number

Exactly i need

If Number means print number like Time Format (HH:MM:SS) else print string value

Coding Help for the above condition


Edited Version:

I'm working with an ADO.Recordset object and am trying to determine the data type of a column at run-time. I need to handle the column value differently in my code depending on its underlying data type. If the column value is a string, I want to work with the value as-is. If it is a number, I want to treat the number as an packed time and convert it to HH:MM:SS format (i.e. the number 120537 would be converted to the string "12:05:37").

Below is some example code that demonstrates what I want to achieve. However, when I run this code I get a "Type Mismatch" error:

If rsCardEvent(4).Value = Str Then
   TimOut = rsCardEvent(4)
Else
   TimeOut = Left(TimOut, 2) & ":" & Mid(TimOut, 3, 2) & ":" & Right(TimOut, 2)
End If
A: 

You can use the IsNumeric function available in VB6.

Kirtan
A: 

How about:

If TypeName(rsCardEvent(4).Value) = "String" then

http://msdn.microsoft.com/en-us/library/5422sfdf.aspx

Jack B Nimble
If TypeOf rsCardEvent(4).Value is String then - is Not accepting Showing Error in "TypeOf" and "is String"
Yep, TypeOf only works with objects, but have you tried TypeName like Jack suggested?
MarkJ
+1  A: 

Have a look at the Visual Basic 6 function library. There are functions that can help you determine the underlying type of a value.

There are quite a few but you might find these useful:

dariom
IsNumeric and IsString is not Accepting showing error
+1  A: 

Based on this article, if rsCardEvent is an ADO recordset, you could check the Type property. Something like this:

    Select Case rsCardEvent(4).Type
        Case adBSTR, adChar, adVarChar, adWChar, _
           adVarWChar, adLongVarChar, adLongVarWChar
            ' It is a string '
        Case Else
            ' It is not a string '
    End Select
MarkJ