VisualBasic试验参考指导书程序代码精.doc

上传人:知**** 文档编号:97938911 上传时间:2024-07-08 格式:DOC 页数:25 大小:40.54KB
返回 下载 相关 举报
VisualBasic试验参考指导书程序代码精.doc_第1页
第1页 / 共25页
VisualBasic试验参考指导书程序代码精.doc_第2页
第2页 / 共25页
点击查看更多>>
资源描述

《VisualBasic试验参考指导书程序代码精.doc》由会员分享,可在线阅读,更多相关《VisualBasic试验参考指导书程序代码精.doc(25页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、9-1Option ExplicitOption Base 1Private Sub Command1_Click(Dim x(10 As Integer, maxv As Integer, minv As IntegerDim i As IntegerFor i = 1 To 10x(i = Int(90 * Rnd + 10Text1.Text = Text1 & Str(x(iNext iCall maxmin(x, maxv, minvText2.Text = maxvText3.Text = minvEnd SubPrivate Sub Command2_Click(Text1.Te

2、xt = Text2.Text = Text3.Text = End SubPrivate Sub Command3_Click(EndEnd SubPrivate Sub maxmin(a( As Integer, max As Integer, min As Integer Dim i As Integermax = a(1: min = a(1For i = LBound(a + 1 To UBound(aIf a(i max Thenmax = a(iElseIf a(i min Thenmin = a(iEnd IfNext iEnd Sub9-2Private Sub Comman

3、d1_Click(Dim x As Longx = Val(Text1.TextIf verify(x ThenList1.AddItem xElseMsgBox Str(x & 不是自守数。, vbInformation End IfEnd SubPrivate Sub Command2_Click(Text1.Text = End SubPrivate Sub Command3_Click(EndEnd SubPrivate Function verify(x As Long As BooleanDim y As Long, s As Integerverify = Falses = Le

4、n(CStr(xy = x * xIf x = Val(Right(CStr(y, s Thenverify = TrueEnd IfEnd Function9-3Option ExplicitOption Base 1Private Sub Command1_Click(Dim a As Integer, b As Integer, i As Integera = Val(Text1.Text:b = Val(Text2.TextFor i = a To bIf sx(i = True ThenList1.AddItem i8 End IfNext iIf List1.ListCount =

5、 0 Then List1.AddItem 无升序数 End SubPrivate Sub Command2_Click(Text1.Text = Text2.Text = List1.ClearText1.SetFocusEnd SubPrivate Sub Command3_Click(EndEnd SubPrivate Function sx(ByVal n As Integer As Boolean Dim a( As Integer, k As Integer, i As IntegerDok = k + 1ReDim Preserve a(ka(k = n Mod 10n = n

6、10Loop Until n = a(i Then Exit FunctionNext isx = TrueEnd Function9-4Option ExplicitPrivate Sub Command1_Click(Text1.Text = Text2.Text = Text3.Text = End SubPrivate Sub Command2_Click(EndEnd SubPrivate Function common(ByVal a As Integer, ByVal b As Integer As Integer Dim r As IntegerDor = a Mod ba =

7、 bb = rLoop While r 0common = aEnd FunctionPrivate Sub Option1_Click(Index As IntegerDim a As Integer, b As IntegerDim m As Integer, d As Integera = Text1b = Text2m = common(a, bIf Index = 0 ThenText3 = mElsed = a * b / mText3 = dEnd IfEnd Sub9-5Option ExplicitPrivate Function Judge(n As Integer As

8、BooleanDim i As IntegerFor i = 2 To Sqr(nIf n Mod i = 0 Then Exit FunctionNext iJudge = TrueEnd FunctionPrivate Sub Command1_Click(Dim x As Integer, i As Integerx = Text1.TextIf x = 4 ThenText2 = 2+2Elsei = 3Do While Text2 = If Judge(i And Judge(x - i ThenText2 = i & + & x - iElsei = i + 2End IfLoop

9、End IfEnd SubPrivate Sub Command2_Click(Text1.Text = Text2.Text = End SubPrivate Sub Command3_Click(EndEnd Sub9-6Private Function change(s As String, n As Integer As String Dim i As Integer, k As Integer, sum As IntegerDim p As String * 1, q As Integerk = 0For i = Len(CStr(Text2.Text To 1 Step -1p =

10、 Mid(CStr(Text2.Text, i, 1If p = 0 And p = Len(Text1.Textnx = Val(stEnd Function9-8Private Sub Command1_Click(Dim n As Integer, i As Integer, s As String, a( As IntegerFor n = 153 To 9999If arm(n = True ThenReDim a(Len(CStr(nFor i = 1 To Len(CStr(na(i = Mid(CStr(n, i, 1Next is = For i = 1 To Len(CSt

11、r(n - 1s = s & CStr(a(i & & CStr(Len(CStr(n & +Next iList1.AddItem CStr(n & = & s & CStr(a(i & & CStr(Len(CStr(n End IfNext nEnd SubEndEnd SubPrivate Function arm(n As Integer As BooleanDim a( As Integer, i As Integer, st As String, sum As Integerarm = Falsest = CStr(nReDim a(Len(stFor i = 1 To Len(

12、sta(i = Mid(st, i, 1Next iFor i = 1 To Len(stsum = Val(a(i (Len(st + sumNext iIf n = sum Thenarm = TrueElseExit FunctionEnd IfEnd Function9-9Dim sco(5 As SinglePrivate Sub Command1_Click(Dim i As IntegerFor i = 0 To 5sco(i = (Int(Rnd * 61 + 40 / 10Text1(i.Text = sco(iNext iEnd SubPrivate Sub Command

13、2_Click(Dim i As Integer, sum As Integer, min As Single, max As Single Call a(min, maxFor i = 0 To 5sum = sum + sco(iNext iText7.Text = (sum - min - max / 4End SubPrivate Sub a(min As Single, max As SingleDim i As Integer, k As Integermax = sco(0: min = sco(0For i = 1 To 5If sco(i max Thenmax = sco(

14、iElseIf sco(i min Thenmin = sco(iEnd IfNext iEnd SubFor i = 0 To 5Text1(i = Next iText7.Text = End SubPrivate Sub Command4_Click(EndEnd Sub9-10Private Sub Command1_Click(Dim max As Long, min As LongCall at(max, minText2.Text = maxText3.Text = minEnd SubPrivate Sub Command2_Click(Text1.Text = Text2.T

15、ext = Text3.Text = End SubPrivate Sub Command3_Click(EndEnd SubPrivate Sub at(max As Long, min As LongDim s As String, i As Integer, a( As Integer, k As Integer, temp As Integer, st As String, st1 As String s = CStr(Text1.TextReDim a(Len(sFor i = 1 To Len(sk = k + 1a(k = Val(Mid(s, i, 1Next imax = a

16、(1: min = a(1For i = 1 To Len(sFor j = 1 To Len(sIf a(i a(j Thentemp = a(ia(i = a(ja(j = tempEnd IfNext jNext iIf a(1 = 0 ThenFor i = 2 To Len(sIf a(i 0 Then Exit ForNext itemp = a(ia(i = a(1a(1 = tempEnd IfFor i = 1 To Len(sst = st & a(iNext imin = Val(stFor i = 1 To Len(sFor j = 1 To Len(sIf a(i a

17、(j Thentemp = a(ia(i = a(ja(j = tempEnd IfNext jNext iFor i = 1 To Len(sst1 = st1 & a(iNext imax = Val(st1End Sub7-2Option ExplicitOption Base 1Private Sub Command1_Click(Dim a(20 As Integer, i As Integer, st As StringDim max As Integer, min As Integer, maxp As Integer, minp As Integer For i = 1 To

18、20a(i = Int(Rnd * (100 - 1 + 1 + 1st = st & Str(a(iIf i Mod 10 = 0 Then st = st & vbCrLfNext iText1.Text = stmax = a(1: min = a(1maxp = 1: minp = 1For i = 2 To 20If a(i max Thenmax = a(imaxp = iElseIf a(i min Thenmin = a(iminp = iEnd IfNext iText2.Text = max & 位置是 & maxpText3.Text = min & 位置是 & minp

19、End SubPrivate Sub Command2_Click(Text1.Text = Text2.Text = : Text3.Text = End SubPrivate Sub Command3_Click(EndEnd Sub7-5Private Sub cmdExit_Click(Unload MeEnd SubPrivate Sub cmdJudge_Click(Dim m As Integer, i As Integer, j As Integer, sum As Integer Dim a(m = Text1.TextFor i = 1 To m / 2If m Mod i

20、 = 0 Thensum = sum + ij = j + 1ReDim Preserve a(ja(j = iEnd IfNext iIf m = sum ThenPicture1.Print m & 是完数,因为Picture1.Print m; =;For i = 1 To UBound(a - 1Picture1.Print a(i; +;Next iPicture1.Print a(iElsePicture1.Print m & 不是完数End IfEnd SubPrivate Sub cmdNext_Click(Picture1.ClsText1.Text = Text1.SetF

21、ocusEnd Sub7-6Option ExplicitOption Base 1Private Sub Command1_Click(Dim fn( As Integer, i As Integer, k As IntegerDim j As Integer, st As StringFor i = 10 To 50k = 0For j = 1 To i - 1If i Mod j = 0 Thenk = k + 1ReDim Preserve fn(kfn(k = jEnd IfNext jIf UBound(fn = 3 Thenst = i & :For j = 1 To UBoun

22、d(fn - 1st = st & fn(j & ,Next jList1.AddItem st & fn(jEnd IfNext iEnd SubPrivate Sub Command2_Click(List1.ClearEnd Sub7-7Private Sub Command1_Click(Dim word( As String, S As StringDim n As Integer, k As Integer, maxw As String S = Text1.TextDon = InStr(S, If n 0 Thenk = k + 1ReDim Preserve word(kwo

23、rd(k = Left(S, n - 1List1.AddItem word(kS = Right(S, Len(S - nEnd IfLoop Until n = 0ReDim Preserve word(k + 1word(k + 1 = Left(S, Len(S - 1List1.AddItem word(k + 1maxw = word(k + 1For n = 2 To UBound(wordIf Len(word(n Len(maxw Thenmaxw = word(nEnd IfNext nText2.Text = maxwEnd SubPrivate Sub Command2

24、_Click(Text1.Text = Text2.Text = List1.ClearText1.SetFocusEnd SubPrivate Sub Command3_Click( End End Sub 7-9 Option Base 1 Private Sub Command1_Click( Dim rndArray(10 As Integer Dim i As Integer, j As Integer, temp As Integer Randomize Picture1.Print 排序前: For i = 1 To 10 rndArray(i = Int(90 * Rnd +

25、10 Picture1.Print rndArray(i; Next i For i = 1 To 9 For j = 1 To 9 If rndArray(j rndArray(j + 1 Then temp = rndArray(j rndArray(j = rndArray(j + 1: rndArray(j + 1 = temp End If Next j Next i Picture1.Print Picture1.Print 排序后: For i = 1 To 10 Picture1.Print rndArray(i; Next i Picture1.Print End Sub Private Sub Command2_Click( Picture1.Cls End Sub Private Sub Command3_Click( End End Sub

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 其他杂项

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁