Vb.net dbnull和string.empty,dbnull有效,但string.empty不起作用 [英] Vb.net dbnull and string.empty, dbnull working but string.empty is not

查看:116
本文介绍了Vb.net dbnull和string.empty,dbnull有效,但string.empty不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向其他开发人员寻求帮助.
我的软件有问题,不是主要问题,
但我想了解一下为什么这个问题
发生了.

我有一个文本框,在其中输入数字,它将变成文本框2中的单词.
我把它放在editvaluechanged事件中.

I would like to request some help from fellow developers.
I have and issue with my software, it is not major issue,
but i want to gain some understanding why is this issue
happening.

I have a text box where i enter a number and it will change to words in text box 2.
I put it in editvaluechanged event.

Private Sub BCAmaunTxtEdt_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BCAmaunTxtEdt.EditValueChanged

    'convert number to words in upper case
    Dollar2WordMemoEdt.Text = UCase(ConvertCurrencyToMalay(BCAmaunTxtEdt.EditValue))

End Sub



到目前为止,每次框的值超过突然为空时,我都会报错,
由于下面的代码,它引发了空错误



so far i was getting errors every time the box has a value than suddently is empty,
it throws a null error because of the code below

' Convert MyNumber to a string, trimming extra spaces.
        MyNumber = Trim(Str(MyNumber))



所以我做了,我试图用这段代码停止它



so what i did was, i tried to stop it with this code

if not BCAmaunTxtEdt.EditValueChanged = string.empty then
Dollar2WordMemoEdt.Text = UCase(ConvertCurrencyToMalay(BCAmaunTxtEdt.EditValue))
end if



一切顺利,直到今天,当我尝试删除if命令时,
本来是想抛出一个错误,但经过进一步调查却没有这么做
我发现它只会在string.empty或"时抛出错误,但
不要去dbnull.对于dbnull情况,它会通过并返回单词"tiada"
我指定了是否没有美元或美分的价值.现在,为什么删除了if命令后,代码为什么没有引发错误,如果它是string.empty或",为什么为什么会引发错误?

请帮助那些知道的人.



all when well, until today, when i tried to remove the if command,
it was suppose to throw an error but it did not, after further investigation
i found out that it will only throw an error if it is string.empty or "" but
not to dbnull. for the dbnull case it goes through and return the word "tiada"
which i specified if there was no value for dollars or cents. Now why did the code did not throw an error after i remove the if command and why do it throw an error if it is a string.empty or ""?

please help to those in the know.

推荐答案

您发布的代码都不是.Net.您要从VB6转换吗?如果这样做,将避免出现以下异常:

None of the code you posted is .Net. Are you converting from VB6? If you do this, you will avoid the exception:

Private Sub BCAmaunTxtEdt_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BCAmaunTxtEdt.EditValueChanged
        ' convert number to words in upper case
    Dim myValue as Double
    If Not string.IsNullOrEmpty(BCAmaunTxtEdt.EditValueDoub) And Double.TryParse(BCAmaunTxtEdt.EditValue, myValue) Then
        Dollar2WordMemoEdt.Text = ConvertCurrencyToMalay(BCAmaunTxtEdt.EditValueDoub).ToUpper()
    End If
End Sub



顺便说一句,这是一个.Net解决方案,因此,如果您不是真正在使用.Net,则必须使答案适应所用的VB版本.



BTW, this is a .Net solution, so if you''re not really doing .Net, you''ll have to adapt the answer to whatever version of VB it is that you''re using.


这篇关于Vb.net dbnull和string.empty,dbnull有效,但string.empty不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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