简体   繁体   English

VB.Net中的VB6的vbNull是否等效?

[英]VB6's vbNull equivalent in VB.Net?

I would like to discover and use the VB.Net equivalent to replace the VbNull value seen in VB6, but I can't find the proper value that represents that null value. 我想发现并使用等效的VB.Net替换VB6中显示的VbNull值,但是我找不到代表该空值的正确值。

Dim formatProvider As NumberFormatInfo = 
    DirectCast(CultureInfo.GetCultureInfo("es-ES").NumberFormat.Clone, NumberFormatInfo)

With formatProvider
    .NumberDecimalSeparator = Microsoft.VisualBasic.vbNull
End With

Dim pi As String = Math.PI.ToString(String.Empty, formatProvider)

The NumberDecimalSeparator property does not accepts an empty value, but it accpets the vbNull value as well and it works perfectlly (the separator is removed), so... I suppose that I can reproduce the same result using the .Net Class library to avoid resort at VB6 things. NumberDecimalSeparator属性不接受空值,但也支持vbNull值,并且可以完美地工作(删除了分隔符),所以...我想我可以使用.Net类库来重现相同的结果,以避免在VB6上求助。

I've tried to replace the vbNull with those other values, but all give an exception due to the emptiness restriction of the property that I mentioned above: 我试图用其他值替换vbNull ,但是由于上面提到的属性的空性限制,它们都给出了例外:

""
String.Empty
ControlChars.NullChar()
DBNull.Value.ToString
Nothing

UPDATE 更新

I also tried these supposed solutions, any of these throws an exception of empty value but instead that it does not give me the expected result because using this as a separator to format a decimal number the number is printed broken. 我还尝试了这些假定的解决方案,其中的任何一个都抛出一个空值异常,但它没有给我预期的结果,因为使用此分隔符格式化十进制数字时,数字被打断了。

Convert.ToChar(0)
Char.ConvertFromUtf32(0)
New String(Char.ConvertFromUtf32(0))

Source: VB.NET - string of nulls 来源: VB.NET-空字符串

Trigger is correct vbNull is a constant, but its value is defined thusly: Public Const vbNull As VariantType = VariantType.Null 触发器是正确的vbNull是一个常数,但其值已这样定义: Public Const vbNull As VariantType = VariantType.Null

Please see Microsoft Reference Source 请参阅Microsoft参考源

vbnull is a datatype and not what you think it is. vbnull是数据类型,而不是您认为的那样。 From Object Viewer (VB6 or Office VBA Editor press F2) 从对象查看器(VB6或Office VBA编辑器按F2)

Const vbNull = 1
    Member of VBA.VbVarType
    Return value constant for VarType

Things you may have it confused with 您可能会混淆的事情

Const vbNullChar = ""
    Member of VBA.Constants
    Basic constant for a single Null character (ASCII value 0); equivalent to Chr$(0)

Const vbNullString = ""
    Member of VBA.Constants
    Constant for  use when calling external procedures requiring a string whose value is zero

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM