中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Visual Basic > 系统
全局变量的定义和使用
作者:xbxue 时间:2001-11-05 10:49 出处:互联网 责编:chinaitpower
              摘要:全局变量的定义和使用

    在用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共同探讨。

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有