vb程序设计的几个简单例子
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Option Explicit
Private Sub Command1_Click()
Dim i%, j%, r!
i = Val(Text1.Text)
j = Val(Text2.Text)
Picture1.Print i; j;
Call gysh(i, j)
Picture1.Print "最大公约数是" & i
r = Val(InputBox("输入半径"))
Call S(r)
End Sub
Public Function gysh(m As Integer, n As Integer) As Integer Dim t%
Do
t = m Mod n: m = n: n = t
Loop While t <> 0
End Function
Public function S(r!)
Const pi = 3.1415926
S = pi * r ^ 2
MsgBox "圆面积为:" & S
End function
Public Function 定积分()
End Function
Dim a() As Integer, i%, j%, n%, t%
Private Sub Command1_Click()
Picture1.Print "排序前的数组为:"
n = V al(InputBox("请输入一个3到100的整数")) ReDim a(1 To n)
Randomize
For i = 1 To n
a(i) = Int(Rnd * 100) + 1
Picture1.Print Tab(((i - 1) Mod 5) * 6); a(i);
Next i
End Sub
Private Sub Command2_Click()
Picture1.Print
Picture1.Print "排序后的数组为:"
For i = 1 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
For i = 1 To n
Picture1.Print Tab(((i - 1) Mod 5) * 6); a(i);
Next
End Sub
Dim a(), i%, j%
Private Sub Command1_Click()
Dim n%
n = Val(InputBox("请输入一个整数")) Randomize
ReDim a(n)
For i = 1 To n
a(i) = Int(Rnd * 100) + 1
Next i
Picture1.Print "选择法排序后的数组为:" For i = 1 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next
Next
For i = 1 To n
Picture1.Print Tab(((i - 1) Mod 5) * 6); a(i); Next
Picture1.Print
End Sub
Private Sub Command2_Click()
Dim n%
n = Val(InputBox("请输入一个整数")) Randomize
ReDim a(n)
For i = 1 To n
a(i) = Int(Rnd * 100) + 1
Next i
Picture2.Print "冒泡排序法后的数组为:" For i = 1 To n-1
For j = n To i-1 Step -1
If a(j-1) > a(j) Then
t = a(j): a(j) = a(j-1): a(j-1) = t
End If
Next
Next
For i = 1 To n
Picture2.Print Tab(((i - 1) Mod 5) * 6); a(i); Next
Picture2.Print
End Sub
4
Dim a(), i%, j%, n%, m%, t%
Private Sub Command1_Click()
n = Val(InputBox("请输入一个整数")) Call fuzhi(n)
Picture1.Print "选择排序法后的数组为:" Call paixu(n)
Picture1.Print
ReDim Preserve a(n)
End Sub
Private Sub Command2_Click()
m = Val(InputBox("请输入一个整数")) Call fuzhi(m)
Picture1.Print "冒泡排序法后的数组为:" For i = 1 To m - 1
For j = m To i + 1 Step -1
If a(j - 1) > a(j) Then
t = a(j - 1): a(j - 1) = a(j): a(j) = t
End If
Next
Next
For i = 1 To m
Picture1.Print Tab(((i - 1) Mod 5) * 6); a(i); Next
Picture1.Print
End Sub
Private Sub Command3_Click()
ReDim a(t)
Picture1.Print "合并后的数组为:"
Call paixu(t)