VB试验答案.docx
《VB试验答案.docx》由会员分享,可在线阅读,更多相关《VB试验答案.docx(111页珍藏版)》请在冰豆网上搜索。
![VB试验答案.docx](https://file1.bdocx.com/fileroot1/2023-1/12/d8e194e6-6ca1-4440-a2ab-9622106022af/d8e194e6-6ca1-4440-a2ab-9622106022af1.gif)
VB试验答案
2-1
PrivateSubCmdCalculate_Click()
DimLAsInteger
L=Val(TxtLength.Text)
TxtArea.Text=Str(L*L)
TxtGirth.Text=Str(4*L)
EndSub
PrivateSubcmdClear_Click()
TxtLength.Text=""
TxtArea.Text=""
TxtGirth.Text=""
TxtLength.SetFocus
EndSub
PrivateSubForm_Load()
EndSub
2-2
PrivateSubCmdCalculate_Click()
DimRAsInteger
DimHAsInteger
R=Val(TxtR.Text)
H=Val(TxtH.Text)
TxtV.Text=Str(3.14*R*R*H)
EndSub
PrivateSubcmdClear_Click()
TxtR.Text=""
TxtH.Text=""
TxtV.Text=""
TxtR.SetFocus
EndSub
PrivateSubLabel1_Click()
EndSub
2-3
PrivateSubCmdexit_Click()
UnloadMe
Frmmain.Show
EndSub
PrivateSubForm_Load()
EndSub
2-5
PrivateSubForm_Load()
Text1.Text="本练习是采用文本框制作的一个简单编辑器,该编辑器可以输入多行文字,有水平滚动条和垂直滚动条。
另外文本框的大小可随着窗体大小的改变而改变,并总是充满整个窗体"
EndSub
PrivateSubForm_Resize()
Text1.Left=0
Text1.Top=0
Text1.Width=Form1.ScaleWidth
Text1.Height=Form1.ScaleHeight
EndSub
PrivateSubText1_Change()
EndSub
2-6
PrivateSubCommand1_Click()
Text1.Text=Label1.Caption
EndSub
PrivateSubCommand2_Click()
End
EndSub
PrivateSubText1_Change()
EndSub
2-7
PrivateSubCommand1_Click()
PrintTab(5);"*"
PrintTab(4);"***"
PrintTab(3);"*****"
PrintTab
(2);"*******"
EndSub
PrivateSubCommand2_Click()
Cls
EndSub
PrivateSubCommand3_Click()
Move0,0
EndSub
PrivateSubForm_Load()
EndSub
2-8
PrivateSubCommand1_Click()
Text1="千里之行,始于足下"
Text1.Left=Form1.Width-Text1.Width
Text1.Top=0
Command1.Enabled=False
Text1.Visible=True
EndSub
PrivateSubCommand2_Click()
Text1.Visible=False
Command1.Enabled=True
EndSub
PrivateSubForm_Load()
EndSub
3-1
DimfAsSingle,cAsSingle
DimanswerAsInteger
'PrivateSubCmdend_Click()
'UnloadMe
'Frmmain.Show
'EndSub
PrivateSubCmdhs_Click()
f=Val(Txthua.Text)
c=(f-32)*5/9
Txtshe.Text=Str$(c)
EndSub
PrivateSubCmdsh_Click()
c=Val(Txtshe.Text)
Ifc=0Then
Txthua.Text="32"
ElseIfc>0Then
f=(c*9#/5)+32
Txthua.Text=Str$(f)
Else
answer=MsgBox("非法数据!
",vbOKOnly+vbExclamation,"提示信息")
Ifanswer=vbOKThen
Txtshe.Text=""
Txthua.Text=""
Txtshe.SetFocus
EndIf
EndIf
EndSub
PrivateSubLabel1_Click()
EndSub
3-2
OptionExplicit
DimfsAsInteger
PrivateSubcmdGreat_Click()
Text1.Text=UCase(Text1.Text)
EndSub
PrivateSubcmdRecall_Click()
Text2.Text=Len(Text1.Text)
EndSub
PrivateSubcmdSmall_Click()
Text1.Text=LCase(Text1.Text)
EndSub
PrivateSubForm_Load()
EndSub
3-3
PrivateSubForm_Click()
Dims1AsSingle,s2AsSingle,s3AsSingle
Dimstr1AsString,str2AsString
Dimb1AsBoolean,b2AsBoolean,b3AsBoolean
Dimn1AsInteger,n2AsInteger,n3AsInteger
s1=18\4*4#^2/1.6
s2=25\3Mod3.2*Int(2.5)
str1=UCase("Xyz")&1234&LCase("abC")
b1=3>4Or5>4
b2=TrueAndFalse
n1=Int(-3.5)+Fix(3.5)+CInt(2.6)
n2=Len(Str(123)+"Hello")
s3=Sgn(7Mod3-4)+"0.75"
b3="aeoplane"<"airplane"
n3=Len("VB程序设计")
Prints1
Prints2
Printstr1
Printb1
Printb2
Printn1
Printn2
Prints3
Print"******************************"
Printb3
Printn3
EndSub
3-4
OptionExplicit
PrivateSubForm_Click()
DimxAsInteger,yAsSingle
ConstPI=3.1415926
x=30:
y=x*PI/180
Print"SIN(";x;")=";Sin(y)
Print"cos(";x;")=";Cos(y)
Print"tan(";x;")=";Sin(y)/Cos(y)
Print
x=45:
y=x*PI/180
Print"SIN(";x;")=";Sin(y)
Print"cos(";x;")=";Cos(y)
Print"tan(";x;")=";Sin(y)/Cos(y)
Print
x=90:
y=x*PI/180
Print"SIN(";x;")=";Sin(y)
Print"cos(";x;")=";Cos(y)
EndSub
3-5
OptionExplicit
PrivateSubCommand1_Click()
DimmAsInteger,aAsInteger,bAsInteger,cAsInteger,dAsInteger
m=Val(Text1.Text)
a=m\1000
b=m\100-a*10
c=(m\10)Mod10
d=mMod10
Text2.Text=CStr(d*1000+c*100+b*10+a)
EndSub
PrivateSubCommand2_Click()
End
EndSub
3-6
OptionExplicit
DimfsAsInteger
PrivateSubcmdGreat_Click()
DimiAsInteger
Randomize
i=Int(Rnd*(3-1+1))+1
txtInput.FontSize=i*txtInput.FontSize
cmdGreat.Enabled=False
cmdSmall.Enabled=True
EndSub
PrivateSubcmdRecall_Click()
txtInput.FontSize=fs
cmdSmall.Enabled=True
cmdGreat.Enabled=True
EndSub
PrivateSubcmdSmall_Click()
DimiAsInteger
Randomize
i=Int(Rnd*(3-1+1))+1
txtInput.FontSize=txtInput.FontSize/i
cmdSmall.Enabled=False
cmdGreat.Enabled=True
EndSub
PrivateSubForm_Load()
fs=txtInput.FontSize
EndSub
PrivateSubtxtInput_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
txtInput=UCase(Trim(txtInput))
cmdGreat.SetFocus
EndIf
EndSub
4-2
PrivateSubCommand1_Click()
DimstrAsString
str=InputBox("请输入文本信息","输入",_
"欢迎使用VB6")
Label1.Caption="欢迎使用VB6"
EndSub
PrivateSubCommand2_Click()
DimiAsInteger
i=MsgBox("你确实要退出吗?
",_
vbYesNo+vbExclamation,"退出警告")
Ifi=6ThenEnd
EndSub
4-3
OptionExplicit
PrivateSubCommand1_Click()
DimgzAsSingle,zgzAsSingle
gz=Val(txtGz)
Ifgz>=1600Then
zgz=gz*(1+0.1)
ElseIfgz>=1400Then
zgz=gz*(1+0.15)
Else
zgz=gz*(1+0.2)
EndIf
txtZGz=CStr(zgz)
EndSub
PrivateSubCommand2_Click()
txtGz=""
txtZGz=""
txtGz.SetFocus
EndSub
4-4
OptionExplicit
PrivateSubCommand1_Click()
DimtAsInteger,yAsSingle
t=Val(txtTime)
Ift<10Then
y=30
ElseIft<50Then
y=30+(t-10)*3
Else
y=30+(t-10)*2.5
EndIf
Ify<=150Then
txtCost=CStr(y)
Else
txtCost=CStr(150)
EndIf
EndSub
PrivateSubCommand2_Click()
txtTime=""
txtCost=""
txtTime.SetFocus
EndSub
4-5
PrivateSubCommand1_Click()
DimcjAsSingle,str1AsString
cj=Val(Text1.Text)
Ifcj>=90Then
Text2.Text="A"
ElseIfcj>=80Then
Text2.Text="B"
ElseIfcj>=70Then
Text2.Text="C"
ElseIfcj>=60Then
Text2.Text="D"
ElseIfcj>=0Then
Text2.Text="E"
EndIf
EndSub
PrivateSubCommand2_Click()
Text1.Text=""
Text2.Text=""
EndSub
PrivateSubCommand3_Click()
End
EndSub
PrivateSubText1_LostFocus()
IfNotIsNumeric(Text1.Text)OrVal(Text1.Text)<0Then
MsgBox"数据输入错误,重输"
Text1.Text=""
Text1.SetFocus
EndIf
EndSub
4-6
OptionExplicit
PrivateSubForm_Load()
DimYAsInteger,mAsInteger
DimdAsInteger,w1AsInteger
DimRqAsDate
Dimw2AsString
Rq=Date
Y=Year(Rq)
m=Month(Rq)
d=Day(Rq)
w1=Weekday(Rq)
SelectCasew1
Case1
w2="日"
Case2
w2="一"
Case3
w2="二"
Case4
w2="三"
Case5
w2="四"
Case6
w2="五"
Case7
w2="六"
EndSelect
Label1.Caption="今天是"&Y&"年"&m&"月"&d&"日"&"星期"&w2
EndSub
4-7
PrivateSubCommand1_Click()
DimY1AsInteger,M1AsInteger
DimflagAsBoolean,D1AsInteger,S1AsString
Y1=Val(txtYear)
M1=Val(txtMonth)
flag=(Y1Mod4=0AndY1Mod100<>0)OrY1Mod400=0
SelectCaseM1
Case1,2,3
D1=31:
S1="一季度"
IfM1=2Then
IfflagThen
D1=29
Else
D1=28
EndIf
EndIf
Case4,5,6
D1=30:
S1="二季度"
IfM1=5ThenD1=31
Case7,8,9
D1=31:
S1="三季度"
IfM1=9ThenD1=30
Case10,11,12
D1=31:
S1="四季度"
IfM1=11ThenD1=30
EndSelect
IfflagThen
txtRun="是闰年"
Else
txtRun="不是闰年"
EndIf
txtSea=S1
txtDays=Str(D1)
EndSub
PrivateSubCommand2_Click()
txtYear=""
txtMonth=""
txtSea=""
txtRun=""
txtDays=""
EndSub
4-8
PrivateSubCmdclear_Click()
txta.Text=""
Txtb.Text=""
Txtc.Text=""
Txtx1.Text=""
Txtx2.Text=""
txta.SetFocus
EndSub
PrivateSubCmdcup_Click()
a=Val(txta.Text)
b=Val(Txtb.Text)
c=Val(Txtc.Text)
disc=b*b-4*a*c
p=-b/(2*a)
q=Sqr(Abs(disc))/(2*a)
Ifdisc>=0Then
Txtx1=Format$(p+q,"####0.###")
Txtx2=Format$(p-q,"####0.###")
Else
Txtx1=Str$(p)&"+"&Str$(q)&"i"
Txtx2=Str$(p)&"-"&Str$(q)&"i"
EndIf
EndSub
PrivateSubCmdend_Click()
End
EndSub
PrivateSubtxta_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
IfNotIsNumeric(txta.Text)Then
MsgBox"数据非法,重输"
txta.Text=""
txta.SetFocus
Else
Txtb.SetFocus
EndIf
EndIf
EndSub
PrivateSubTxtb_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
IfNotIsNumeric(Txtb.Text)Then
MsgBox"数据非法,重输"
Txtb.Text=""
Txtb.SetFocus
Else
Txtc.SetFocus
EndIf
EndIf
EndSub
PrivateSubTxtc_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
IfNotIsNumeric(Txtc.Text)Then
MsgBox"数据非法,重输"
Txtc.Text=""
Txtc.SetFocus
Else
Cmdcup.SetFocus
EndIf
EndIf
EndSub
4-9
PrivateSubCmdclear_Click()
txtm1=""
txtm2=""
txtm3=""
Lblinfo.Caption=""
txtm1.SetFocus
EndSub
PrivateSubCmdsort_Click()
Dimm1AsInteger,m2AsInteger,m3AsInteger
m1=Val(txtm1.Text)
m2=Val(txtm2.Text)
m3=Val(txtm3.Text)
If(m1+m2+m3)\3>95Or(m1=100Andm2=100Andm3>=80)_
Or(m1=100Andm3=100Andm2>=80)Or_
(m1>=80Andm2=100Andm3=100)Then
Lblinfo.Caption="此学生奖学金为一等奖"
ElseIf(m1+m2+m3)\3>90Or(m1=100Andm2>=75Andm3>=75)_
Or(m1>=75Andm2=100Andm3>=75)Or_
(m1>=75Andm2>=75Andm3=100)Then
Lblinfo.Caption="此学生奖学金为二等奖"
ElseIfm1>=70Andm2>=70Andm3>=70Then
Lblinfo.Caption="此学生奖学金为三等奖"
Else
Lblinfo.Caption="此学生无奖学金"
EndIf
EndSub
PrivateSubtxtm1_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
IfNotIsNumeric(txtm1)Then
MsgBox"数据非法,重新输入",vbExclamation,"输入操作数1"
txtm1.Text=""
txtm1.SetFocus
Else
txtm2.SetFocus
EndIf
EndIf
EndSub
PrivateSubtxtm2_KeyPress(KeyAsc