• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 全局變量的定義和使用

    發表于:2007-05-25來源:作者:點擊數: 標簽:開發在用全局義和使用
    在用 VB 開發 軟件時,經常需要在不同的窗體間共享數據,但在過多的使用全局變量時不便于軟件的調試和修改。通常有兩種解決方法。 第一種方法:定義全局變量,然后在各個窗體中直接使用,例如 Public strCustomerID As String Public strCustomerName As Str

        在用VB開發軟件時,經常需要在不同的窗體間共享數據,但在過多的使用全局變量時不便于軟件的調試和修改。通常有兩種解決方法。

    第一種方法:定義全局變量,然后在各個窗體中直接使用,例如
    Public strCustomerID    As String
    Public strCustomerName  As String

    第二種方法:添加一個模塊專門用于定義變量,然后定義一些Public過程或函數來設置和獲取這些數據,例如
    Dim strCustomerID    As String
    Dim strCustomerName  As String

    Public Sub SetCustomerID(CustomerID As String)
        strCustomerID = CustomerID
    End Sub

    Public Function GetCustomerID() As String
        GetCustomerID = strCustomerID
    End Function

    Public Sub SetCustomerName(CustomerName As String)
        strCustomerName = CustomerName
    End Sub

    Public Function GetCustomerName() As String
        GetCustomerName = strCustomerName
    End Function

    其實這兩種方法都有缺點,使用第一種方法時,當過程或函數中過于頻繁的使用全局變量時會給調試和修改程序帶來很大的工作量,有時會產生災難性的后果。使用第二種方法時,若共享數據很多,則需要定義很多的Set*和Get*函數。小弟經驗有限,望各位大蝦多多指教,同時歡迎來Email:xbxue@163.com共同探討。

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>