1、建立应用程序界面
2、设置对象的属性
3、编写应用程序的代码
4、保存和运行程序
VB拥有图形用户界面(GUI)和快速应用程序开发(RAD)系统,可以轻易的使用DAO、RDO、ADO连接数据库,或者轻松的创建Active X控件,用于高效生成类型安全和面向对象的应用程序。程序员可以轻松的使用VB提供的组件快速建立一个应用程序。
扩展资料
VB语言缺点
Visual Basic 语言具有不支持继承、无原生支持多线程、异常处理不完善等三项明显缺点,使其有所局限性(此些缺点皆已在 vb .net 获得改进)。
1、不支持继承
VB 5.0 和 VB 6.0 都是基于对象的编程语言,但是不包含继承特性。VB 中提供了特殊的类的功能,但是还是不能满足程序员的需求。
2、无原生支持多线程
Visual Basic 对于多线程无原生支持,只能通过Windows API的调用实现,且极其的不稳定。因为在API创建的线程中,并没有自动初始化运行时库,导致部分的函数无法使用。一般的,在VB6等早期的VB开发环境下,使用API创建线程的目的是完成容易使程序假死的大量数据或者逻辑的计算。
3、异常处理不完善
Visual Basic 中内置异常处理,即使未写异常处理代码,一旦用户出错也会d出一个明确写出出错原因对话框,接着程序终止。
Visual Basic 中可以使用 Err.Raise抛出异常。对系统及用户抛出的异常的处理常用两种模式:一是使用 On Error Resume Next 处理错误;另一种是使用 On Error Goto 将运行引入错误处理代码。但相对 C++ 等语言而言,这样的异常处理破坏了代码的结构。
VB6.0测试通过'利用随机函数产生60个100~200之间的随机整数,将其中的偶数按由小到大的顺序排列并输出,将奇数按由大到小的顺序排列并输出。
'1.将随机产生的60个整数按每行10个数输出到窗体或文本框中。
'2.将排好序的偶数和奇数分别输出到两个文本框中。
Dim RndArray(6, 10) As Integer
Dim OddArray() As Integer
Dim EvenArray() As Integer
Dim i, j As Integer
Dim m, n As Integer
Private Sub Cmd_Exit_Click()
'销毁数组
Unload Me
End Sub
Private Sub Cmd_Start_Click()
'除数化
Me.Txt(0).Text = ""
Me.Txt(1).Text = ""
Me.Txt(2).Text = ""
ReDim OddArray(60)
ReDim EvenArray(60)
For i = 0 To 5 Step 1
For j = 0 To 9 Step 1
RndArray(i, j) = RndNuN(100, 200)
Next j
Next i
For i = 0 To 5 Step 1
For j = 0 To 8 Step 1
Me.Txt(0).Text = Me.Txt(0).Text + Trim(Str(RndArray(i, j))) + ","
Next j
Me.Txt(0).Text = Me.Txt(0).Text + Trim(Str(RndArray(i, j))) + vbCrLf
Next i
m = 0
n = 0
For i = 0 To 5 Step 1
For j = 0 To 9 Step 1
If RndArray(i, j) Mod 2 Then
OddArray(m) = RndArray(i, j)
m = m + 1
Else
EvenArray(n) = RndArray(i, j)
n = n + 1
End If
Next j
Next i
ReDim Preserve OddArray(m)
ReDim Preserve EvenArray(n)
DwComp OddArray(), m
UpComp EvenArray(), n
m = m - 1
n = n - 1
For i = 0 To m Step 1
Me.Txt(1) = Me.Txt(1) + Trim(Str(OddArray(i))) + ","
Next i
For i = 0 To n Step 1
Me.Txt(2) = Me.Txt(2) + Trim(Str(EvenArray(i))) + ","
Next i
End Sub
Public Function RndNuN(ByVal Min As Integer, ByVal Max As Integer)
RndNuN = Min + (Max - Min) * Rnd
End Function
Public Function UpComp(ByRef parray() As Integer, ByVal num As Integer)
Dim temp As Integer
num = num - 2
For i = 0 To num Step 1
For j = 0 To num Step 1
If parray(j) >parray(j + 1) Then
temp = parray(j)
parray(j) = parray(j + 1)
parray(j + 1) = temp
End If
Next j
Next i
End Function
Public Function DwComp(ByRef parray() As Integer, ByVal num As Integer)
Dim temp As Integer
num = num - 2
For i = 0 To num Step 1
For j = 0 To num Step 1
If parray(j) <parray(j + 1) Then
temp = parray(j)
parray(j) = parray(j + 1)
parray(j + 1) = temp
End If
Next j
Next i
End Function
'利用随机函数产生100个10~99之间的随机整数,找出其中的素数,并将这些素数求和。
'1. 将随机产生的100个整数存入数组,按每行10个数输出到窗体或文本框中。
'2. 用Sub子过程或Function函数过程判断随机整数是否为素数。
'3. 将素数按每行10个数在窗体或文本框中输出。
'4. 将素数的个数以及求和结果出到窗体或文本框中。
Dim RndArray(10, 10) As Integer
Dim PrimArray() As Integer
Dim i, j As Integer
Dim m, n As Integer
Dim num As Integer
Dim sum As Integer
Private Sub Cmd_Click(Index As Integer)
If Index Then
Unload Me
Else
'初始化
Me.Txt(0).Text = ""
Me.Txt(1).Text = ""
Me.Txt(2).Text = ""
Me.Txt(3).Text = ""
For i = 0 To 9 Step 1
For j = 0 To 9 Step 1
RndArray(i, j) = RndNuN(10, 99)
Next j
Next i
For i = 0 To 9 Step 1
For j = 0 To 8 Step 1
Me.Txt(0).Text = Me.Txt(0).Text + Trim(Str(RndArray(i, j))) + ","
Next j
Me.Txt(0).Text = Me.Txt(0).Text + Trim(Str(RndArray(i, j))) + vbCrLf
Next i
m = 0
n = 0
num = 0
sum = 0
ReDim PrimArray(10, 10)
For i = 0 To 9 Step 1
For j = 0 To 9 Step 1
If IsPrime(RndArray(i, j)) Then
PrimArray(m, n) = RndArray(i, j)
Me.Txt(1).Text = Me.Txt(1).Text + Trim(Str(PrimArray(m, n))) + ","
sum = sum + PrimArray(m, n)
n = n + 1
If n >9 Then
m = m + 1
n = 0
End If
num = num + 1
End If
Next j
Next i
Me.Txt(2).Text = Trim(Str(num))
Me.Txt(3).Text = Trim(Str(sum))
End If
End Sub
Public Function RndNuN(ByVal Min As Integer, ByVal Max As Integer)
RndNuN = Min + (Max - Min) * Rnd
End Function
Public Function IsPrime(ByVal n As Integer) As Boolean
Dim a, b As Integer
IsPrime = False
If n Mod 2 Then
b = Sqr(n)
For a = 3 To b Step 2
If n Mod a = 0 Then
Exit Function
End If
Next a
IsPrime = True
End If
End Function
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)