Visual Basic 中怎么让两个文本框中的变量相加,然后把结果在第三个文本框里边输出?

2024-11-24 20:53:00
推荐回答(5个)
回答1:

Private Sub Command1_Click()
Dim sum As Double
Dim a As Integer
Dim b As Integer
a = Text1.Text
b = Text2.Text
sum = a+b '把这里改了 Addition(Text1.Text, Text2.Text)
Text3.Text = sum
Text3.Refresh
End Sub
或是你的代码不改动,加一个方法
private function Addition(a as integer,b as integer)
Addition=a+b
end sub

回答2:

sum = Addition(Text1.Text, Text2.Text)
改为 sum = val(a)+val(b)

回答3:

sum = Addition(Text1.Text, Text2.Text)
改为 sum = a+b

回答4:

Private Sub Command1_Click()
Dim sum As Double
Dim a As Integer
Dim b As Integer
a = cint(Text1.Text)
b = cint(Text2.Text)
sum = Addition(a, b)
Text3.Text = cstr(sum)
Text3.Refresh
End Sub
public function Addition(byval x as integer,byval y as integer) as Double
return cdbl(x+Y)
end function

回答5:

直接 a+b