当我尝试将vb6升级到.net时,invalidcastexception会发生任何帮助,感激不尽... [英] Invalidcastexception occur when i try to upgrade vb6 to .net any help appreciate...

查看:58
本文介绍了当我尝试将vb6升级到.net时,invalidcastexception会发生任何帮助,感激不尽...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'FIXIT: Declare 'varValue' with an early-bound data type                                   FixIT90210ae-R1672-R1B8ZE
Public Function NullToText(varValue As Variant) As String

    ' Append an empty string, forcing a conversion
    ' of a Null value to a string, leaving normal
    ' strings as is.
    NullToText = varValue & vbNullString

End Function

推荐答案

您到底想做什么?首先,基本上所有对象都有 ToString() [ ^ ]方法,因为它已定义在Object类上,并在所有其他类上派生.

如果您想知道什么是变体,请使用object.

如果问题出在varValue为Nothing的情况下进行转换,则可以使用类似以下内容的方法:
What is exactly that you''re trying to do? First of all, basically all objects have ToString()[^] method since it''s defined on Object class and derived on all other classes.

If you''re wondering what is the equivalent for variant, use object.

If the problem lies in conversion if varValue is Nothing, then you could use something like:
Public Function NullToText(varValue As Object) As String
    If varValue Is Nothing Then
        NullToText = ""
    Else
        NullToText = varValue.ToString()
    End If
End Function


但是,根据环境和您使用此函数的用途,如果将十进制数字,日期等传递给该函数并使用不同的语言环境,则可能无法正常工作,因为转换应了解区域性.例如,请参阅: Int32.ToString方法(IFormatProvider) [


However, depending on your environment and what you use this function for, that may not work correctly if decimal numbers, dates etc. are passed to the function and different locales are used since the conversion should be culture aware. For example, see: Int32.ToString Method (IFormatProvider)[^]


这篇关于当我尝试将vb6升级到.net时,invalidcastexception会发生任何帮助,感激不尽...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆