Visual Basic,Visual Studio 2013
我的问题是如何更改此代码以读取在文本框中写入的任何函数,该程序未支付转换错误。
Public Function f(Byval x As Double) As Double
Return x * x + 2 * x <- how read this function from textbox ?
End Function
我尝试其他的但没有工作:
Public Function f(x) As Double
f = TextBox1.Text
End Function
答案 0 :(得分:0)
您必须从文本框中读取值,检查它是否为数字,然后将该值传递给计算。
' in some code somewhere, like maybe a click event
Dim value As Double = 0
If IsNumeric(Textbox1.Text) Then
value = f(CDbl(Textbox1.Text))
End If
' Do something useful with value
' the rest of the code . . .
Public Function f(Byval x As Double) As Double
Return x * x + 2 * x
End Function