要求的全局变量这是一个赋值,它是其中一个要求。我不太了解全局变量。我试图设置shoestotal作为一个全局变量,然后以另一种形式使用它 这是我的第一种形式的代码,我不太确定从哪里开始下一个。我试过了,但它给了我$ 0如何使用全局变量
私人小组Frm7_Load(发送者为对象,E作为EventArgs的)把手MyBase.Load TxtBox7.Text = FormatCurrency(Frm3.Shoestotal) 结束小组
第一种形式
Public Class Frm3
Public Shoestotal As Single
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Lbl3.Click
End Sub
Private Sub Btn2_Click(sender As Object, e As EventArgs) Handles Btn2.Click
Me.Close()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Btn4.Click
TxtBox1.Text = ""
TxtBox2.Text = ""
TxtBox3.Text = ""
TxtBox4.Text = ""
TxtBox5.Text = ""
TxtBox6.Text = ""
TxtBox7.Text = ""
TxtBox8.Text = ""
TxtBox9.Text = ""
TxtBox10.Text = ""
TxtBox11.Text = ""
End Sub
Private Sub Btn3_Click(sender As Object, e As EventArgs) Handles Btn3.Click
Frm2.Show()
Me.Close()
End Sub
Private cntstyle = 0
Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles Btn1.Click
Dim blackprice As Single = 43.0
Dim classyheelprice As Single = 48.95
Dim redprice As Single = 35.95
Dim weddingprice As Single = 155.65
Dim sportsprice As Single = 50
Dim price1 As Single
Dim price2 As Single
Dim price3 As Single
Dim price4 As Single
Dim price5 As Single
If TxtBox1.Text.Length <> 0 Then
Dim qty1 As Integer = Int32.Parse(TxtBox1.Text.ToString())
price1 = qty1 * blackprice
End If
If TxtBox3.Text.Length <> 0 Then
Dim qty2 As Integer = Int32.Parse(TxtBox3.Text.ToString())
price2 = qty2 * classyheelprice
End If
If TxtBox4.Text.Length <> 0 Then
Dim qty3 As Integer = Int32.Parse(TxtBox4.Text.ToString())
price3 = qty3 * redprice
End If
If TxtBox5.Text.Length <> 0 Then
Dim qty4 As Integer = Int32.Parse(TxtBox5.Text.ToString())
price4 = qty4 * weddingprice
End If
If TxtBox6.Text.Length <> 0 Then
Dim qty5 As Integer = Int32.Parse(TxtBox6.Text.ToString())
price5 = qty5 * sportsprice
End If
Shoestotal = price1 + price2 + price3 + price4 + price5
TxtBox11.Text = FormatCurrency(Shoestotal)
TxtBox2.Text = FormatCurrency(price1)
TxtBox7.Text = FormatCurrency(price2)
TxtBox10.Text = FormatCurrency(price3)
TxtBox9.Text = FormatCurrency(price4)
TxtBox8.Text = FormatCurrency(price5)
If TxtBox1.Text.Length <> 0 Then
cntstyle += 1
End If
If TxtBox3.Text.Length <> 0 Then
cntstyle += 1
End If
If TxtBox4.Text.Length <> 0 Then
cntstyle += 1
End If
If TxtBox5.Text.Length <> 0 Then
cntstyle += 1
End If
If TxtBox6.Text.Length <> 0 Then
cntstyle += 1
End If
If cntstyle > 4 Then
Btn4.PerformClick()
MessageBox.Show("Only 3 styles can be chosen")
End If
End Sub
这心不是一个全局变量在所有 - 它是一种形式的水平VAR,你有隐式转换一个更大的问题 - 打开选项严格。因为,表单变量应该工作 - 我猜你会遇到与默认表单实例有关的问题。显示如何尝试从另一个表格使用 – Plutonix
Private Sub Frm7_Load(sender As Object,e As EventArgs)Handles MyBase.Load TxtBox7.Text = FormatCurrency(Frm3.Shoestotal)End Sub – Rob
'Frm3'是一个类名。你需要一个适当的表单实例来确保你引用了你的想法。但那不是全球性的,只是形成水平, – Plutonix