VB2005程序设计实例教程
Visual Basic 2005编程基础与项目实践_11
Visual Basic 2005 编程基础与项目实践 编程基础与项目实践——第11章 记事本 第 章
StatusStrip
Visual Basic 2005 编程基础与项目实践 编程基础与项目实践——第11章 记事本 第 章
功能实现与编码
具体源代码见: 具体源代码见:P148
Visual Basic 2005 编程基础与项目实践 编程基础与项目实践——第11章 记事本 第 章
�
运行结果
为修改字体格式和颜色的操作界面. 图11-8为修改字体格式和颜色的操作界面. 为修改字体格式和颜色的操作界面
Visual Basic 2005 编程基础与项目实践 编程基础与项目实践——第11章 记事本 第 章
小结
本章介绍了如何制作一个功能较完备的记事本,通过本章的学习, 本章介绍了如何制作一个功能较完备的记事本,通过本章的学习,不仅 可以掌握一些控件的属性,方法和事件,更重要的是展示了 可以掌握一些控件的属性,方法和事件,更重要的是展示了Visual Basic 2005大型软件的设计方法和思路,在学习的时候一定要认真思 大型软件的设计方法和思路, 大型软件的设计方法和思路 考别人的设计思路,不断地学习,思考,从中培养良好的编程习惯. 考别人的设计思路,不断地学习,思考,从中培养良好的编程习惯. 重点及难点: 重点及难点: (1)如何使用 )如何使用MenuStrip,ToolStrip,RichTextBox和StatusStrip控件 , , 和 控件 设计记事本程序界面; 设计记事本程序界面; 对话框的常用属性和使用方法; (2)OpenFileDialog,SaveFileDialog对话框的常用属性和使用方法; ) , 对话框的常用属性和使用方法 (3)记事本程序的设计与实现. )记事本程序的设计与实现.
Visual Basic 2005程式设计概要
請設計某一運輸公司表單,輸入托運重 量,求出所需金額。
每一件托運均收 300 元 基本費 重量超出 5 公斤後,每公斤收 80 元。
5-2-3 If…Then…ElseIf…:「如果…就….
否則 如果…就…否則…」(多向選擇)
If condis1 ElseIf condition2 Then statements2 ElseIf condition3 Then statements3
Visual Basic 2005程式設計
第5章 流程控制
5-1 認識流程控制
判斷結構 (decision structures)
If...Then…Else Select…Case Try…Catch…Finally
迴圈結構 (loop structures)
For...Next For Each...Next Do...Loop While…End While
5-2-2 If…Then…Else:如果 …就…否則…(雙向選擇)
If condition Then
statements1
Else
statements2
End If
Module Module1 Sub Main() Dim Num As Integer Num = CInt(InputBox("請輸入0-100的數字")) If Num >= 60 Then MsgBox("及格!") Else MsgBox("不及格!") End If End Sub End Module
5-2 If…Then…Else
5-2-1 If…Then:如果…就…(單向選擇) If condition Then statement If condition Then
Visual Basic 2005程序设计教程chap11简明教程PPT课件
清华大学出版社
11.2建立Web应用程序的运行环境
11.2.2 管理Web服务器的目录 2. 权限
访问权限用于确定给定目录的访问类型,并说明包含于目录中的文件 的允许权限。共有以下几类:脚本资源访问、读取、写入、浏览目录。 执行权限用于确定在包含于指定目录中的页面上允许执行什么级别的 程序。这里有3 种可能的值: 无、纯脚本、脚本和可执行文件。
Visual Basic 2005程序设计教程 AutoCAD计算机辅助设计
清华大学出版社
11.2建立Web应用程序的运行环境
11.2.1 安装IIS Web服务器
(1)IIS的作用 (2)不同的操作系统IIS的版本号。 (3)IIS的安装步骤 (4)打开IIS (5)关闭IIS
Visual Basic 2005程序设计教程 AutoCAD计算机辅助设计
Visual Basic 2005程序设计教程 AutoCAD计算机辅助设计
清华大控件 11.5.2 DataList控件
DataList Web服务器控件以某种格式显示数据,这种格式可以使用 模板和样式进行定义。DataList控件可用于任何重复结构中的数据,如 表。DataList控件可以以不同的布局显示行,如按列或行对数据进行排 序。 使用DataList控件时,必须将该控件绑定到数据源。最常用的数据 源是数据源控件,如SqlDataSource或ObjectDataSource控件。或者, 可以将DataList控件绑定到任何实现IEnumerable接口的类。
Visual Basic 2005程序设计教程 AutoCAD计算机辅助设计
清华大学出版社
11.3 VB 2005在开发Web应用程序时的作用 10.3.1 Connection 对象
Visual Basic 2005编程基础与项目实践(1)
ByVal e As System.EventArgs) Handles MyBase.Load
loginTimer.Enabled = T登录窗
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor ' 鼠标指针设为等待
然后在模块中添加代码如下:
Module frmModule Public ob_FrmLogin As New frmLogin
' 定义全局变量ob_FrmLogin
End Module 计时器Tick事件代码如下:
Private Sub logInTimer_Tick(ByVal sender As System.Object, ByVal e As
Visual Basic 2005 编程基础与项目实践——第17章 售楼客户需求统计系统
登录界面设计
1. “frmLogo”窗体 打开“frmLogo”窗体,给其添加一个PictureBox控件,并
通过“Image”属性设置相关的图片。 接下来添加一个Timer控件,用于控制3秒后显示登录界面。
“frmLogo”窗体界面设计结果如图17-1所示。
ComboBox2
DateTimePiker1 DataGridView1
属性 Name Name ReadOnly Name Name Name Name Name Name Name Name Name Name Name Name Items DropDownStyle Name Items DropDownStyle Name Name ReadOnly
Visual Basic 2005 编程基础与项目实践——第17章 售楼客户需求统计系统
Visual Basic 2005编程基础与项目实践_02
(3)熟练掌握常量与变量的声明。
(4)熟练掌握Visual Basic 2005的运算符和表达式,以及
常用函数的应用。
(5)掌握Visual Basic 2005编码规则。
Visual Basic 2005 编程基础与项目实践——第02章 Visual Basic 2005 语言基础
数据类型
数据类型是对各种数据形态的描述,如整型、浮点型等。
双精度型
Double
8
Visual Basic 2005 编程基础与项目实践——第02章 Visual Basic 2005 语言基础 类型 数据类型 十进制型 名称 Decimal 占用字节数 16 取值范围 0~+/79,228,162,514,264,337,593,950 ,335之间不带小数点的数;0~+/7.9228162514264337593543950335 之间带28位小数的数;最小非0数 为+/-1E-28 0~65535(无符号) 0~大约20亿个Unicode字符
指定其类型定义变量
声明变量的语法格式为: {Dim | Public | Private | Protected | Friend | Protected Friend} <变量名> [As < 数据类型>] [= <表达式>] … 说明: ① <变量名>遵循标识符的命名规则。 ② {Dim | Public | Private | Protected | Friend | Protected Friend}必选其一,表 示该变量的类型和作用域等,其中变量的作用域将在7.5节介绍。 ③ [As <数据类型>]为可选项,如果不指定则是Object类型。 ④ [= <表达式>]为可选项,可以在声明变量时给其赋初值(变量的初始化)。
Visual Basic 2005编程基础与项目实践
通过前面的学习,读者对Visual Basic 2005环境下的 Windows编程技术和方法有了基本的了解。考虑到本书 章节内容的难度由浅入深和篇幅的限制,前面设计的系 统没有将数据库连接、数据库的备份与恢复和打印报表 等常用的功能模块加入其中,本章将对这几个功能模块 进行详细的介绍。
Catch ex As Exception MessageBox.Show(ex.Message)
End Try End Sub
Байду номын сангаас
Visual Basic 2005 编程基础与项目实践——第18章 常用功能模块设计
恢复数据库代码如下: Private Sub btBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btBack.Click
Try Dim sqlstr As String Dim adapter As SqlDataAdapter Dim ds As New DataSet sqlstr = "select * from 学生基本信息表" adapter = New SqlDataAdapter(sqlstr, sqlConn) adapter.Fill(ds) dgStudent.DataSource = ds.Tables(0)
& ";Integrated Security=True"
' Windows集成安全模式
sqlConn.ConnectionString = strConn MessageBox.Show("数据库连接成功", "提示")
Visual Basic 2005程序设计实验课堂(2003格式)
实验提示:
N有可能有多种取值,要显示所有情况。
实验十七 乌龟旅行问题
实验内容:
一只乌龟决心做环球旅行,出发时踌躇满志,
第一秒爬了1米,随着体力和毅力的下降,第二 秒爬了1/2米,第三秒爬了1/3米,第四秒爬了1/4 米……,编程求解这只乌龟一小时能爬多远?爬 出10米大概需要多少分钟?
实验八 控件的移动
实验提示:
引入PictureBox控件 设置image属性导入图片 查阅帮助、教材或网络理解Top属性和Left属性 每点击一次按钮,图像可以移动10像素
实验九 种群增长问题求解
创建一个窗口应用程序(自由设计),实
现解决以下问题: 当自然资源和环境条件对种群增长起阻滞作 用时,可用Logistic曲线来描述种群增长模型。 如某农场的某种昆虫从现在(t=0)起到t周 后的数量为P(t)=20/(2+3e-0.06t)万,程序运行 时要求输入周数,点击按钮后显示该周数时 昆虫数量。用到math.exp()方法。
TextChanged
在帮助系统中找到TextChanged事件的帮助
信息,浏览中文说明。
实验三 变量、常量、类型转换
实验要求: 创建一个窗口,可以实现以下功能:
显示一个整数常量 显示我校全名 显示某种格式的日期
通过信息框显示我校简称和网址,要求分两行
显示 显示文本框中输入的内容 显示文本框中输入文本的前后两个字符
界面要求:如图上外观所示。 功能要求:
点“登录”后会在一个信息框中显示“登陆成
功” 点“重新输入”会清除用户名和密码。 点“退出”会关闭窗口。
实验二 课外思考
如果要实现在一个文本框中输入文本时,
2005程式设计教程
3-3-3 Visual Basic 2005程式碼註解 以單引號 ' 或REM關鍵字來表示註解 3-3-4 Visual Basic 2005程式碼縮排 例如:
Module Module11 Sub Main() MsgBox("Hello World!") End Sub End Module
3-3-1 Visual Basic 2005程式結構
1.
Option陳述式
Option Explicit {On|Off}
所有變數在始用之前都須先宣告。
Option Strict {On|Off}
資料型態不嚴謹要求。
字串比較根據二進位,英文字母有大小寫之分。
Option Compare {Binary|Text}
2.
3.
4.
5.
3-2-5 編譯與執行程式
請按 [F5] 鍵或點取標準工具列的 [開始 偵錯] 按鈕
3-2-6 儲存檔案、專案與方案
3-2-7 關閉檔案、專案與方案
如果只要關閉Windows Form設計工具或 目前正在編輯的檔案,可以點取 Windows Form設計工具或程式碼視窗右 上角的 [關閉] 按鈕。 如果要關閉專案及方案,可以從功能表 列選取 [檔案] \ [關閉方案]。
2.
Imports陳述式,例如:
Imports LBControl = System.Windows.Forms.ListBox Dim LBC As LBControl
3.
Namespace陳述式
4.
5.
條件編譯陳述式
Main() 程序 Sub Main() Sub Main(ByVal cmdArgs() As String) Function Main() As Integer
VB.NET vs 2005 中级篇2
实例53:获得拨号网络项目实例说明在本实例中,我们将制作一个能够取得本地计算机上的拨号网络的项目的应用程序。
程序运行结果如图53-1所示。
图53-1 运行结果技术要点●读取注册表内容●添加到列表框实现过程■新建项目打开Visual ,选择“新建项目”,在项目类型窗口中选择“Visual Basic项目”,在模板窗口中选择“Windows应用程序”,在名称域中输入“GetDialList”,然后选择保存路径。
单击“确认”。
■添加控件和设置属性向窗体上添加一个ListBox控件。
将窗体的Text属性改为“获得拨号网络项目”,其余属性都保持默认。
■添加代码Private Declare Function RegOpenKey Lib "advapi32.dll" Alias"RegOpenKeyA"(ByVal hKey As Integer, ByVal lpSubKey As String, ByRefphkResult As Integer) As IntegerPrivate Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As中 级篇 167Integer) As IntegerPrivate Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA"(ByVal hKey As Integer, ByVal dwIndex As Integer, ByVal lpName As String, ByVal cbName As Integer) As Integer Const HKEY_CURRENT_USER As Integer = &H80000001 Const ERROR_NO_MORE_ITEMS As Short = 259Const ERROR_SUCCESS As Short = 0Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load Dim hKey As Integer Dim i As IntegerDim astr As VB6.FixedLengthString = New VB6.FixedLengthString(256) If RegOpenKey(HKEY_CURRENT_USER, "RemoteAccess\Profile", hKey) = ERROR_SUCCESS ThenWhile RegEnumKey(hKey, i, astr.Value, 256) = ERROR_SUCCESSList1.Items.Add(astr.Value) i = i + 1 End While RegCloseKey(hKey) End If End Sub■运行程序单击菜单“调试|启动”或单击 图标运行程序。
VB2005-01
目錄-I
第1章: 第2章: 第3章: 第4章: 第5章: 第6章: 第7章: 第8章:
程式語言與Visual Basic的基礎 建立Visual Basic應用程式 變數、資料型態與運算子 視窗應用程式的基本輸出入 選擇控制項與條件敘述 迴圈結構 程序與函數 字串與陣列
目錄-II
如何閱讀本書(三)第12章的模組可以讓讀者建立多模組、多表單和 多文件的視窗應用程式,輕鬆擴大讀者程式設計 的視野,第13~15章是檔案、資料庫和網路程式 設計,說明Visual Basic 2005程式如何使用串 流讀寫檔案,存取資料庫和網路程式設 計。 第16章是以主控台應用程式來說明物件導向程式 設計的類別、繼承、介面、多形和運算子過載等 觀念。最後第17章說明如何使用.NET Framework類別函式庫的眾多類別物件和泛型程 式設計。
1-1-2 程式語言的種類
程式語言隨著電腦科技的進步,已經延伸 出龐大的族群。在程式語言的分類上,以 發展世代來區分,如下表所示:
程式語言 機器語言(Machine Languages) 組合語言(Assembly Languages) 高階語言(High Level Languages) 應用程式產生的語言(Application-Generation Languages)或查 詢語言(Query Languages) 邏輯導向語言(Logic-Oriented Languages)
如何閱讀本書(二)
第3章是Visual Basic 2005語言的變數、資料型 態和運算子,筆者使用主控台應用程式範例來說 明此部分的語法,第4章是以輸出和輸入角度來說 明視窗表單的輸出與輸入介面,第5~7章使用 Windows視窗應用程式範例說明Visual Basic 2005語言的流程控制和程序與函數,第8章是基 本資料結構的字串與陣列,來說明程式資料的常 用儲存方式。 第9~10章建立圖形使用介面的視窗程式設計, 說明Windows視窗程式設計的事件處理和介面設 計,第11章是如何在視窗繪圖、載入圖片和建立 動畫等多媒體效果。
使用VB2005设计Smartphone智能手机应用程序入门
要 】 m r hn :S at oe是一个兴起 中的智 能手机 系统 , coo 将 智能手机 编程 赋予给 高级语 言编程 系统 V 2 0 , p Mi sf r t B05 实
现 了大 众 化 的 程 序 开发 。通 过 实例 分 析 , S ath n 程 序 的 界 面设 计 、 序 代码 编 写 , 程序 的 调 试 、 用 , 合 程 序 员 的 从 m r oe p 程 到 应 适
等 操作 系统 的智 能 手 机 更 易 于 个人 计算 机 连 接 .更 适 合 在 微 机 的 no s 台 下 开 发应 用程 序 。 dw 平 同 时 . coo 在 Vsa td 05 中 集 成 了 使 用 V # Mirsf t i l ui 20 u S o C. N T和 V .E E BN T进 行 智 能 设 备 的开 发 。 而 VBN T拥 有 广 泛 的 .E 计 算 机 编程 人 员 。 是 高校 普 遍 开 设 的 一 门课 程 。V 2 0 ( i 也 B 05V. sa Su i 2 0 ul td 0 5中 的 V sa B s 05本 文 简 称 V 2 0 ) 突 o i l ai 2 0 , u c B 05更 出了 V B的 易 用 优 势 , 合 .E o p c Fa e r 程 设 计 , 配 N TC m at rm Wok编 轻 松 实 现 了对 S ath n 智 能 手 机 的 应 用 程序 开 发 。 m r oe p
下 面 。 用 V 2 0 计 一 个 实 现 跑 表 计 时 的 简单 程 序 , 使 B 0 5设 用
于 S ath n m r oe智 能手 机 。 了便 于分 析 , 程 序 仅 设 计 基 本 的单 p 为 本 个跑表计时 , 读者 可 以 自行 扩 充 功 能 。 31跑 表 程 序 界 面 设 计 . 如 图 1 示 。 面 设 计 比较 简单 , 所 界 添加 5个 L bl 件 、 丑e控 4个 T x o 件 、 个 Tm r 时 器 和 菜 单 按 键 Ma M n 1 ae e t x控 B 1 ie 定 i e u 。L bl n 控 件 显 示 界 面 基 本 文 字 ,eto l- T xB x , 4分别 显 示 跑 表 的 时 、分 、 秒 和毫秒。 311菜单 设 计 ..
VB2005
VB 2005程序设计
Index Prev Next End
VB2005集成开发环境
运行程序
快捷键F5 “调试”菜单中选“启动调试” 工具栏“启动调试”按钮
NO.17
Friday, August 09, 2013
VB 2005程序设计
Index Prev Next End
控件、属性和代码
启动 界面介绍
NO.11
Friday, August 09, 2013
VB 2005程序设计
Index Prev Next End
VB2005集成开发环境
菜单栏 工具栏 工具箱
解决方案资源管理器
属性栏 开始窗口 起始页 其它
NO.12
Friday, August 09, 2013
VB 2005程序设计
Index Prev Next End
.NET概述
命名空间
简单来说,在不同空间内可以使用相同的类名称,
实际就是为类创建作用域
.NET目标
易于进行编程语言(VB、C#等)的互操作
多平台运行
NO.9
Friday, August 09, 2013
VB 2005程序设计
Index Prev Next End
对象、方法和事件
事件
控件的事件是指控件对键盘和鼠标“操作”的响
应,任何控件都有自己的事件集合,一旦控件的 某个事件发生,就可以引起一个事件过程的执行, 事件的过程代码是由程序员根据自己的问题需求 编写的
NO.21
Friday, August 09, 2013
VB 2005程序设计
VISUAL BASIC 2005 教程和示例
安装Visual Basic2005要使用Visual Basic2005,你必须安装Visual Studio,因为Visual Basic是Visual Studio的一部分。
Visual Studio2005是一个微软开发工具的套装,它包含了微软的开发工具,如Visual Basic,C#,Visual C++,J#等。
Visual Studio有四个版本,按功能多少依次是:∙Visual Studio Team Edition∙Visual Studio Professional Edition∙Visual Studio Standard Edition∙Visual Studio Express Edition对于Visual Basic的一般用户来说,安装Visual Studio Express Edition或者Visual Studio Standard Edition就足够了。
Visual Studio2005安装详解我是依照Visual Studio Team Edition的安装过程来讲解和截屏的,如果你手里有的是Visual Studio的其它版本,也别担心,因为无论是Visual Studio的哪个版本,安装过程几乎都是一样的,最多是在安装功能选项中,有些版本功能多,有些版本功能少而已。
插入Visual Studio的安装光盘,你会看到如下画面。
请点击最上面的链接Install Visual Studio2005。
然后你会进入下面的画面,这时候安装程序会运行一段时间,运行完以后,右下角的Next 按钮就可以点击了。
点击Next按钮之后,你会被要求填写product key,请将I accept the terms of the License Agreement勾上,然后填上你的product key。
至于Name栏,一般来说是填写该软件的购买者。
所有填完之后再按Next。
《VB2005程序设计实例教程》-PPT第1章-PPT精选文档
1
第1章 Visual Basic 2019概述
本章内容 .NET框架体系构成 Visual Studio 集成开发环境 Visual Basic 2019应用程序的创建及调试 本章重点 Visual Studio 集成开发环境的使用 Visual Basic 2019应用程序的创建及调试 本章学习目标 了解.NET框架体系构成 掌握Visual Studio 2019集成开发环境的使用 掌握Visual Basic 2019应用程序的开发流程
3
1.1 .NET概述
1.什么是.NET 是以公共语言运行时(CLR, Common Language Runtime)为基础,以Web Services为核心技术,为信息、人、系统、智能设备提供 无缝链接的一组软件产品(如:SmartClient、服务器、 开发工具)、技术(如:Web Services)或服务(.NET Services,如.NET Passport)。 . NET以公共语言运行时CLR为基础,实现了跨平台和跨 语言开发;不管所采用的是哪种操作系统、设备或编程 语言,以XML Web Services为核心技术,应用程序就能 够通过Internet进行通讯和共享数据。
9
1.1 .NET概述
3.为什么要使用.NET Microsoft .NET的策略是将互联网本身作为构建新一代 操作系统的基础,对互联网和操作系统的设计思想进行合理 延伸。这样,开发人员必将创建出摆脱设备硬件束缚的应用 程序,从而轻松实现互联网连接。.NET的最终目的就是让 用户在任何地方、任何时间,利用任何设备都能访问所需的 信息、文件和程序。用户不需要知道这些文件放在什么地方, 只需发出请求,然后只管接收就可以了,所有后台的复杂性 是完全屏蔽起来的。由此可见,Microsoft .NET无疑是当今 计算机技术通向计算时代的一个非常重要的里程碑。
VB2005微软官方教程05
Chapter 5Constructing User InterfacesIn this chapter:Application: New Windows Forms Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131Application: Changes to Existing Windows Forms Controls. . . . . . . . . . . . . . . . .136 This chapter explores the controls and improvements to existing controls that are provided by version 2.0 of the Microsoft .NET Framework. These features allow you to create professional-looking applications that provide a better end-user experience and reduce your coding effort. Application: New Windows Forms ControlsThis application demonstrates many of the new controls available in Microsoft Visual Studio 2005 for creating compelling Windows Forms user interfaces.New ConceptsVisual Studio has a long history of providing a large library of prebuilt controls that allowdevelopers to quickly create user interfaces for Microsoft Windows applications. However, the capabilities and visual style of these components often resulted in applications that had a look and feel significantly different from other Microsoft products such as Microsoft Office andInternet Explorer. Visual Studio 2005 introduces many new controls to address this issue.These controls provide the same advanced look and feel and customization support asMicrosoft Office, which allows you to provide your users with a familiar experience andincreased personalization options.ToolStrip ControlToday’s professional applications provide many features that allow users to fully customizethe positioning, formatting, and content of their menus and toolbars. Users expect to be able to perform such tasks as moving toolbars around, selecting which buttons to display, and con-trolling how much information is presented with each item. In addition, they expect the ren-dering of these controls to be clean and consistent across applications. The ToolStrip is a new toolbar control that supports all these features and provides the base functionality for the131132Introducing Microsoft Visual Basic 2005 for DevelopersMenuStrip and StatusStrip controls. You are no longer limited to just adding buttons to yourtoolbars. The ToolStrip allows you to add seven different types of items, such as the ToolStrip-Button, ToolStripComboBox, ToolStripTextBox, and ToolStripSplitButton.The first thing you will notice when you add a ToolStrip to a form is that it looks like an Office toolbar by default. Many controls support a new pluggable rendering framework that allows you to select how you want the control to look. There are currently two main “looks” for the ToolStrip, and you select which one you want with the RenderMode property. Providing a value of System indicates that you want the control to follow the current Windows system displaysettings. Providing a value of Professional indicates that you want the control to look like itscounterpart in Microsoft Office.There are many new types of behavior—including rafting, merging, and item overflow—sup-ported by the ToolStrip. Rafting is the behavior that allows a user to drag and drop a toolbar to various locations on the form and have the toolbar automatically “snap” into position. Theintegrated development environment (IDE) automatically provides support for rafting by add-ing multiple RaftContainer controls to the form when you add your ToolStrip. You specify the initial location for the ToolStrip by setting its Raft property. At run time, the user will be able to move the ToolStrip to any of the other RaftContainers.Merging is the behavior you see when the items from two ToolStrips are combined into a single ToolStrip. You can specify whether or not a particular strip supports merging with the Allow-Merge property. You can then govern each item’s merge behavior with the MergeAction andMergeIndex properties.Item reordering is the behavior that allows a user to rearrange toolbar and menu items. Youcan enable item reordering by setting the AllowItemReorder property to True. At run time, users will be able to move items by dragging and dropping them while pressing the Alt key.FlowLayoutPanel and TableLayoutPanel ControlsVisual Studio 2005 provides two new layout controls that address some common controlpositioning scenarios. The normal Panel control uses absolute positioning to determine thelocation of each of its child controls. The FlowLayoutPanel, on the other hand, positions each control relative to the one just prior to it as you add them to the panel. By default, it flows con-trols from left to right and top to bottom, but you can control the flow direction by using the FlowDirection property. The FlowLayoutPanel is useful in situations where you want controls to automatically reposition themselves as the contents of one of the children changes or as the size of the panel changes.The TableLayoutPanel is a panel that contains an invisible table structure that allows you toplace a single control in each table cell. You can specify how many rows and columns the inter-nal table should have as well as the sizing rules for each row and column. The TableLayout-Panel is useful when you need to define major, fixed-size sections of a form. You can also useChapter 5:Constructing User Interfaces133 it to quickly create tabular data-entry interfaces. However, keep in mind that you can add onlya single control to each cell. So, if you want a cell to contain more that one child control, youneed to first add a Panel to the cell and then add your two child controls to the Panel.WebBrowser ControlVisual Studio 2005 now provides an optimized, managed wrapper for the wel1-knownActiveX Web browser control. This control provides access to the full DHTML rendering capa-bilities of Internet Explorer. You can use this control to add many kinds of Web browsingcapabilities to your applications. For example, you could allow users to read HTML documen-tation files from within your application. Or you could allow a user to link to content on the Internet. Using the WebBrowser control is straightforward, and it provides some powerfuloptions that enable deep integration between your DHTML and WinForm assets.You can download and display a document by simply calling the Navigate method and provid-ing a URL to the resource. Once it’s loaded, you can programmatically access the DHTMLDOM through the Document property. Through this property, you can directly read and mod-ify the structure of the document. You can perform standard navigation tasks through meth-ods such as GoForward, GoHome, GoSearch, and GoBack. You can even expose a managedobject to script code to allow script in the page to call into your managed application. All you have to do is supply an object to the ObjectForScripting property. Monitoring the progress of a download is accomplished by handling the WebBrowser’s events, such as Navigating, Navi-gated, ProgressChanged, and DocumentCompleted.ActiveDocumentHost ControlThe ActiveDocumentHost control provides a bridge between your Windows Forms application and OLE resources. You can load and display a resource by calling the LoadFrom method and providing the path to the resource. The ActiveDocumentHost will launch an instance of theapplication that is registered for that particular type of resource. For example, if you load aMicrosoft Word document, the ActiveDocumentHost will automatically launch Microsoft Word and display the document in a read-only state. By default, double-clicking the control willcause it to switch to an editable mode and display the editing application’s toolbars andmenus. You can control most aspects of this through properties such as ShowMenus andShowToolbars.WalkthroughThis walkthrough demonstrates how you can use these new controls to create WindowsForms interfaces that look more professional and are easier to use.134Introducing Microsoft Visual Basic 2005 for DevelopersCreating Office InterfacesThe DocumentBrowser form presents an interface that draws many of its design elements from various Microsoft products, including Office and Internet Explorer. Notice that the two Tool-Strips are rendered as Office-type toolbars, with a vertical gradient background and “grips” at their left edge. One of the ToolStrips includes a text box. There is also a third ToolStrip control in the bottom-left corner of the form with two items, Documents and Web Pages. This ToolStrip has been modified by setting its LayoutStyle to Vertical to give it a bit of a Microsoft Outlookstyle. The status bar at the bottom of the form is a StatusStrip control with two children, a Sta-tusStripPanel and a ToolStripProgressBar. The progress bar has been configured to displayprogress as a continuous strip by setting its Style property to Continuous.When you run the application, click and drag the tool strips to any edge of the form and you will see that they will automatically dock to that side. This action is possible because there isa RaftingContainer control at each edge of the form. These containers are automatically addedby Visual Studio when you add the ToolStrips to the form. You can also reorder items andeven move an item from one ToolStrip to another by holding down the Alt key and dragging an item.Interacting with Web ContentThe application uses the WebBrowser control to load and display Web content. At run time,click the Web Pages button in the bottom-left corner of the form. Next, enter a URL into the Address text box in the tool strip. Click the Go button to navigate to the document.Note If you do not have access to the Internet, an HTML page named “MSDN HomePage.htm” is available in the application directory.As the application loads, you should notice the progress bar and status text updating at thebottom of the form. When the document finishes loading, you will see an entry appear in the History List to the left of the browser pane. This progress monitoring is accomplished by han-dling numerous WebBrowser events.The process starts with the btnGo_Click event handler. In this procedure, you tell the Web-Browser to load a document by calling the Navigate method:wbrBrowser.Navigate(txtAddress.Text)When the WebBrowser starts navigating to the resource, it raises the Navigating event. ThewbrBrowser_Navigating event handler retrieves the URL from the event arguments and posts a message to the StatusStripPanel indicating that the download is in progress:SetStatus(“Navigating to ‘“ + e.Url + “‘“)Chapter 5:Constructing User Interfaces135 While the WebBrowser is loading the document, it periodically raises its ProgressChanged event. The wbrBrowser_ProgressChanged event handler updates the progress bar in the StatusStrip first, resetting it if it is already showing 100 percent, and then increments it by a value of 5:If pbrProgress.Value >= pbrProgress.Maximum ThenClearProgress()End IfpbrProgress.Increment(5)When the WebBrowser is finished loading the document, it raises the DocumentCompleted event. You can use this event to notify your user that the content is available or perhaps to log the results of the download. The wbrBrowser_DocumentCompleted event handler retrieves the title of the document from the URL of the document from the event arguments. This informa-tion is used to populate a new ListViewItem and added to the history list view. The procedure ends by resetting the status text and the progress bar:Dim title As String = e.UrlDim visited As String = DateTime.Now.ToString()Dim docInfo As New ListViewItem(New String(1) {title, visited})lvwHistory.Items.Add(docInfo)SetStatus(String.Empty)ClearProgress()Interacting with Document ContentThe application also allows you to load and display files that have been registered to allow OLE hosting. Office documents, sound files, and .avi movie files are all examples of “active” data. You can load a file by first selecting the Documents button in the bottom-left corner of the form. Then, enter a local path to the desired file in the Address text box and click the Go button. The document will display inside the ActiveDocumentHost. If the document is editable, you can double-click the ActiveDocumentHost to launch the document in its associated host application. The menu and toolbars of the host application will display in the Document-Browser form.The ActiveDocumentHost has fewer progress-related events than the WebBrowser control. How-ever, it does raise a Loaded event when it has finished loading and displaying the document. The ahdDocument_Loaded event handler starts by retrieving information about the loaded document. It then creates a ListViewItem and adds it to the history list view:Dim url As String = adhDocument.SourceDocumentDim visited As String = DateTime.Now.ToString()Dim docInfo As New ListViewItem(New String(1) {url, visited})lvwHistory.Items.Add(docInfo)SetStatus(String.Empty)ClearProgress()136Introducing Microsoft Visual Basic 2005 for DevelopersConclusionThe new Windows Forms controls provided by the .NET Framework 2.0 allow you to create applications that are more professional looking and more powerful than ever before without having to rely on third-party components. The ToolStrip provides you with a powerful mecha-nism for creating menu, tool, and status bars that look and behave like their counterparts in other applications your users are familiar with. This can translate directly into quicker useradoption and higher user satisfaction. The WebBrowser and ActiveDocumentHost allow you to integrate external data into your applications. The WebBrowser is designed for the reliable and versatile downloading and rendering of DHTML content, while the ActiveDocumentHost pro-vides a mechanism for hosting and editing OLE data types.Application: Changes to Existing Windows Forms Controls This application examines some changes and additions to the Windows Forms frameworkthat affect a broad set of existing and new Windows Forms controls.New ConceptsThe .NET Framework 2.0 and Visual Studio 2005 introduce many new features to Windows Forms development that will have a broad impact on how you work with Windows Formscontrols at both design time and run time. These features affect a wide range of behaviors,including control layout and positioning, run-time data entry, and application configuration and personalization.Margins and PaddingEnsuring that your controls are positioned and spaced consistently is important for creating applications that are easy to learn and navigate. Unfortunately, the process of positioning con-trols is at best laborious and time consuming. One aspect of proper positioning involves mak-ing sure that there is a consistent amount of space between controls. For example, you might have a series of buttons at the bottom of a form that need to have exactly ten pixels of space between each of them. This generally involves placing one button, recording its Left property and modifying the Left property of the next button to the desired amount. Another example is when you have a container control and you want to make sure that constituent controls are no closer than eight pixels from the edge of the container. At a minimum, this setup involves plac-ing the first control to serve as an anchor point and then aligning the other controls to it asappropriate.The .NET Framework 2.0 introduces two new concepts, margins and padding, to controls that greatly simplify the work involved in scenarios like those just mentioned. Margin is the exter-nal space between two controls, while padding is the internal space between a control’s edge and its contents. So, the right edge of one button and the left edge of another button is theChapter 5:Constructing User Interfaces137 margin between them. On the other hand, the space between a panel’s edge and its constitu-ent controls is the panel’s padding. The Control class now has Padding and Margin properties so that a control can declare and enforce its spacing requirements.The Margin and Padding properties are used by the Visual Studio IDE at design time to provide margin and padding indicators and to autosnap controls according to their Margin and Pad-ding properties. Both of these properties are of the Padding type, which is a simple structure that allows you to provide unique values for each edge of the control: Top, Bottom, Left, and Right. So, if you have a Panel whose Padding.Left is set to 5, and you are placing a child control on the Panel, the IDE will automatically provide you with feedback when the left side of the child control is five pixels from the left side of the Panel. This allows you to quickly place con-trols exactly where they need to be without having to manually set location properties. These properties are also honored at run time as controls are resized or relocated.Auto-CompletionIf you have used Internet Explorer, you have seen auto-completion in action. Auto-completion is the behavior you see when you enter data in a text control and the system automatically suggests what it thinks you might be entering. This feature is generally most beneficial when the user has to enter strings that are either long or complex. A prerequisite necessary for an auto-completion solution to work is the existence of some set of data that the system can use to look up possible matches.You can now easily add auto-completion support to text boxes and combo boxes in your Windows Forms applications. Both controls have three new properties: AutoCompleteMode, AutoCompleteSource, and AutoCompleteCustomSource. You enable auto-completion by setting the AutoCompleteMode to Append, Suggest, or SuggestAppend. Setting AutoCompleteMode to Append results in the most likely match being automatically appended to the current data. Using Suggest results in a drop-down list populated with one or more suggested completion strings. SuggestAppend performs both tasks. The control also needs a source list from which it can search for suggestions as the user enters data. The AutoCompleteSource property allows you to select from some system sources such as FileSystem, HistoryList, RecentlyUsedList, AllUrl, and CustomSource.If you select CustomSource, you must provide a list of strings to the AutoCompleteCustomSource property. This can be done at either design time or run time. Custom sources are very power-ful, as they allow you to provide auto-complete behavior for business data. For example, you could query a list of product categories from a database when the form loads and supply a list of category names to serve as both the display source and auto-complete source for a combo box. This approach would allow your users to quickly select a category without having to enter the full category name or manually navigate through a long list of items.138Introducing Microsoft Visual Basic 2005 for DevelopersConfigurationThe .NET Framework 1.1 provides a basic application configuration mechanism that allows you to define read-only application settings in the application configuration file. You accessthese settings through the System.Configuration.AppSettings class, which retrieves settings by key and returns a weakly typed object that you must cast to an appropriate type. This mecha-nism is useful for simple scenarios focused on relatively static data that is generally modified only by an administrator. However, many other application configuration scenarios require a more robust and flexible solution. The .NET Framework 2.0 and Visual Studio 2005 providea new configuration system for Windows Forms applications. This system addresses the lim-itations of the previous solution and introduces many new concepts that result in a more inte-grated and efficient design-time experience and a more personalized end-user experience.Note Presented here is a description of what will be available in the release-to-market (RTM)version. At the time of this writing, the configuration system is only partially implemented.Configuration Settings The configuration system provides much more robust support for the definition, reading, and writing of configuration settings. Each setting is defined by itsname, data type, scope, default value, and accessibility. All settings are strongly typed, and you can specify any serializable type. The configuration system supports many mechanisms for persisting a setting’s value, including string representation, XML serialization, and binary serialization.You can also define a setting to have one of two scopes, User or Application. Application set-tings are read-only, and their value is shared across all users of an application on a machine.By default, these values are stored in the application configuration file. User settings arestored and managed on a per-user basis and stored in user.config files. You can configure user settings to be read/write or read-only. A major feature of user settings is the configuration system’s support for roaming Windows profiles. If you specify that user settings should roam with the user’s Windows profile, those settings will automatically follow them when they run the application from another machine. The following is an example of some configuration settings:<userSettings><WindowsApplication1.MySettings><setting name="DefaultView” serializeAs="String"><value>AllEmployees</value></setting><setting name="Credentials” serializeAs="workCredentials"><value>some binary representation…</value>Chapter 5:Constructing User Interfaces139</setting></WindowsApplication1.MySettings></userSettings><applicationSettings><WindowsApplication1.MySettings><setting name="Employee_CS” serializeAs="String"><value>server=localhost;initial catalog=northwind</value></setting></WindowsApplication1.MySettings></applicationSettings>Wrapper Classes The configuration system requires that you use wrapper classes to access the settings stored in the configuration store. These wrapper classes provide the strongly typed interface to the configuration system and provide metadata that fully describes each set-ting. This allows a user of the wrapper class to understand how each setting is configured without having to directly access the configuration files.Note You should be aware that the configuration system connects to the settings store through a pluggable architecture. Initially, the system will only support storing settings in configuration files, but there will eventually be many potential settings stores.The following is the wrapper class for the settings shown previously:Imports System.ConfigurationImports Public Class SettingsWrapperInherits System.Configuration.ApplicationSettingsBase<ApplicationScopedSettingAttribute(), _DefaultSettingValueAttribute(“server=local;initial catalog=northwind”)> _Public Overridable ReadOnly Property Employee_CS() As StringGetReturn CType(Me(“Employee_CS”),String)End GetEnd Property<UserScopedSettingAttribute(), _DefaultSettingValueAttribute(“AllEmployees”)> _Public Overridable Property DefaultView() As StringGetReturn CType(Me(“DefaultView”),String)End GetSetMe(“DefaultView”) = valueEnd SetEnd Property<UserScopedSettingAttribute()> _Public Overridable Property Credentials() As NetworkCredentialGetReturn CType(Me(“Credentials”), NetworkCredential)140Introducing Microsoft Visual Basic 2005 for DevelopersEnd GetSetMe(“Credentials”) = valueEnd SetEnd PropertyEnd ClassYou use the wrapper class in your application code to access and modify your configuration settings. For example, the following code retrieves the NetworkCredential stored in the usersetting named Credentials.Dim wrapper as New SettingsWrapper()Dim cred as NetworkCredential = wrapper.CredentialsIDE Support You can manually create both the configuration files and the wrapper classes, but Visual Studio 2005 provides full IDE support for both tasks. In Visual Basic .NET, you can access the Settings Designer by right-clicking a project in Solution Explorer and selectingProperties. In the property pages list, select Settings. You will be presented with a designerthat allows you to define all aspects of your application and user settings. When you save your changes in the designer, Visual Basic will automatically create and populate the appropriateconfiguration files. It will also create a wrapper class and make it accessible through the MyObject as My.Settings.Visual Studio also fully integrates your settings into the Windows Forms design experience to provide a convenient mechanism for binding control properties to application and user set-tings. The design experience is similar to what exists today for data binding. There is a newsection in the Properties window named (ApplicationSettings). When you select this property, you are presented with a dialog that lets you bind individual control properties to configura-tion settings. Because settings are strongly typed, the IDE can even filter the list of availablesettings to only show those that are compatible with the type of the currently selected prop-erty. The code generated by this process handles populating a control’s properties from set-ting values, but the process does not add code to update those setting values when theproperty changes or when the application ends.Currently, you need to manually implement the persistence of any changed values to the set-tings store. This is not a difficult task, but it can be time consuming when you consider that it is common to have many control properties pointed to configuration settings. To ease thisburden, some controls will provide built-in support for auto-loading and persisting their prop-erty values. This support will mainly apply to layout and formatting-oriented properties such as Location and Size on container controls such as Form and SplitContainer. Other controls,such as the ToolStrip, might support other properties such as the order of its items and its cur-rent rafting location. Controls that support automatic configuration persistence have two new properties, SaveSettings and SettingsKey.Chapter 5:Constructing User Interfaces141 WalkthroughThis walkthrough demonstrates how you can use padding, auto-completion, and the new con-figuration system to create more powerful user interfaces.Using PaddingA design goal of this application was to examine easy ways to replicate the look and feel ofMicrosoft Office applications. For example, Microsoft Outlook organizes functional areas of the interface into panels separated by movable splitters. Each visual panel has a single pixel and a dark blue border, and there is consistent spacing around the outside of and between the panels. You can use many combinations of controls to achieve this look, and this application examines one of them.The main container control is the SplitContainer, which displays the history list and some but-tons on the left and displays the Web and document content on the right. The SplitContainer consists of two Panels separated by a Splitter. Although the Panel control does not allow you to specify a border color directly, you can still easily achieve the look described previously. First, set the Panel control’s BorderStyle property to None. Next, set the BackColor property to your desired border color. Finally, set the Padding.All property to define the width of your border.Now, when you place a control on the Panel and set its Dock property to Fill, the Panel will pro-vide a colored border around your control.Using Auto-CompletionThe Address text box in the tool strip uses auto-completion to suggest URLs to resources as you type them in. If you select the text box, you will see that its AutoCompleteMode property is set to Suggest. This setting is consistent with Internet Explorer’s auto-completion behav-ior. The AutoCompleteSource property changes based on what type of resource you are search-ing for. When you click either the Documents or Web Pages buttons in the bottom-leftcorner of the form, the DocTypeButton_Click event handler runs. This event handler per-forms some basic state maintenance tasks on the interface. One of these tasks is to change the AutoCompleteSource of the text box. If the user clicked the Web Pages button, theAutoCompleteSource is set to provide suggestions from all resolvable URLs. If the user clicked the Documents button, the AutoCompleteSource is set to just use the file system:txtAddress.AutoCompleteSource = AutoCompleteSource.AllUrl...txtAddress.AutoCompleteSource = AutoCompleteSource.FileSystem。
Visual Basic 2005编程基础与项目实践_06
Visual Basic 2005 编程基础与项目实践——第06章 常用控件
窗体
窗体是Windows应用程序界面的最大容器,它可以容纳其
他的一些控件,使用它和其他的Windows控件可以设计
False两个属性值,True 为默认值,设为False则标签不
可见。 4. Click、DoubleClick事件 Click为单击事件;DoubleClick为双击事件,双击标签时 发生该事件,并执行相应的程序代码。
5. MouseHover 事件
当在鼠标指针悬停在控件上时发生MouseHover 事件。
LinkLabel控件除了具有Label控件的所有属性、方法和事件以外,还 有一些自己独有的属性。
1)LinkArea属性
LinkArea 属性用于获取或设置文本中被作为超级链接的区域。例如: LinkLabel控件的Text属性为“Visual Basic 2005”,现在要为 “Basic”设置链接,因为“Basic”为该字符串的第8到13个字符, 所以应将LinkLabel控件的LinkArea 属性设为“8,13”。
出美观的用户界面,下面将介绍窗体的生成方法及其常 用的属性、方法和事件。
Visual Basic 2005 编程基础与项目实践——第06章 常用控件
窗体常用的属性、方法与事件
1. MaximizeBox和MinimizeBox属性
MaximizeBox和MinimizeBox属性用于确定窗体标题栏的右上角的最
Visual Basic 2005 编程基础与项目实践——第06章 常用控件
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
8
2.1 VB2005的基本语法
2.基本数据类型(其它类型,如下表)
数据类型 关键字 CTS类型 说明 一个16位的 Unicode字符 一系列Unicode字 符 用于包含逻辑值 2 8 所占 字 节 2 取值范围
字符型 字符串型 布尔型 日期型
char String Boolean date
6
2.1 VB2005的基本语法
2.ห้องสมุดไป่ตู้本数据类型(整数数据类型,如下表)
名 称 SByte Byte CTS类型 System.SByte System.Byte 说 明 所占 字节 1 1 取 值 范 围 -128~127 0~255
8位有符号整数 8位无符号整数
Short
UShort Integer UInteger
4
2.1 VB2005的基本语法
1.VB2005编程规则
(3)语句书写规则 ①语句书写自上而下,一般情况下,一条语句占一行,按 Enter键结束。 ②在同一行上可以书写多条语句,每条语句间用冒号“:”分 隔。 ③如果一条语句太长,在一行写不下,可在本行后面加上续 行符“ _”(由一个空格和一个下划线组成),按Enter键后,在 下一行书写后面的代码。 (4)添加注释语句。 注释语句只对代码起说明作用,不参加编译。注释语句可添 加到代码的任意位置,可与其他代码写在一行,也可单独另起一 行。在VB2005中常用的注释方法有2种: ①一是在注释内容前加一个撇号“′”,然后输入注释内容。 ②二是选定要注释的行,单击“文本编辑器”工具栏上的 “注释选定行”按钮。
第2章 Visual Basic 2005编程基础
本章内容 基本数据类型 常量与变量 运算符和表达式 流程控制语句 函数和过程 本章重点 数据类型及变量的使用 控制语句的使用 本章学习目标 掌握VB2005的编程规则 掌握VB2005的数据类型及变量的使用 掌握控制语句的使用 掌握函数和过程的创建和使用
4
±1.5x10-45~±3.4x1038
System.Double
双精度符点数 System.Decimal Decimal(定点) 精确到小数点后 28位有效数字 8 ±5.0x10-324~±7x10308
16
±1.0×10-28~±7.9×1028
定点类型和浮点类型都可以表示小数,二者之间有何区别?定点小数数据类型的取 值范围要比浮点类型数据的取值范围小,但是计算机精度要比浮点型数据高的多;要把 数字(如1.34)指定为定点小数类型,必须在数字的后面加上m或M(如1.34m),否则 就会认为是标准的浮点数据类型。
3
2.1 VB2005的基本语法
1.VB2005编程规则
(2)用于标识符的约定 ①标识符命名尽量“见名知意”。给应用程序的变量名、方 法名、类名、枚举名和命名空间选择名称时,要使应用程序易于 理解,既能反映对象的功能,又能看出对象的类型。 ②标识符不区分大小写,Mycomputer和mycomputer是相同变 量。为了增强标识符的可读性,可以参照Pascal命名规范,要求 名称中的每个单词的第一个字母大写,例如EmploySalary , ConfirmationDialog;也可以参照Camel命名规范,要求名称中的 第一个单词的第一个字母不是大写,其余单词的首字母要大写, 例如:employeeSalary,confirmationDialog。 ③命名空间的名字很重要,要避免不同应用程序中使用相同 名称的命名空间。
5
2.1 VB2005的基本语法
2.基本数据类型
VB2005数据类型分为两类:值类型和引用类型。从概念上来讲, 值类型变量直接存储数据;而引用类型变量存储对值的引用,即数 据内存的地址,两个引用类型数据可以指向同一个对象实例 。 在VB2005中,值类型的数据类型有:基本数据类型、结构和枚 举;引用类型有:String、数组和Object(对象)类型。本章主要 介绍基本值类型,其它类型将在后面介绍。
System.Int16
System.Uint16 System.Int32 System.Unt32
16有符号整数
16无符号整数 32有符号整数 32无符号整数
2
2 4 4
-32768~32767
0~65535 -2,147,483,648到2,147,483,647 0~4294967295 -9,223,372,036,854,775,808~ 9,223,372,036,854,775,807 0~18446744073709551615
Long
ULong
System.Int64
System.Uint
64有符号整数
64无符号整数
8
8
7
2.1 VB2005的基本语法
2.基本数据类型(浮点小数与定点小数,如下表)
关键字 CTS类型 System.Single 说明 所占字节 取值范围
Single (浮点)
Double(浮点)
单精度符点数
1
第2章 Visual Basic 2005编程基础
2.1 2.2 2.3 2.4 2.5 2.6 VB2005的基本语法 运算符和表达式 流程控制语句 函数与过程 本章小结 实训作业
2
2.1 VB2005的基本语法
1.VB2005编程规则
每种编程语言都有自己的编程规则,有些规则是在语言的使 用过程中约定俗成的,有些规则是编译器强制使用的。VB2005语 言的主要编程规则如下: (1)用于标识符的规则 标识符是一串字符,是给变量、用户自定义类型和这些类型 的成员指定的名称。 ①标识符必须是以字母或下划线“_”开头,其后可以跟随任 意字母、数字和下划线。如unit1和unit_2是合法的,而3year (数字开头)和m#(#是非法字符)是非法的。 ②一般不能把关键字作为标识符。例如,数据类型名称 Integer、Single、String,语句特征符号If、While等。关键字 是高级程序设计语言中属于语言成分的特殊标识符,由系统保留 使用,每个关键字都有特殊意义。如果需要把某一关键字作为标 识符,则可以通过将名称括在方括号 ([ ]) 中来忽略此限制。