Global和Public,Dim和Private变量之间有什么区别? [英] What is the Difference between Global and Public, Dim and Private variables?
问题描述
Global和Public,Dim和Private变量之间有什么区别?在Visual Basic 6.0中。因为我总是使用Public和Dim但是使用Global和Private做同样的事情,这些类型的声明范围之间是否有任何差异???????
例如:
有什么区别:
''在bas模块中
选项明确
全球gblmyVar1为龙''被宣布为全球
公共pblmyVar1为龙''被宣布为公众
''在表单模块中
私有prvRecSet为新ADODB.Recordset''声明为私有
Dim dimRecSet为新ADODB.Recordset'' Decimred as Dim
请提前帮助,谢谢。
全球和公共,弱点和私人变量之间的区别是什么?在Visual Basic 6.0中。因为我总是使用Public和Dim但是使用Global和Private做同样的事情,这些类型的声明范围之间是否有任何差异???????
例如:
有什么区别:
''在bas模块中
选项明确
全球gblmyVar1为龙''被宣布为全球
公共pblmyVar1为龙''被宣布为公众
''在表单模块中
私有prvRecSet为新ADODB.Recordset''声明为私有
Dim dimRecSet为新ADODB.Recordset''十分淡化
请提前帮助,谢谢。
嗨
Global不是vb关键字。
MSDN库说:
< blockquote class =post_quotes>
使用Public语句声明的变量可用于所有应用程序中所有模块中的所有过程,除非Option Private Module生效;在这种情况下,变量仅在它们所在的项目中是公共的。
警告Public语句不能在类模块中用于声明固定长度的字符串变量。
使用Public语句声明变量的数据类型。例如,以下语句将变量声明为整数:
Public NumberOfEmployees As Integer
如果您只使用Public希望你的变量在整个项目中具有范围。
至于暗淡:
在模块中用Dim声明的变量级别可用于模块中的所有过程。在过程级别,变量仅在过程中可用。
在模块或过程级别使用Dim语句来声明变量的数据类型。例如,以下语句将变量声明为整数。
Dim NumberOfEmployees As Integer
Global和Public,Dim和Private变量之间有什么区别?在Visual Basic 6.0中。因为我总是使用Public和Dim但是使用Global和Private做同样的事情,这些类型的声明范围之间是否有任何差异???????
例如:
有什么区别:
''在bas模块中
选项明确
全球gblmyVar1为龙''被宣布为全球
公共pblmyVar1为龙''被宣布为公众
''在表单模块中
私有prvRecSet为新ADODB.Recordset''声明为私有
Dim dimRecSet为新ADODB.Recordset''十分淡化
请提前帮助,谢谢。
全球???
公开 - 我们可以通过Direct或间接通过Project的所有部分访问该变量
Private - 只是访问的一个特殊部分
Dim - 就像调用该部分时的Private和Initialize一样
Global不是vb关键字。
啊,我们多久忘了...... :)
Global是早期版本的延续,我相信VB仍然接受它以实现向后兼容。我很确定它和Public一样对待。
What is the Difference between Global and Public, Dim and Private variables? in Visual Basic 6.0. Because I am always using Public and Dim but using Global and Private is doing the same thing, is there any differences between these types of declaration scopes???????
Example:
What is the difference:
'' In bas Module
Option Explicit
Global gblmyVar1 as Long '' Declared as Global
Public pblmyVar1 as Long '' Declared as Public
'' In Form Module
Private prvRecSet as New ADODB.Recordset '' Declared as Private
Dim dimRecSet as New ADODB.Recordset '' Decalred as Dim
Please help, thanks in advance.
What is the Difference between Global and Public, Dim and Private variables? in Visual Basic 6.0. Because I am always using Public and Dim but using Global and Private is doing the same thing, is there any differences between these types of declaration scopes???????
Example:
What is the difference:
'' In bas Module
Option Explicit
Global gblmyVar1 as Long '' Declared as Global
Public pblmyVar1 as Long '' Declared as Public
'' In Form Module
Private prvRecSet as New ADODB.Recordset '' Declared as Private
Dim dimRecSet as New ADODB.Recordset '' Decalred as Dim
Please help, thanks in advance.Hi
Global is not a vb keyword.
The MSDN library says:
Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect; in which case, the variables are public only within the project in which they reside.
Caution The Public statement can''t be used in a class module to declare a fixed-length string variable.
Use the Public statement to declare the data type of a variable. For example, the following statement declares a variable as an Integer:
Public NumberOfEmployees As IntegerOnly use Public if you want your variable to have scope in your entire project.
As for dim:
Variables declared with Dim at the module level are available to all procedures within the module. At the procedure level, variables are available only within the procedure.
Use the Dim statement at module or procedure level to declare the data type of a variable. For example, the following statement declares a variable as an Integer.
Dim NumberOfEmployees As Integer
What is the Difference between Global and Public, Dim and Private variables? in Visual Basic 6.0. Because I am always using Public and Dim but using Global and Private is doing the same thing, is there any differences between these types of declaration scopes???????
Example:
What is the difference:
'' In bas Module
Option Explicit
Global gblmyVar1 as Long '' Declared as Global
Public pblmyVar1 as Long '' Declared as Public
'' In Form Module
Private prvRecSet as New ADODB.Recordset '' Declared as Private
Dim dimRecSet as New ADODB.Recordset '' Decalred as Dim
Please help, thanks in advance.
Global???
Public - We can access that variable by Direct or Indirectly through all parts of Project
Private - Only a Pirticular part of Access
Dim - Just like Private and Initialize at the time of calling that part
Global is not a vb keyword.Ah, how soon we forget... :)
Global is a holdover from earlier versions, and I believe VB still accepts it for backward compatibility. I''m fairly certain it''s treated the same as Public.
这篇关于Global和Public,Dim和Private变量之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!