VB编程题.docx
- 文档编号:5104667
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:19
- 大小:1.59MB
VB编程题.docx
《VB编程题.docx》由会员分享,可在线阅读,更多相关《VB编程题.docx(19页珍藏版)》请在冰豆网上搜索。
VB编程题
编程题
⏹PrivateSubCommand1_Click()
⏹'''不得删除本行注释
⏹DimiAsInteger
⏹Fori=1To200
⏹IfiMod3=0AndiMod7=0Then
⏹Text1.Text=Text1.Text+Str(i)
⏹EndIf
⏹Next
⏹EndSub
⏹PrivateSubCommand1_Click()
⏹DimaAsInteger
⏹DimbAsInteger
⏹a=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)
⏹EndSub
⏹PrivateSubCommand1_Click()
⏹Dims
⏹Open"Bdata.txt"ForInputAs#1
⏹DoWhileNotEOF
(1)
⏹LineInput#1,s
⏹Text1.Text=Text1.Text+s&vbCrLf
⏹Loop
⏹Close#1
⏹EndSub
⏹PrivateSubCommand1_Click()
⏹DimaAsString
⏹GetChara
⏹Text1.Text=a
⏹If48<=Asc(a)AndAsc(a)<=57Then
⏹Label1.Caption="是数字字符"
⏹ElseIf(65<=Asc(a)AndAsc(a)<90)Or(97<=Asc(a)AndAsc(a)<=122)Then
⏹Label1.Caption="是字母字符"
⏹Else
⏹Label1.Caption="是其他字符"
⏹EndIf
⏹EndSub
⏹DimaAsString
⏹PrivateSubCommand1_Click()
⏹Text1.Text=UCase(a)
⏹EndSub
⏹PrivateSubCommand2_Click()
⏹Text1.Text=LCase(a)
⏹EndSub
⏹PrivateSubCommand3_Click()
⏹Text1.Text=a
⏹EndSub
⏹PrivateSubText1_KeyPress(KeyAsciiAsInteger)
⏹a=Text1.Text
⏹EndSub
⏹DimsumAsSingle
⏹Open"Jsdata.txt"ForInputAs#1
⏹Fori=1To15
⏹Input#1,Arr(i)
⏹Next
⏹Close#1
⏹IfOp1Then
⏹T1.Text=Aaa
⏹EndIf
⏹IfOp2Then
⏹T1.Text=Bbb
⏹EndIf
⏹EndSub
⏹PrivateSubcommand1_Click()
⏹'''不得删除本行注释
⏹DimaAsInteger,bAsDouble,iAsInteger,nAsInteger
⏹n=Val(Text1.Text)
⏹a=0
⏹b=0
⏹Fori=1Ton
⏹a=a+i
⏹b=b+a
⏹Nexti
⏹Text2.Text=b
⏹EndSub
PrivateSubCommand1_Click()
'''不得删除本行注释
Dimi%,xh$,xm$
OpenApp.Path&"\"&"Xhxm.txt"ForOutputAs#1
Fori=1To3
xh=InputBox("请输入学号")
xm=InputBox("请输入姓名")
Write#1,xh,xm
Nexti
Close#1
EndSub
⏹PrivateSubCommand2_Click()
⏹'''不得删除本行注释
⏹Dimsasstring
⏹OpenApp.Path&"\"&"Xhxm.txt"ForInputAs#2
⏹DoWhileNotEOF
(2)
⏹LineInput#2,s
⏹Text1.Text=Text1.Text&s&vbCrLf
⏹Loop
⏹Close#2
⏹EndSub
PrivateSubCommand1_Click()
DimnAsInteger,iAsInteger,sAsDouble
n=Val(Text1.Text)
s=0
Fori=1Ton
s=s+i^2
Nexti
Text2.Text=s
EndSub
⏹PrivateSubCommand1_Click()
⏹'''不得删除本行注释
⏹DimiAsInteger
⏹OpenApp.Path&"\"&"yssj.txt"ForInputAs#1
⏹Fori=1To10
⏹Input#1,a(i)
⏹Nexti
⏹Close#1
⏹EndSub
⏹PrivateSubCommand2_Click()
⏹'''不得删除本行注释
⏹DimiAsInteger
⏹Text1.Text=""
⏹Fori=1To10
⏹Ifa(i)Mod3=2Then
⏹Text1.Text=Text1.Text&Str(a(i))
⏹EndIf
⏹Nexti
⏹EndSub
PrivateSubCommand1_Click()
‘”读取文件”按钮代码
'''不得删除本行注释
DimstAsString
Text1.Text=""
OpenApp.Path&"\"&“jmwb.txt"ForInputAs#1
WhileNotEOF
(1)
Input#1,st
Text1.Text=Text1.Text+st+vbCrLf
Wend
Close#1
PrivateSubCommand2_Click()
DimsAsString,coAsString,cAsString,
DimnAsInteger,iAsInteger,pAsInteger
s=Trim(Text1.Text)
n=Len(s)
co=""
Fori=1Ton
c=Mid(s,i,1)
p=Asc(c)+5
co=co+Chr(p)
Nexti
Text2.Text=co
EndSub
⏹PrivateSubcommand1_click()
⏹'''不得删除本行注释
⏹ForN=1To15
⏹x(N)=Int(Rnd*91+10)
⏹Text1.Text=Text1.Text+Str(x(N))
⏹NextN
⏹EndSub
⏹PrivateSubCommand2_Click()
⏹'''不得删除本行注释
⏹DimmAsInteger,KAsInteger
⏹ForN=1To15
⏹Form=N+1To15
⏹Ifx(m)>x(N)Then
⏹K=x(N)
⏹x(N)=x(m)
⏹x(m)=K
⏹EndIf
⏹Nextm
⏹Text2.Text=Text2.Text+Str(x(N))
⏹NextN
⏹EndSub
PrivateSubcommand1_Click()
'''不得删除本行注释
DimaAsInteger,bAsInteger,cAsInteger
DimmaxAsInteger,minAsInteger
a=Val(Text1.Text)
b=Val(Text2.Text)
c=Val(Text3.Text)
max=a+b+Abs(a-b)
max=max/2
min=a+b-Abs(a-b)
min=min/2
max=max+c+Abs(max-c)
max=max/2
min=min+c-Abs(min-c)
min=min/2
Text4.Text=max
Text5.Text=min
EndSub
PrivateSubCommand1_Click()
DimmAsInteger,nAsInteger,cAsDouble
m=Val(text2.Text)
n=Val(text1.Text)
Ifm MsgBox("m应大于等于n! ") ExitSub EndIf c=fact(m)/(fact(n)*fact(m-n)) text3.Text=Str(c) EndSub Functionfact(nAsInteger)AsDouble DimiAsInteger,fAsDouble f=1Fori=1Ton f=f*i Nexti fact=f EndFunction PrivateSubCommand1_Click() DimaAsInteger a=Val(Text1.Text) If(aMod4=0AndaMod100<>0)OraMod400=0Then Text2.Text="闰年" Else: Text2.Text="非闰年" EndIf EndSub PrivateSubText1_Change() IfNotIsNumeric(Text1.Text)Then MsgBox"请输入数字! ",48,"输入的不是数字" Command1.Enabled=False Text1.SetFocus Text1.SelStart=0 Text1.SelLength=Len(Text1.Text) Else: Command1.Enabled=True EndIf ⏹PrivateSubCommand1_Click() ⏹'''不得删除本行注释 ⏹DimnAsInteger,iAsInteger ⏹n=Val(Text1.Text) ⏹Ifn<0Or(NotIsNumeric(Text1.Text))ThenMsgBox"请输入正整数",48,"输入的不是正整数" ⏹OpenApp.Path&"\"&"jfwj.txt"ForOutputAs#1 ⏹Fori=1Ton ⏹Print#1,String(i,"*") ⏹Nexti ⏹Close#1 ⏹EndSub PrivateSubCommand1_Click() '''不得删除本行注释 DimaAsInteger a=Val(Text1.Text) Text2.Text=zh(a) ‘zh过程在原本的程序代码中已经有了~直接可用 EndSub ⏹PrivateSubCommand1_Click() ⏹DimxAsDouble ⏹DimyAsDouble ⏹x=Val(Text1.Text) ⏹Ifx<10Then ⏹y=x-1 ⏹ElseIfx<20Then ⏹y=2*x-1 ⏹Else ⏹y=3*x-1 ⏹EndIf ⏹Text2.Text=y ⏹EndSub ⏹PrivateSubCommand1_Click() ⏹'''不得删除本行注释 ⏹Text1.Text="" ⏹OpenApp.Path&"\"&"zfwj.txt"ForInputAs#1 ⏹Fori=1To10 ⏹Input#1,a(i) ⏹Text1.Text=Text1.Text&""&a(i) ⏹Nexti ⏹Close#1 ⏹EndSub ⏹PrivateSubCommand2_Click() ⏹'''不得删除本行注释 ⏹DimtAsString ⏹Text2.Text="" ⏹Fori=1To10 ⏹t=a(i) ⏹a(i)=a(10-i+1) ⏹a(10-i+1)=t ⏹Text2.Text=Text2.Text&""&a(i) ⏹Nexti ⏹EndSub PrivateSubCommand1_Click() '''不得删改本行注释 DimnAsInteger n=Val(Text1.Text) Ifn<100Orn>999Then MsgBox"请输入三位正整数",,"输入出错" Else: Text2.Text=Int(nMod10) Text3.Text=Int((nMod100)/10) Text4.Text=Int(n/100) EndIf EndSub ⏹DimiAsInteger ⏹PrivateSubCommand1_Click() ⏹Fori=1To10 ⏹List1.AddItemInt((Rnd()*90)+10) ⏹Next ⏹EndSub ⏹PrivateSubCommand2_Click() ⏹Fori=List1.ListCount-1To0Step-1 ⏹IfList1.List(i)Mod2<>0Then ⏹List2.AddItemList1.List(i) ⏹List1.RemoveItemi ⏹EndIf ⏹Next EndSub PrivateSubCommand3_Click()’清除按钮的代码 List1.Clear List2.Clear EndSub PrivateSubCommand1_Click() ‘”读入数据”按钮代码 '''不得删除本行注释 DimstAsString Text1.Text="" OpenApp.Path&"\"&"yy.txt"ForInputAs#1 WhileNotEOF (1) Input#1,st Text1.Text=Text1.Text+st+vbCrLf Wend Close#1 EndSub PrivateSubCommand2_Click() '''不得删除本行注释 DimxAsString,yAsString*1,nAsInteger,iAsInteger,pAsInteger x=Trim(Text1.Text) n=Len(x) p=0 Fori=1Ton y=UCase(Mid(x,i,1)) Ify>="A"Andy<="Z"Then p=p+1 EndIf Nexti Label1.Caption="共"&p&"个字母" EndSub PrivateSubCommand1_Click() '''不得删除本行注释 DimnAsInteger,kAsInteger,iAsInteger Forn=200To300 k=Int(Sqr(n)) Fori=2Tok IfnModi=0ThenExitFor Nexti Ifi>kThenList1.AddItemn Nextn EndSub ⏹PrivateSubCommand1_Click() ⏹'''不得删除本行注释 ⏹DimiAsInteger,nAsInteger,sAsInteger ⏹n=Val(Text1.Text) ⏹Ifn<0Or(NotIsNumeric(Text1.Text))ThenMsgBox"请输入正整数",48,"输入的不是正整数" ⏹s=0 ⏹Fori=1Ton ⏹IfiMod3=0Then ⏹s=s+i ⏹EndIf ⏹Nexti ⏹Text2.Text=s ⏹EndSub
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 编程