Visual Basic .NET逻辑
答
只需将变量Public
。更妙的是,使之成为公共财产,例如:
Private _data As AccountCharacteristics
Public Property Data() As AccountCharacteristics
Get
If _data Is Nothing Then
Data = New AccountCharacteristics()
End If
Return _data
End Get
Set(ByVal value As AccountCharacteristics)
_data = value
If value IsNot Nothing Then
AccountNumber.Text = value.AccountNumber
End If
End Set
End Property
如果您希望变量在窗体的所有COPES共享,使其Public Shared
代替
+0
@Shaw ,我感谢你的男人。我认为你是能够帮助我的人......我正在开发订购系统,我添加一个新客户,然后“客户表单”进入订单表格,就像一个流程流程......所以在添加新客户之后订购表格,我想要我们刚添加的customerID在订单上共享。我不知道我是否有道理......所以我在努力把它放在代码中。 –
答
创建Class
具有Shared Property
然后你可以从任何Form
访问,无论或者是否Form
已被实例化与否。
这是一个Declare global variables in Visual Studio 2010 and VB.NET描述该怎么做。
谷歌这个疑问,有很多的例子。 –
一个很好的学习起点[类与模块](http://*.com/questions/881570/classes-vs-modules-in-vb-net),那么你可以通过一些基本的搜索来提炼你的知识 – Steve