《VisualBasic实验指导书程序代码精.pdf》由会员分享,可在线阅读,更多相关《VisualBasic实验指导书程序代码精.pdf(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、1 2020419 VisualBasic 2 2020 4 19 9-1 Option Explicit Option Base 1 Private Sub Command1_Click(Dim x(10 As Integer,maxv As Integer,minv As Integer Dim i As Integer For i=1 To 10 x(i=Int(90*Rnd+10 Text1.Text=Text1&Str(x(i Next i Call maxmin(x,maxv,minv Text2.Text=maxv Text3.Text=minv End Sub Private
2、Sub Command2_Click(Text1.Text=3 2020 4 19 Text2.Text=Text3.Text=End Sub Private Sub Command3_Click(End End Sub Private Sub maxmin(a(As Integer,max As Integer,min As Integer Dim i As Integer max=a(1:min=a(1 For i=LBound(a+1 To UBound(a If a(i max Then max=a(i ElseIf a(i min Then min=a(i End If Next i
3、 4 2020 4 19 End Sub 9-2 Private Sub Command1_Click(Dim x As Long x=Val(Text1.Text If verify(x Then List1.AddItem x Else MsgBox Str(x&,vbInformation End If End Sub Private Sub Command2_Click(Text1.Text=End Sub Private Sub Command3_Click(End End Sub 5 2020 4 19 Private Function verify(x As Long As Bo
4、olean Dim y As Long,s As Integer verify=False s=Len(CStr(x y=x*x If x=Val(Right(CStr(y,s Then verify=True End If End Function 9-3 Option Explicit Option Base 1 Private Sub Command1_Click(Dim a As Integer,b As Integer,i As Integer a=Val(Text1.Text:b=Val(Text2.Text 6 2020 4 19 For i=a To b If sx(i=Tru
5、e Then List1.AddItem i 8 End If Next i If List1.ListCount=0 Then List1.AddItem End Sub Private Sub Command2_Click(Text1.Text=Text2.Text=List1.Clear Text1.SetFocus End Sub Private Sub Command3_Click(End End Sub 7 2020 4 19 Private Function sx(ByVal n As Integer As Boolean Dim a(As Integer,k As Integer,i As Integer Do k=k+1 ReDim Preserve a(k a(k=n Mod 10 n=n 10 Loop Until n=a(i Then Exit Function Next i