An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
VB的基本概念之一:标识符 • 标识符:变量、常量、数据类型、过程、函数、类等定义的名字。 • 规则:必须以字母(A-Z、a-z)、数字(0-9)或下划线,长度不能超过255个字符,且标识符不能与VB的关键字同名。 • 例如:Dim Mystring As String Const Pi=3.1415926 Public function getvalue() As Integer
VB6的关键字 • VB6的关键字有:As Binary ByRef ByVal Date Else Empty Error False For Friend Get Input Is Len Let Lock Me Mid New Next Nothing Null On Option Optional ParamArray Print Private Property Public Resume Seek Set Static Setp String Then Time To True WithEvents
VB的变量 • 变量名的命名遵从标识符命名规则。 • 变量的声明:VB可以使用不声明的变量。如:Form的Click过程,加入下列代码:Private sub Form_click() Stringtext$=“Hello,World!” print “*********”,Stringtext$ end sub
VB变量的声明 • 格式:Dim 变量 AS 类型 :说明局部变量 • 格式2:Private 变量 As 类型 :说明私有变量 • 格式3:Public 变量 As 类型 :说明公告全局变量 • 格式4:Static 变量 As 类型 : 说明静态变量
记录类型数据 • 记录类型定义: [Private|Public] Type 记录类型名 成员列 End Type • 在记录类型中声明静态数时,必须用数字文字或常量而不能用变量来声明。 • 定义记录类型变量:用来说明拥有这种类型的变量,如:Dim stu1,stu2 As stu. • 记录类型变量的赋值和检索。
IS比较示例 • 有下列语句: Dim_ myobject,yourobject,thisobject,otherobject,mycheck set yourobject=myobject set thisobject=myobject set thatobject=otherobject mycheck=yourobject is thisobject ‘true mycheck=thatobject is thisobject ‘false
LIKE示例 • 如:Dim Mycheck Mycheck=“aBBBa” like “a*a” ‘BBB与*相匹配,返回结果True • 见书P58
条件分支——IF语句 • 第一种格式:if 条件 then 语句 end if 如果条件为true,则执行“语句”,否则执行end if后面语句。 第二种格式:if 条件 then 语句 else 语句 end if
IF语句的第三种格式 • If 条件1 then 语句1 else if 条件2 then 语句2 else 语句3 end if 如果条件1为true,则执行语句1,如果为false,则检查条件2,如果条件2为true,则执行语句2,如果条件2为false,则执行语句3。
条件语句——select case语句 • 格式: select case 测试表达式 case 条件1 语句1 ……… case else 语句 end select VB将测试表达式的值与此同时结构中的每个case的值进行比较,如果相等,就执行与该case 相关的程序段,如果都不等,则执行case else所对应的程序段。
Case 语句举例一 • 用select case…….语句判断0-9范围内整树的奇偶性。 select case Num_ten case 0,2,4,6,8 print “偶数“ case 1,3,5,7,9 print “奇数“ end select
循环语句:Do……Loop语句 • 第一种格式:Do While 条件式 [程序段] Loop 当条件为true时,循环继续,直到条件变为False为止。
示例一 • Private Sub Form_Click() Dim I As Integer I=1 Do While I<=5 Print I I=I+1 Loop End Sub
Do ……Loop第二种格式 • Do Until 条件式 [程序段] Loop 当条件为false时,循环继续进行,直到条件式变为true为止。
示例二 • Private Sub Form_Click() Dim I As Integer I=1 Do Until I>5 Print I I=I+1 Loop End sub
Do……Loop第三种格式 • Do [程序段] Loop While 条件式 当条件式为true时,循环继续进行,直到条件式变为false为止。