VB编程问题:计算不同窗口里的数字的值

来源:百度知道 编辑:UC知道 时间:2024/04/28 12:51:50
例如在Form1里的Text1.text里输入1
在Form2里的Text1.text里输入2
把在Form1里的Text1.text里的1加上在Form2里的Text1.text里的2
怎样在Form3里的Text1.text显示它们的和

Form1.Text1.Text = Int(Form2.Text1.Text) + Int(Form3.Text1.Text)

具体作法:
在Form1代码中输入:
Private Sub Form_Load()
Form2.Show
Form3.Show
Form2.Text1.Text = ""
Form3.Text1.Text = ""
End Sub

在form2和form3中分别输入:
Private Sub Text1_Change()
If IsNumeric(Form2.Text1.Text) And IsNumeric(Form3.Text1.Text) Then
Form1.Text1.Text = Int(Form2.Text1.Text) + Int(Form3.Text1.Text)
End If
End Sub
这样在Form2或form3输入数字,Form1中就会同步显示两个和的计算结果.

'在FORM3里写如下代码
Text1 = Val(Form1.Text1) + Val(Form2.Text1)