老师叫我用vb编一个加法计算器代码,但是我不太会 想法是第一和第二个文本框随意输入0到100的数字,第三个文本框就等于第一和第二个文本框之和
第1个回答 2011-02-28
Private Sub Command1_Click()
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub
Private Sub Text1_Change()
If Val(Text1) > 100 Or Val(Text1.Text) < 0 Then Text1.Text = ""
End Sub
Private Sub Text2_Change()
If Val(Text2) > 100 Or Val(Text2.Text) < 0 Then Text2.Text = ""
End Sub
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub
Private Sub Text1_Change()
If Val(Text1) > 100 Or Val(Text1.Text) < 0 Then Text1.Text = ""
End Sub
Private Sub Text2_Change()
If Val(Text2) > 100 Or Val(Text2.Text) < 0 Then Text2.Text = ""
End Sub
第2个回答 2011-02-27
原理就像这样:
Edit3.Text := IntToStr(StrToInt(Edit1.Text) + StrToInt(Edit2.Text));
不过,我想你老师是让你写一个精简版的“计算器”,只保留加法这功能。本回答被网友采纳
Edit3.Text := IntToStr(StrToInt(Edit1.Text) + StrToInt(Edit2.Text));
不过,我想你老师是让你写一个精简版的“计算器”,只保留加法这功能。本回答被网友采纳
第3个回答 2011-03-01
以下为VBA中按钮代码,至于在VB中弄,太麻烦了,也犯不着:
Private Sub CommandButton1_Click()
Dim x As String
Dim y As String
Dim z As String
x = InputBox("请输入起始单元格")
y = InputBox("请输入结束单元格")
z = InputBox("请输入你想把计算结果存放的单元格")
Dim i As Single
On Error Resume Next
For Each target In Range(x
Private Sub CommandButton1_Click()
Dim x As String
Dim y As String
Dim z As String
x = InputBox("请输入起始单元格")
y = InputBox("请输入结束单元格")
z = InputBox("请输入你想把计算结果存放的单元格")
Dim i As Single
On Error Resume Next
For Each target In Range(x