VB中怎么把另一个窗体text中的信息定为一个变量?

来源:百度知道 编辑:UC知道 时间:2024/07/07 01:06:48
就是 一个工程 有几个窗体 想在form5中定义一个变量a等于form6中

text1中输入的信息 (其中text1中的输入已经规定只能是数字)

还有就是怎么才能把 2个类似这样的变量进行数学运算(比如减法运算)

刚刚学VB一天多 很多都不知道 不要笑我 分不多 诚恳请教!!
Private Sub Form_Load()
Dim a As Single
Dim b As Single
Dim c As Single
Timer1.Enabled = True
Timer1.Interval = 1000
h = 0

a = Val(Form6.Text1.Text)
b = Val(Form6.Text2.Text)
c = a - b

End Sub

Private Sub timer1_timer()
h = h + 1
If h = 2 and c = 1 Then
Unload Me
Form2.Show
End If
End Sub

form6.text1中输入2 form6.text2中输入1
怎么 Unload Me 和 Form2.Show 都还是不能实现
去掉and c = 1 就能实现
但这不是我要的效果啊

之所以去掉and c = 1 就能实现,是因为你的变量声明用错了。应该这样改:
'====代码部分====
Dim c As Single ,h as integer
Private Sub Form_Load()
Dim a As Single
Dim b As Single
Timer1.Enabled = True
Timer1.Interval = 1000
h = 0

a = Val(Form6.Text1.Text)
b = Val(Form6.Text2.Text)
c = a - b

End Sub

Private Sub timer1_timer()
h = h + 1
If h = 2 and c = 1 Then
Unload Me
Form2.Show
End If
End Sub

1、
a=form6.text1
2、
c=a+b
3、多试验,多看帮助。窗体不要太多。

答案补充:

Private Sub timer1_timer()
h = h + 1
If h = 2 and c = 1 Then
Unload Me
Form2.Show
End If
End Sub

1、这里的h在每次运行到该过程都是0而不会继承上次的值。因为你没有声明他为窗体级变量。而默认测试过程级别。
建议在所有的代码之前加上:dim h as integer

2、下面两行代码把顺序颠倒一下也许会更好。
Unload Me
Form2.Show

3、在该过程中c永远等于0
道理挤解决的办法,同h一样。

form5.text1.text=form6.text1.text