《(完整word版)VB语言基础.pdf》由会员分享,可在线阅读,更多相关《(完整word版)VB语言基础.pdf(30页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、VB语言基础一、数据类型1、数值型:取值范围:Byte(字节型)占1字节;0255无符号Integer(整型)占 2字节;-3276832767 long(长整型)占 4字节;-21474836482147483647 single(单精度浮点)占4字节;略Double(双精度浮点)占4字节;略Currency(货币型)占 8字节小数点左 15位,右4位(精确定点数据类型)2、逻辑型:Boolean(布尔型)占2字节;true或false 3、字符串型:String?a?a 定长型占字符串长度,变长型再加10 4、日期型:Date(日期型)占 8字节 100-1-19999-12-31 5、对
2、象型:Object 占 4字节;任何 Object 引用 6、变体型:Variant 变体型数字占 16字节,变体型字符占 22字节字符串长注:此类型还包含三种特定值:Empty;Null;Error;?7、用户定义的数据类型:?用户可以利用 Type 语句定义自己的数据类型。格式如下?Type 数据类型名?数据类型元素名As 类型名?End Type?用Type 可定义类似于 C语言中的结构体类型。例如:?Type Date_Rec?RYear As Integer?RMonth As String*3?RDay As Integer?End Type?注:记录类型中的元素可以是字符串,但必
3、须是定长字符串,其长度由类型名加上一个星号和常数指明。?数据类型转换函数:?函数名及书写格式转换结果?CBool(表达式)布尔型?CCur(表达式)货币型?CByte(表达式)字节型?CDate(表达式)日期型?CDbl(表达式)双精度文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4
4、I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L
5、4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4
6、L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ
7、4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:C
8、J4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:
9、CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码
10、:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2?CSng(表达式)单精度?CInt(表达式)整型?CLng(表达式)长整型?CStr(表达式)字符串?Cvar(表达式)变体型?二变量?1 变量名V中变量的命名遵从标识符命名原则:必须以字母开头;变量中间不能有空格;不能使用VB关键字;?2变量的声明VB允许使用不声明的变量,即一个变量未经声明就可以在程序中使用。这种变量使用方式称为隐含变量声明。(使用隐含变量时,VB 会自动创建变量,并赋予它变体类型。在为其指定值之前,其值为Em
11、pty,当为它赋值后,会采用所赋值的类型作为自己的类型。)?显式声明:?用类型说明符:将类型说明符加在变量名的尾部;?定义变量时指定其类型:?格式:Declare 变量名 As 类型名?其中的Declare 可以是 Dim,Static,Redim,Public中之一?用Def type 语句:Def type 字母范围?这里的Type 是类型标志,Def 是系统保留字,它们之间没有空格。例如:DefInt D-J?该定义声明了 D、E、F、G、H、I、J都是整型变量,而且以这些字母开头的变量名也都是整型变量。文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X
12、2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10
13、X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R1
14、0X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R
15、10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4
16、R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F
17、4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6
18、F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2?类型说明符:?:整型;?&:长整型;?!:单精度浮点型;?#:双精度浮点型;?:货币型;?$:字符串型;?字节、布尔、日期、对象及变体型没有类型说明符。?
19、注意:?Dim a,b,c As Integer是错误的。只有c被声明成Integer,而 a,b 缺省为 Variant类型。?如果使用 Dim x As Integer语句声明了变量 x为Integer,而在后面又使用带有类型说明符的该变量,如x$,x!,x 和x#,程序运行时就会产生“duplicate definition”错误。?使用不带 As 的Dim 语句,会被声明成变体类型的变量。?通过不带长度说明的字符串声明语句可以声明变长字符串。?对于声明布尔型的变量,其缺省值为False;文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ
20、4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:C
21、J4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:
22、CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码
23、:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编
24、码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档
25、编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文
26、档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2?为声明为 Date 类型的变量赋值时,日期值应放在一对#之间,且多种日期和时间格式在VB 中都是有效的。?3变量的作用域和生存期:?变量的作用域 指变量的有效作用范围,也
27、就是变量可以被访问的范围。按以下三种方式来定义变量的作用范围:?范围说明?过程在过程内使用 Dim 或Static?私有在模块开头加上Dim 或Private?公共在模块开头加上 Public?变量的生存期 指VB保存该变量值的时间,是变量在整个程序运行过程中的有效生存时间1)过程层变量 过程层变量是指在过程或函数内部定义的变量,这种变量无论是用Dim 还是 Static 声明,其作用域都只是该过程或函数体,在过程或函数外不能引用;2)窗体层变量 窗体层变量是指在窗体的通用部分声明的变量,即不是在任何一个窗体内的过程或函数中声明的变量。它的作用范围至少是窗体的存在范围,也就是说在窗体内的每个过
28、程或函数中都可以使用窗体层变量。?窗体层变量的声明有三种方式:?用Dim 语句声明。文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2
29、文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X
30、2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10
31、X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R1
32、0X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R
33、10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4
34、R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F
35、4R10X2?用Private语句声明。?用Public 语句声明。?对于用 Dim 和Private声明的窗体层变量,其作用范围都是在所声明的窗体范围内。用Public 声明的窗体层变量作为窗体公用数据成员,可以在其他窗体或模块中以“窗体名.变量”方式引用。其作用可以大于当前窗体范围。窗体层变量在本窗体所有过程中都是可见的。?3)模块层变量 模块(Module)是构成 VB 工程(Project)的一部分,是包含数据和过程的集合。定义模块层变量只需在模块的通用部分加入Dim,Private,Global 或Public 等声明语句即可。用Dim 和Private声明的模块层变量作用域为所在模
36、块范围,而用 Public 和Global 定义的模块层变量则可以全局使用。?注:全局变量必须用Public 或Global 声明,不能用 Dim?三常量?常量是一个有意义的名字,用来表示程序运行时不变的数值和字符串。?Visual Basic中的常量分为文字常量和符号常量两种,文字常量又可分为数字常量和字符串常量。?符号常量(自定义常量):在程序中程序员用Const 声明的常量。文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5
37、S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R
38、5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9
39、R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB
40、9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 H
41、B9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7
42、HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7
43、 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2?使用常量时应注意:?(1)用Const 声明的常量在程序运行过程中是不能被重新赋值的。?(2)在常量声明的同时赋值。?(3)可以为声明的常量指定数据类型,如Const conVal As Currency=3.78,缺省时为所赋值的类型。?(4)在用常量为常量初始化时注意,不可有循环引
44、用。例如:?模块 1中:?Public const con1=con2+8?模块 2中:?Public Const con2=con1*3?四数组?1数组的定义:?必须用 Global 或Dim 语句定义。Dim 语句的语法格式如下:?Dim 数组名(lower To upper,lower To upper)As type?在这里,每对 lower 和upper 为数组的一维,lower 是该维下标的下限,upper 是该维下标的上限,如不标明lower,其默认值为0。Upper 不可省略。文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4
45、L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ
46、4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:C
47、J4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:
48、CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码
49、:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编
50、码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档编码:CJ4L4I3N2W7 HB9R5S10Y6X10 ZI1E6F4R10X2文档