vb語言程序設(shè)計(jì)簡介
以vb程序設(shè)計(jì)語言為工具,對特定的問題進(jìn)行分析,并設(shè)計(jì)出解題的算法,根據(jù)得到的算法,用vb語言編寫出源程序的過程就是vb程序設(shè)計(jì)。
編寫計(jì)算機(jī)程序需要使用計(jì)算機(jī)編程語言。計(jì)算機(jī)編程語言是人和計(jì)算機(jī)“對話”的橋梁。就像人類的語言一樣,計(jì)算機(jī)編程語言也有很多。目前較為廣泛使用的語言有“C++”、“Pascal”、“Basic”等。在眾多的計(jì)算機(jī)編程語言中,以BASIC語言最為易學(xué)易用。
BASIC是英文Beginner’s All purpose Symbolic Instruction Code的縮寫,意思為初學(xué)者通用符號(hào)指令代碼,一直都是程序設(shè)計(jì)入門的首選語言。
1991年,Visual Basic(簡稱VB)面世,他是第三代BASIC語言,它不但秉承了BASIC語言的易學(xué)易用的優(yōu)點(diǎn),而且增加了圖形界面設(shè)計(jì)工具。它簡化了復(fù)雜的窗口程序編寫過程,讓編程者將更多的精力致力于問題的求解過程。
vb語言程序設(shè)計(jì)實(shí)例(一)
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 “最大公約數(shù)是” & 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
vb語言程序設(shè)計(jì)實(shí)例(二)
Dim a() As Integer, i%, j%, n%, t% Private Sub Command1_Click() Picture1.Print “排序前的數(shù)組為:” n = Val(InputBox(“請輸入一個(gè) 3 到 100 的整數(shù)”)) 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 “排序后的數(shù)組為:” 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
vb語言程序設(shè)計(jì)實(shí)例(三)
Dim a(), i%, j% Private Sub Command1_Click() Dim n% n = Val(InputBox(“請輸入一個(gè)整數(shù)”)) Randomize ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 100) + 1 Next i Picture1.Print “選擇法排序后的數(shù)組為:” 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(“請輸入一個(gè)整數(shù)”)) Randomize ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 100) + 1 Next i Picture2.Print “冒泡排序法后的數(shù)組為:” 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
vb語言程序設(shè)計(jì)實(shí)例(四)
Dim a(), i%, j%, n%, m%, t% Private Sub Command1_Click() n = Val(InputBox(“請輸入一個(gè)整數(shù)”)) Call fuzhi(n) Picture1.Print “選擇排序法后的數(shù)組為:” Call paixu(n) Picture1.Print ReDim Preserve a(n) End Sub Private Sub Command2_Click() m = Val(InputBox(“請輸入一個(gè)整數(shù)”)) Call fuzhi(m) Picture1.Print “冒泡排序法后的數(shù)組為:” 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 “合并后的數(shù)組為:” Call paixu(t)
Picture1.Print End Sub Public Sub fuzhi(n%) Randomize ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 100) + 1 Next i End Sub Public Function paixu(n%) As Integer 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 Function
vb語言程序設(shè)計(jì)實(shí)例(五)
Dim i%, j%, s% Private Sub Command1_Click() Picture1.Cls Picture1.Scale (0, 0)-(10, 10) For i = 1 To 9 Picture1.Line (1, i)-(9, i) Picture1.Line (i, 1)-(i, 9) Next Picture1.FillColor = QBColor(0) Picture1.Circle (4.5, 4.5), 0.4 Picture1.Circle (5.5, 5.5), 0.4 Picture1.FillColor = QBColor(15) Picture1.Circle (4.5, 5.5), 0.4
Picture1.Circle (5.5, 4.5), 0.4 End Sub Private Sub Command2_Click() s = Abs(s - 1) End Sub Private Sub picture1_mousedown(botton As Integer, shift As Integer, x!, y!) i = Fix(x) j = Fix(y) If s = 0 Then Picture1.FillColor = QBColor(0) If s = 1 Then Picture1.FillColor = QBColor(15) Picture1.Circle (i + 0.5, j + 0.5), 0.4 s = Abs(s - 1) End Sub
-
VB語言
+關(guān)注
關(guān)注
1文章
18瀏覽量
9710
發(fā)布評論請先 登錄
相關(guān)推薦
評論