Visual Basic(初学者)错误:对象引用未设置为对象的实例

时间:2018-04-16 11:07:53

标签: vb.net

我是初学者所以请你好。我在Visual Basic中制作货币兑换计算器,我遇到了一个我似乎无法弄清楚的错误:

  • 未将对象引用设置为对象的实例。

以下是我正在努力解决的代码:

Dim Currency As Double
Dim TextOther As String = Othertext.Text
Dim TextGBP As String = GBPtext.Text

Private Sub Calculate_Click(sender As Object, e As EventArgs) Handles Calculate.Click
    TextOther = Currency * Convert.ToDouble(TextGBP)
    TextGBP = Currency * Convert.ToDouble(TextOther)
End Sub

提前谢谢。

1 个答案:

答案 0 :(得分:1)

您需要将货币设置为某种内容并使用' .text。之后(我假设是)你的文本框。

还可以在点击事件中设置变量。

Dim Currency As Double
Dim TextOther As String
Dim TextGBP As String

Private Sub Calculate_Click(sender As Object, e As EventArgs) Handles Calculate.Click
currency = 10.0
TextOther = Othertext.Text
TextGBP = GBPtext.Text

TextOther.text = Currency * Convert.ToDouble(TextGBP)
TextGBP.text = Currency * Convert.ToDouble(TextOther)
End Sub