《医药信息技术基础实践指导》答案作者晏峻峰.docx
《《医药信息技术基础实践指导》答案作者晏峻峰.docx》由会员分享,可在线阅读,更多相关《《医药信息技术基础实践指导》答案作者晏峻峰.docx(44页珍藏版)》请在冰豆网上搜索。
《医药信息技术基础实践指导》答案作者晏峻峰
《医药信息技术基础实践指导》作者:
晏峻峰
练习答案
答案由“晓英振辉奇葩计算机”提供
(红色加粗是检索词,绿色是备注)
PublicClassForm1
PrivateSubForm1_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.Click
Dimvar1AsInteger,var2AsString
var1=12345
var2=InputBox("输入Var2=","输入对话框")
MsgBox(var2&Chr(13)+Chr(10)&"var1="&Str(var1))
'MsgBox(var2&vbCrLf&"var1="&Str(var1))
EndSub
EndClass
定义不同变量
PublicClassForm1
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
DimaAsShort
‘短型
DimbAsSingle
‘单精度
DimcAsInteger
‘整型
DimdAsDate
Dime1AsString
DimfAsBoolean
‘判断
DimgAsString
DimhAsDouble
‘双精度
DimiAsSingle
Dimj(4,3)AsInteger
a=3.25
b=546.2
c=5383149
d=#12/31/2003#
1
e1="ABCDEF"
f=False
g="123456"
h=3.24E+100
i=1.2563E+15
j(0,0)=456
MsgBox(a&vbCrLf&b&vbCrLf&c&vbCrLf&d&vbCrLf&e1&vbCrLf&f&vbCrLf
&g&vbCrLf&h&vbCrLf&i&vbCrLf&j(0,0))EndSub
分析不同表达式,定义并输出结果
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
Dimx21,x22,x23,x24AsSingle
Dimx25,x27,x28AsBoolean
Dimx26AsString
x21
=Sqrt(3^2/(2*4))
‘开方
x22
=+Abs(0.123-3)
‘绝对值
x23
=-Sin(30)
x24
=Exp(6)+Log(2.135)
‘e的6次方
x25
=89&12<>8912
x26
="AB"+Str(32.56)+"CD"
'x27=Mid("student",5)="ent"And(5>2)
‘右边数三位
x27
=Microsoft.VisualBasic.Right("student",3)="ent"And(5>2)
x28
=Not(6>2)Or(7<9)
MsgBox(x21&vbCrLf&x22&vbCrLf&x23&vbCrLf&x24&vbCrLf&x25&vbCrLf&x26&vbCrLf&x27&vbCrLf&x28)
EndSub
一百以内随机数
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
DimyAsInteger
y=Int(Rnd()*100)
MsgBox(y)
EndSub
2
任意字符串测长度
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click
DimyAsString
Dimy1AsInteger
y="VB程序设计语言"
y1=Len(y)
MsgBox(y&"长度为"&y1)
EndSub
给出字符串查片段位置
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click
DimyAsInteger
y=InStr("abcstudent","stu")
MsgBox(y)
EndSub
除去字符串两边空格
PrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton6.Click
DimyAsString
y=Trim("VisualC++")
MsgBox("去除左边空格"&y&"去除右边空格")
EndSub
测字符串所占字节数
PrivateSubButton7_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton7.Click
DimyAsString
Dimy1AsInteger
y="VB程序设计语言"
y1=Len(y)*2‘字符串长度×2
MsgBox(y&"字节数为"&y1)
EndSub
3
字符串反序排列
PrivateSubButton8_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton8.Click
Dimy,y1AsString
y="我去资料室查资料"
y1=StrReverse(y)
MsgBox(y1)
EndSub
从字符串中截取字符
PrivateSubButton9_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton9.Click
Dimy,y1AsString
y="我去资料室查资料"
y1=Mid(y,3,3)‘左边数第三个,数三个
MsgBox(y1)
EndSub
截取字符
PrivateSubButton10_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton10.Click
Dimy,y1AsString
y="我去资料室查资料"
y1=Mid(y,7,2)
'y1=Microsoft.VisualBasic.Right(y,2)
MsgBox(y1)
EndSub
在字符串中插入空格
PrivateSubButton11_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton11.Click
Dimy,y1AsString
y="Thisisabook"
4
y1=Mid(y,1,4)&Space
(1)&Mid(y,5,2)&Space
(1)&Mid(y,7,1)&Space
(1)&Mid(y,
8)
MsgBox(y1)
EndSub
求字母ASCII码
PrivateSubButton12_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton12.Click
DimyAsInteger
y=Asc("Z")
MsgBox(y)
EndSub
计算日期间隔
PrivateSubButton13_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton13.Click
DimyAsDate
Dimy1,y2,y3AsInteger
y="2013-1-1"
y1=DateDiff(DateInterval.Month,y,Today())
y2=DateDiff(DateInterval.WeekOfYear,y,Today())
y3=DateDiff(DateInterval.Day,y,Today())
MsgBox(y1&"个月"&y2&"个星期"&y3&"天")
EndSub
字符串转化为数值
PrivateSubButton14_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton14.Click
DimyAsString
DimaAsInteger
Dimy1AsInteger
y="42897"
y1=Val(y)
a=MsgBox(y1,vbOKCancel)
IfvbOK=aThen
MsgBox(a)
EndIf
EndSub
5
改变数值的输出形式(小数位数)
PrivateSubButton15_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton15.Click
DimyAsSingle
y=3287.153
MsgBox(Format(y,"000.00"))
EndSub
输出数据(每行四个,数据间隔四格,数值型00000.00,字符型@@@@@@@@,日期型
dddddd
PrivateSubButton16_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)
HandlesButton16.Click
Dimz1,z2,z3,z4AsSingle
Dimz5,z6,z7AsString
Dimz8AsDate
z1
=45.632
z2
=8246.25
z3
=123.8
z4
=45627
z5
="student"
z6
="permanence"
z7
="teachers"
z8
=#4/5/2004#
MsgBox(Format(z1,"00000.00")&""&Format(z2,"00000.00")&""&Format(z3,
"00000.00")&""&Format(z4,"00000.00")&vbCrLf&Format(z5,"{0,-8}")&""&Format(z6,
"{0,-8}")&""&Format(z7,"{0,-8}")&""&Format(z8,"d"))‘换行
EndSub
EndClass
If语句,select语句进行有条件的计算,成绩排名,大小排序
PublicClassForm1
数学公式计算格式,含平方根
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
DimaAsString,bAsString,cAsString
6
Dimx1AsSingle,x2AsSingle
a=InputBox("输入A","输入数据Y",,500,500)
b=InputBox("输入B","输入数据Y",,500,500)
c=InputBox("输入C","输入数据Y",,500,500)
x1
=-b+Math.Sqrt(b^2-4*a*c)/2/a
x2
=-b-Math.Sqrt(b^2-4*a*c)/2/a
MsgBox("x1="&Format(x1,"###.###")&"
x2="&Format(x2,"###.###"))
EndSub
公式计算
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
DimxAsInteger
DimyAsInteger
DimzAsSingle
x=5
y=9
z=(x^3+x*y+y^3)/(2*x*y)
MsgBox("(x^3+x*y+y^3)/(2*x*y)="&z)
EndSub
公式计算,含对数,绝对值
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
DimxAsSingle
DimyAsSingle
x=InputBox("输入x")
y=Math.Log(20)+Math.Abs(x-16)
MsgBox("Math.Log(20)+Math.Abs(x-16)="&y)
EndSub
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)
HandlesButton4.Click
DimxAsSingle
DimyAsSingle
x=InputBox("输入x")
y=0.231*x+1.36
MsgBox("0.231*x+1.36="&y)
EndSub
7
公式计算,角度转换
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click
ConstgAsSingle=9.81
DimvAsSingle,oAsSingle,tAsSingle,sAsSingle
v=InputBox("输入初速度")
o=InputBox("输入角度")
t=2*v*Math.Sin(o*Math.PI/180)/g
s=v*Math.Sin(2*o*Math.PI/180)/g
MsgBox("落地所需时间"&t&"落地时运动的射程"&s)
EndSub
EndClass
PublicClassForm1
If语句,随机函数产生奇,偶数,
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)
HandlesButton1.Click
DimxAsInteger
x=Int(Rnd()*100)
IfxMod2=0Then
MsgBox(x&"是偶数")
Else
MsgBox(x&"是奇数")
EndIf
EndSub
If语句找出a,b,c中最大最小数
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
DimaAsSingle,bAsSingle,cAsSingle,xAsSingle,yAsSingle
a=InputBox("请输入a")
b=InputBox("请输入b")
c=InputBox("请输入c")
Ifa>bThen
x=a
y=b
Else
x=b
y=a
8
EndIf
Ifc>aThen
x=c
Else
Ifcy=c
EndIf
EndIf
MsgBox("最大数"&x&"最小数"&y)
EndSub
If语句进行有条件的计算
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
DimtAsSingle,fAsSingle
t=InputBox("请输入t")
Ift<120Then
f=0.06*t+2
MsgBox("f=0.06*t+2="&f)
Else
f=0.06*t*0.85
MsgBox("f=0.06*t*0.85="&f)
EndIf
EndSub
If语句排成绩等级
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click
DimxAsSingle
DimyAsString
x=InputBox("请输入成绩")
Ifx>=90Then
y="A"
ElseIfx>=80Then
y="B"
ElseIfx>=70Then
y="C"
ElseIfx>=60Then
y="D"
Else
y="E"
EndIf
9
MsgBox("成绩"&x&"等级为"&y)
EndSub
Select语句进行有条件的计算
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click
DimxAsSingle,yAsSingle
x=InputBox("请输入x")
SelectCasex
CaseIs<=-1
y=x-1
CaseIs<=2
y=2*x
CaseIs<=10
y=x*(x+2)
CaseElse
y=0
EndSelect
MsgBox("y="&y)
EndSub
PrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)
HandlesButton6.Click
DimaAsString,bAsString,cAsString
Dimx1AsSingle,x2AsSingle,xAsSingle
a=InputBox("输入A","输入数据Y",,500,500)
b=InputBox("输入B","输入数据Y",,500,500)
c=InputBox("输入C","输入数据Y",,500,500)
x=b^2-4*a*c
Ifx>=0Then
x1=-b+Math.Sqrt(x)/2/a
x2=-b-Math.Sqrt(x)/2/a
MsgBox("x1="&Format(x1,"###.###")&"x2="&Format(x2,"###.###"))
Else
x1=Math.Sqrt(-x)/2/a
x2=-Math.Sqrt(-x)/2/a
MsgBox("x1="&-b/2/a&x1&"ix2="&-b/2/a&x2&"i")
EndIf
EndSub
PrivateSubButton7_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton7.Click
DimxAsSingle,yAsSingle
10
x=InputBox("请输入x")
Ifx<=-1Then
y=x-1
ElseIfx<=2Then
y=2*x
ElseIfx<=10Then
y=x*(x+2)
End