2013-10-15 31 views
-2

伙计们可以在一个表单上全局声明一个变量,并且能够在另一个表单上调用该变量?或者我应该说:你如何声明一个变量GLOBALLY?Visual Basic .NET逻辑

+1

谷歌这个疑问,有很多的例子。 –

+0

一个很好的学习起点[类与模块](http://stackoverflow.com/questions/881570/classes-vs-modules-in-vb-net),那么你可以通过一些基本的搜索来提炼你的知识 – Steve

回答

0

只需将变量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在订单上共享。我不知道我是否有道理......所以我在努力把它放在代码中。 –