vb中不同窗体的参数传递问题
我写了一个vb程序,其中一个功能是在form1单击某个按钮就到达form2,然后form2显示的东西是包含有form1的运算结果的。这是form2的formload代码P...
我写了一个vb程序,其中一个功能是在form1单击某个按钮就到达form2,然后form2显示的东西是包含有form1的运算结果的。这是form2的form load代码
Public Sub Form_Load()
lblall.Caption = "共答:" & Str(num)
lblright.Caption = "正确:" & Str(right)
lblwrong.Caption = "错误:" & Str(wrong)
Lblrightrate.Caption = "正确率:" & Str(rightrate) & "%"
End Sub
不知道为什么,显示时对于num、right、wrong、rightrate这这几个值,总是显示0
(ps:这四个变量是在form1中的运算中才有数值结果)
例如:
Public Sub Text1_KeyPress(KeyAscii As Integer)
num = num + 1
End Sub 展开
Public Sub Form_Load()
lblall.Caption = "共答:" & Str(num)
lblright.Caption = "正确:" & Str(right)
lblwrong.Caption = "错误:" & Str(wrong)
Lblrightrate.Caption = "正确率:" & Str(rightrate) & "%"
End Sub
不知道为什么,显示时对于num、right、wrong、rightrate这这几个值,总是显示0
(ps:这四个变量是在form1中的运算中才有数值结果)
例如:
Public Sub Text1_KeyPress(KeyAscii As Integer)
num = num + 1
End Sub 展开
1个回答
展开全部
form1里,在通用部分(也就是程序最上面部分)用public定义你想要传递的变量
public num as integer,right as integer,wrong as integer,rightrate as single
form2里
lblall.Caption = "共答:" & Str(form1.num)
lblright.Caption = "正确:" & Str(form1.right)
lblwrong.Caption = "错误:" & Str(form1.wrong)
Lblrightrate.Caption = "正确率:" & Str(form1.rightrate) & "%"
建议把全局变用public量定义到模块中去,这样可以直接使用,而不用加前缀。
public num as integer,right as integer,wrong as integer,rightrate as single
form2里
lblall.Caption = "共答:" & Str(form1.num)
lblright.Caption = "正确:" & Str(form1.right)
lblwrong.Caption = "错误:" & Str(form1.wrong)
Lblrightrate.Caption = "正确率:" & Str(form1.rightrate) & "%"
建议把全局变用public量定义到模块中去,这样可以直接使用,而不用加前缀。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询