这是代码
Public Partial Class MainForm
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
'
' TODO : Add constructor code after InitializeComponents
'
End Sub
Sub Label4Click(sender As Object, e As EventArgs)
End Sub
Sub Button2Click(sender As Object, e As EventArgs)
Dim poundInAKg As Double = 2.20462
Dim KGInAPound As Double = 0.453592
If pound.Text = " " Then
MessageBox.Show("Please fill atleast one value Kilo or Pound : ")
End If
kilo.Text = Val(pound.Text) * 0.453592
'pound.Text = Val(kilo.Text / 2.20462 )
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
End Sub
End Class
错误是来自' Double'的隐式转换。 to' String'。 (BC42016) 请帮忙
答案 0 :(得分:0)
您应该使用double.TryParse方法尝试将用户输入(字符串)转换为double值,然后,如果转换成功,执行moltiplication并将所有内容重新转换回字符串
Dim poundInAKg As Double = 2.20462
Dim KGInAPound As Double = 0.453592
Dim poundVal As Double
if double.TryParse(pound.Text, poundVal) Then
kilo.Text = (poundVal * 0.453592).ToString()
else
MessageBox.Show("Please fill atleast one value Kilo or Pound : ")
End If