我对将a_hasil(Form1)显示到label21(Form2)感到困惑。有人可以帮帮我吗我的代码出了什么问题。谢谢 Form1中:
Public Class Form1
Public a, b, c, d, a_hasil, b_hasil, c_hasil, d_hasil As Double
Public Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
a = Val(textBox1.Text)
b = Val(textBox2.Text)
c = Val(textBox3.Text)
d = Val(textBox4.Text)
a_hasil = (a * 1) + (b * 0.667) + (c * 1) + (d * 0.75)
b_hasil = (a * 0.5) + (b * 0.778) + (c * 0.667) + (d * 1)
c_hasil = (a * 0.625) + (b * 1) + (c * 0.778) + (d * 0.875)
d_hasil = (a * 0.5) + (b * 0.889) + (c * 0.889) + (d * 0.875)
Dim Form2 As New Form2
Form2.stringpass = a_hasil
Form2.Show()
End Sub
End Class
窗体2:
Public Class Form2
Public Property stringpass As Double
Public Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
label21.Text = stringpass
End Sub
End Class
答案 0 :(得分:0)
您的加载方法从未被调用过。添加句柄。其余的似乎没问题,但我会要求您将类变量限制为仅需要的内容。
Public Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
更改为
Public Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load