如何查找记录集值是数字还是字符串?

时间:2021-11-20 19:24:42

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

如果rsCardEvent(4).Value = Str则TimOut = rsCardEvent(4)Else TimeOut = Left(TimOut,2)&“:”&Mid(TimOut,3,2)&“:”&Right(TimOut,2)End如果

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

如果Number表示打印编号,如时间格式(HH:MM:SS),则打印字符串值

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").

我正在使用ADO.Recordset对象,并尝试在运行时确定列的数据类型。我需要在代码中以不同的方式处理列值,具体取决于其基础数据类型。如果列值是一个字符串,我想按原样使用该值。如果是数字,我想将该数字视为打包时间并将其转换为HH:MM:SS格式(即数字120537将转换为字符串“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

4 个解决方案

#1


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

看看Visual Basic 6函数库。有些函数可以帮助您确定值的基础类型。

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

有很多,但你可能会发现这些有用:

#2


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

根据这篇文章,如果rsCardEvent是一个ADO记录集,你可以检查Type属性。像这样的东西:

    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

#3


You can use the IsNumeric function available in VB6.

您可以使用VB6中提供的IsNumeric函数。

#4


How about:

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

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

#1


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

看看Visual Basic 6函数库。有些函数可以帮助您确定值的基础类型。

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

有很多,但你可能会发现这些有用:

#2


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

根据这篇文章,如果rsCardEvent是一个ADO记录集,你可以检查Type属性。像这样的东西:

    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

#3


You can use the IsNumeric function available in VB6.

您可以使用VB6中提供的IsNumeric函数。

#4


How about:

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

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