我想使用一个函数对欧元转换器进行一种补偿。 我希望系统执行此操作,当您在文本框中键入数字并按转换时,我希望标签中的欧元转换数字显示出来。
我相信这是通过告诉系统将任何数字乘以转换率1.34509来实现的。
但我不认为我正确地做到了。
Protected Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
End Sub
Function Convert(txtPound As Decimal) As Decimal
'declare variable to store answer
Dim Converter As Decimal
'calculate the Answer
Converter = Convert(txtPound * 1.34509)
'return the Answer
Return Converter
End Function
End Class
答案 0 :(得分:0)
您需要获取输入的金额并将其转换为小数,然后才能计算:
Dim pounds As Decimal
pounds = Decimal.Parse(txtPound.Text)
Converter = Convert(pounds * 1.34509)
答案 1 :(得分:0)
这符合您的要求,
的事件:强> 的
'---This is the procedure which is going to handle your btnGo's Click Event
Protected Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
'---Here we are calling the function Convert(Decimal) by passing the txtPound's text
msgbox(Convert(Decimal.Parse(txtPound.Text)))
End Sub
的功能强> 的
'---This function will receive the passed value as xValue and execute its code
Private Function Convert(xValue as Decimal) as Decimal
'---This line will do the conversion and simply send back the result to the caller.
return (xValue * 1.34509)
End Function
此外,如果您需要更多说明,请参阅this.