04
2019
10
Basic异常处理
异常处理VB的异常处理和C#的一样,都有Try、Catch、Finally部分。Public Module ExceptionHandling
Sub HandleException()
Try
&n
作者:lianhe | 分类:Basic手册 | 浏览:92 | 评论:0
04
2019
10
Basic继承
继承继承基类和实现接口的声明必须写在类实现的前面。如果一个方法重写了基类的版本,那么这个方法应该使用Overrides关键字修饰。如果不希望类被其他类继承,可以使用NotInheritable修饰,类似于Java的final关键字或者C#的sealed关键字。如果子类需要调用基类的方法,可以使用MyBase关键字代表基类。Class Circle
Inherits Shape
作者:lianhe | 分类:Basic手册 | 浏览:100 | 评论:0
04
2019
10
Basic面向对象编程
面向对象编程类VB的类和C#的类非常相似,同样有字段、属性等概念。构造函数使用New声明,不需要返回值。析构函数使用Finalize声明,也不需要返回值。 Class Contact
' 字段
Private _name As String
Private _tel As
作者:lianhe | 分类:Basic手册 | 浏览:89 | 评论:0
04
2019
10
Basic可变参数列表
可变参数列表可变参数列表使用ParamArray声明。Function PrintIntegers(ParamArray integers As Integer())
For Each i In integers
 
作者:lianhe | 分类:Basic手册 | 浏览:68 | 评论:0
02
2019
10
Basic函数
Sub函数回头来看看前面的HelloWorld,其中就有一个Main函数,它是一个Sub函数,也就是没有返回值的函数。Imports System
Module Program
Sub Main(args As String())
Console.WriteLine("Hello&nb
作者:lianhe | 分类:Basic手册 | 浏览:89 | 评论:0
28
2019
09
Basic数组
Basic数组
先来看看数组定义。VB中的数组比较特殊,定义一个Dim a1(3),其实是下标0-4长度为四的一维数组,这一点要非常注意。
'下标0-9的十个元素的数组 Dim array1(9) As Integer '11X11的二维数组 Dim array2(2, 2) As Integer '定义并初始化数组 Dim array3() = {1, 2, 3, 4, 5} '锯齿数组,也就是数组的数组 Dim array4 As Integer()() = New Integer(1)() {} array4(0) = New Integer() {1, 2} array4(1) = New Integer() {3, 4}
访问数组元素需要使用圆括号,而不是一般语言的方括号。
'初始化一维数组 For i As Integer = 0 To 9 array1(i) = i Next '初始化二维数组 For i = 0 To 2 For j = 0 To 2 array2(i, j) = (i + 1)*(j + 1) Next Next
最后就是遍历数组了,可以使用For循环迭代下标,或者用Foreach循环直接遍历元素。
'显示数组 For Each e In array1 Console.Write(e) Next Console.WriteLine For i As Integer = 0 To 2 For j = 0 To 2 Console.Write(array2(i, j)) Next Console.WriteLine Next For Each e In array3 Console.Write(e) Next Console.WriteLine For i As Integer = 0 To 1 For j = 0 To 1 Console.Write(array4(i)(j)) Next Console.WriteLine Next
作者:lianhe | 分类:Basic手册 | 浏览:93 | 评论:0
27
2019
09
Basic跳转语句
Exit语句
Exit语句用于结束某个代码块,它的形式如下。想用Exit退出哪个代码块,就写哪个代码块的类型。
Exit { Do | For | Function | Property | Select | Sub | Try | While }
Continue语句
Continue语句用于结束当前循环,直接进行下一次循环。它的形式如下,后面跟要继续的代码块类型。
Continue { Do | For | While }
Goto语句
最后就是Goto语句,它会直接跳转到指定的标签处。
'Goto语句 GoTo Ending Console.WriteLine("Print something") Ending: Console.WriteLine("This is end.")
作者:lianhe | 分类:Basic手册 | 浏览:108 | 评论:0
27
2019
09
Basic:With语句
With语句其实不算循环语句,不过我看的这个VB教程把With语句放到这里说,那我也放到这里好了。With语句在有些语言中也有,主要用途是节省代码数量。比方说有下面这个Person类。
Public Class Person
Public Property Name As String
Public Property Age As Integer
End Class
假如有一个person对象多次出现的话,就可以使用With语句,在With语
作者:lianhe | 分类:Basic手册 | 浏览:111 | 评论:0
26
2019
09
Basic循环语句
Do语句循环Do语句循环有两种结构,第一种是循环条件在前。先来看看Do-While语句,当满足循环条件的时候会继续循环,不满足条件时跳出循环。这里顺便提一下,VB中没有块注释,只有单行注释,以单引号开头,直到句末。 'Do While语句
Dim i = 0
作者:lianhe | 分类:Basic手册 | 浏览:128 | 评论:0
25
2019
09
Basic条件语句
If语句先来看看VB中的If语句,其基本结构是If 条件 Then 执行体 Else 执行体 End If。 Dim num As Integer = 5
If num\2 = 0 Then
作者:lianhe | 分类:Basic手册 | 浏览:102 | 评论:0