
如何写2个文本框间数累加的命令?如text1和text2之间所有数的累加和为text3.而text1和text2为1~100的数。
2个回答
展开全部
Dim a As Integer, b As Integer, s As Integer, i As Integer
s = 0
a = Val(Text1.Text)
b = Val(Text2.Text)
If a > b Then
a = Val(Text2.Text)
b = Val(Text1.Text)
End If
For i = a To b
s = s + i
Next i
Text3.Text = s
s = 0
a = Val(Text1.Text)
b = Val(Text2.Text)
If a > b Then
a = Val(Text2.Text)
b = Val(Text1.Text)
End If
For i = a To b
s = s + i
Next i
Text3.Text = s
更多追问追答
追问
不行哎。。。。出错了、
追答
你是不是直接将代码复制到VB中代码窗口中了,那不行,你自己还要做几项工作。
1、添加三个文本框
2、如果不使用命令按钮,可将上述代码复制到form_Click()事件中;如果想使用按钮,则需要在窗体中添加一个命令按钮,将上述代码复制到Command1_Click()事件中.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询