《VB 编程题汇编.ppt》由会员分享,可在线阅读,更多相关《VB 编程题汇编.ppt(47页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、VB 编程题汇编Private Sub command1_Click()不得删除本行注释Dim a As Integer,b As Double,i As Integer,n As Integern=Val(Text1.Text)a=0b=0For i=1 To na=a+ib=b+aNext iText2.Text=bEnd Sub Private Sub Command1_Click()不得删除本行注释Dim i%,xh$,xm$Open App.Path&Xhxm.txt For Output As#1For i=1 To 3 xh=InputBox(请输入学号)xm=InputBox(
2、请输入姓名)Write#1,xh,xm Next iClose#1End SubPrivate Sub Command2_Click()不得删除本行注释Dim s as stringOpen App.Path&Xhxm.txt For Input As#2Do While Not EOF(2)Line Input#2,sText1.Text=Text1.Text&s&vbCrLfLoopClose#2End SubPrivate Sub Command1_Click()Dim n As Integer,i As Integer,s As Doublen=Val(Text1.Text)s=0Fo
3、r i=1 To n s=s+i 2Next iText2.Text=sEnd SubPrivate Sub Command1_Click()”读取文件”按钮代码不得删除本行注释Dim st As StringText1.Text=Open App.Path&“jmwb.txt For Input As#1While Not EOF(1)Input#1,stText1.Text=Text1.Text+st+vbCrLfWendClose#1End SubPrivate Sub Command2_Click()Dim s As String,co As String,c As String,Di
4、m n As Integer,i As Integer,p As Integers=Trim(Text1.Text)n=Len(s)co=For i=1 To n c=Mid(s,i,1)p=Asc(c)+5 co=co+Chr(p)Next iText2.Text=coEnd SubPrivate Sub Command1_Click()Dim char As String*1char=Trim(Text1.Text)If Not IsNumeric(char)Then If(Asc(char)=65 And Asc(char)=97 And Asc(char)=120)Then Label
5、1.Caption=输入的是字母 Else:Label1.Caption=输入的是其它符号 End IfElse:Label1.Caption=输入的是数字End IfEnd Sub课本有完整代码课本有完整代码Private Sub Command1_Click()Text1.Text=UCase(Text1.Tag)End SubPrivate Sub Command2_Click()Text1.Text=LCase(Text1.Tag)End SubPrivate Sub Command3_Click()Text1.Text=Text1.TagEnd SubPrivate Sub Text
6、1_KeyUp(KeyCode As Integer,Shift As Integer)对于文本框控件中输入的每次键盘按键弹起事件做一次文本内容保存Text1.Tag=Text1.Text用Text1.Tag属性作为保存textbox控件文本内容的临时存储区End SubPrivate Sub command1_Click()不得删除本行注释不得删除本行注释Dim a As Integer,b As Integer,c As IntegerDim max As Integer,min As Integera=Val(Text1.Text)b=Val(Text2.Text)c=Val(Text3
7、.Text)max=a+b+Abs(a-b)max=max/2min=a+b-Abs(a-b)min=min/2max=max+c+Abs(max-c)max=max/2min=min+c-Abs(min-c)min=min/2Text4.Text=maxText5.Text=minEnd Sub课本有完整代码课本有完整代码Private Sub Command1_Click()Dim a As Integera=Val(Text1.Text)If(a Mod 4=0 And a Mod 100 0)Or a Mod 400=0 Then Text2.Text=闰年Else:Text2.Tex
8、t=非闰年End IfText1.SetFocusText1.SelStart=0Text1.SelLength=Len(Text1.Text)End SubPrivate Sub Text1_Change()If Not IsNumeric(Text1.Text)ThenMsgBox 请输入数字!,48,输入的不是数字Command1.Enabled=FalseText1.SetFocusText1.SelStart=0Text1.SelLength=Len(Text1.Text)Else:Command1.Enabled=TrueEnd IfPrivate Sub Command1_Cli
9、ck()Dim i As IntegerOpen zfwj.txt For Output As#1For i=0 To Val(Text1.Text)Print#1,String(i+1,*)Next iClose#1End SubPrivate Sub Command1_Click()不得删除本行注释Dim i As IntegerFor i=1 To 200If i Mod 3=0 And i Mod 7=0 ThenText1.Text=Text1.Text+Str(i)End IfNextEnd SubPrivate Sub Command1_Click()不得删除本行注释Dim su
10、m As Single,i As IntegerOpen App.Path&Jsdata.txt For Input As#1For i=1 To 15 Input#1,Arr(i)Next iClose#1If Op1 Then T1.Text=AaaEnd IfIf Op2 Then T1.Text=BbbEnd IfEnd SubPrivate Sub Command1_Click()不得删除本行注释Dim a As Integera=Val(Text1.Text)Text2.Text=zh(a)zh过程在原本的程序代码中已经有了直接可用End Sub课本有完整代码课本有完整代码Priv
11、ate Sub Command1_Click()Dim a As IntegerDim b As Integera=Val(Text1.Text)b=Val(Text2.Text)Label1.Caption=Int(Rnd()*(b-a+1)+a)Label2.Caption=Int(Rnd()*(b-a+1)+a)Label3.Caption=Int(Rnd()*(b-a+1)+a)End SubPrivate Sub Command1_Click()Dim s as stringOpen App.Path&Bdata.txt For Input As#1Do While Not EOF(
12、1)Line Input#1,sText1.Text=Text1.Text+s+Chr(13)+Chr(10)LoopClose#1End Subchr(13)是软回车chr(10)换行 用常量vbcrlf代替即可 Private Sub Command1_Click()不得删改本行注释Dim n As Integern=Val(Text1.Text)If n 999 Then MsgBox 请输入三位正整数,输入出错Else:Text2.Text=Int(n Mod 10)Text3.Text=Int(n Mod 100)/10)Text4.Text=Int(n/100)End IfEnd
13、SubPrivate Sub Command1_Click()产生按钮的代码i=List1.ListIndexFor i=0 To 9 List1.AddItem Int(90*Rnd+10)Next iEnd SubPrivate Sub Command3_Click()清除按钮的代码List1.ClearList2.ClearEnd SubPrivate Sub Command2_Click()不得删改本行注释Dim n As Doublei=List1.ListIndexFor i=0 To List1.ListCount-1 n=Val(List1.List(i)If n Mod 2=
14、1 Then List2.AddItem n List1.RemoveItem I 代码有误 End If Next iEnd SubPrivate Sub Command1_Click()”读入数据”按钮代码不得删除本行注释Dim st As StringText1.Text=Open App.Path&yy.txt For Input As#1While Not EOF(1)Input#1,stText1.Text=Text1.Text+st+vbCrLfWendClose#1End SubPrivate Sub Command2_Click()不得删除本行注释Dim x As String,y As String*1,n As Integer,i As Integer,p As Integerx=Trim(Text1.Text)n=Len(x)p=0For i=1 To n y=UCase(Mid(x,i,1)If y=A And y k Then List1.AddItem nNext nEnd Sub