-1

我想使用函数制作一种英镑到欧元的转换器。我希望系统做什么,当您在文本框中输入您的号码并按转换时,我希望标签中的欧元转换号码显示出来。

我相信这是通过告诉系统将输入的任何数字乘以 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
4

2 回答 2

0

您需要获取输入的金额并将其转换为小数,然后才能计算:

Dim pounds As Decimal
pounds = Decimal.Parse(txtPound.Text)
Converter = Convert(pounds * 1.34509)
于 2013-01-13T13:18:19.333 回答
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

此外,如果您需要对此进行更多说明,请参考此内容。

于 2013-01-13T14:59:12.143 回答