我想知道是否有一种简单的方法可以在一个表单上声明一个变量,然后可以在多个单独的表单上使用它。我看到了这个建议:
Public Variable_Name As String
但是它似乎无法工作,尽管将它放在公共类中并且在公共类中也引用了Variable_Name的代码。如果有人有任何他们知道会有效的建议,我们将不胜感激!
更新: 表格1上的代码:
Public Class WithdrawFunds
Public Funds As String = "0"
Public Sub Button_Withdraw_20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Withdraw_20.Click
Static Funds As String = "$20"
Dim SlideCheckout As New Checkout
SlideCheckout.Show()
Me.Hide()
End Sub
结束班
表格2上的代码:
Public Class Checkout
Public Sub Checkout_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Label_Amount.Text = WithdrawFunds.Funds
End Sub
End Class
答案 0 :(得分:0)
我不知道是否解决了它我认为你正在使用两个基金变量 你应该尝试这样
Public Class WithdrawFunds
Public Funds As String = "0"
Public Sub Button_Withdraw_20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Withdraw_20.Click
Funds = "$20"
Dim SlideCheckout As New Checkout
SlideCheckout.Show()
Me.Hide()
End Sub
祝你好运XD
答案 1 :(得分:0)
把它放在一个模块中:
Public Module MyVariables
Public Funds As String = "0"
End Module
Public Class WithdrawFunds
Public Sub Button_Withdraw_20_Click( ... )
MyVariables.Funds = "$20"
End Sub
End Class
Public Class Checkout
Public Sub Checkout_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Label_Amount.Text = MyVariables.Funds
End Sub
End Class