常用的的测量程序vb代码.docx
- 文档编号:24836987
- 上传时间:2023-06-02
- 格式:DOCX
- 页数:26
- 大小:228.73KB
常用的的测量程序vb代码.docx
《常用的的测量程序vb代码.docx》由会员分享,可在线阅读,更多相关《常用的的测量程序vb代码.docx(26页珍藏版)》请在冰豆网上搜索。
常用的的测量程序vb代码
取一元、二元、五元的硬币共十枚,付给25元钱,有多少种不同的取法?
方法一
PrivateSubCommand1_Click()
Print"一元","两元","五元"
Fora=0To10
Forb=0To10
Forc=0To10
Ifa+2*b+5*c=25Anda+b+c=10Then
Printa,b,c
EndIf
Nextc
Nextb
Nexta
EndSub:
方法二
PrivateSubCommand1_Click()
Print"一元","两元","五元"
Fora=0To10
Forb=0To10
c=10-a-b
Ifa+2*b+5*c=25Andc>0Then
Printa,b,c
EndIf
Nextb
Nexta
EndSub
九九乘法表
方法一
PrivateSubCommand1_Click()
PrintTab(12);"九九乘法表"
Fori=1To9
Forj=1Toi
Printi*j;
Nextj
Print
Nexti
EndSub
方法二
PrivateSubCommand2_Click()
Show
FontSize=15
PrintTab(12);
FontSize=12
Print
Fork=0To9
PrintTab(k*4);k;
Nextkjiu
Print
Forj=1To9
Printj;
Fork=1Toj
PrintTab(k*4);j*k;
Nextk
Print
Nextj
EndSub
求T=8!
=1×2×3×…×8
PrivateSubCommand1_Click()
jc=1
n=Val(Text1.Text)
Forc=1Ton
jc=jc*c
Nextc
Print"jc=";jc
EndSub
用100元买100只鸡,母鸡3元1只,小鸡1元3只,问各应买多少只?
PrivateSubCommand1_Click()
DimxAsInteger,yAsInteger
Forx=1To30
y=100-x
If3*x+y/3=100Then
Print"母鸡只数为:
";x,
Print"小鸡只数为:
";y
EndIf
Nextx
EndSub
数组
打印数组的上界和下界数值
PrivateSubCommand1_Click()
Dima(1To10)AsInteger
Print"下界值","上界值"
PrintLBound(a),UBound(a)
EndSub
数组解决1+2+3+4+5+6+7+8=?
PrivateSubCommand1_Click()
Dima(1To10)AsInteger
DimsumAsInteger
Forb=1To8
a(b)=b
sum=sum+a(b)
Nextb
Text1.Text=sum
Print"1+2+3+4+5+6+7+8="&sum
EndSub
任意五个数字之和
PrivateSubCommand1_Click()
DimData(5)AsInteger
DimSum,IAsInteger
ForI=1To5
Data(I)=InputBox("输入第"&I&"个数据")
NextI
ForI=1To5
Sum=Sum+Data(I)
NextI
Text1.Text=Sum
PrintSum
EndSub
连续输入5个数字
例如1,2,3,4,5
1+3+5+7+9=?
奇数和
PrivateSubCommand1_Click()
Dima(1To5)AsInteger
DimsumAsInteger
Forx=1To5
a(x)=x*2-1
sum=sum+a(x)
Nextx
Text1.Text=sum
Printsum
EndSub
PrivateFunctionpf(xAsLong,yAsLong)AsLong
s=Sqr(x^2+y^2)
pf=s
EndFunction
PrivateSubCommand1_Click()
DimaAsLong
DimbAsLong
DimcAsLong
a=Val(Text1.Text)
b=Val(Text2.Text)
s=pf(a,b)
Prints
EndSub
Sub过程和Function过程
3.编写过程,求两个数的最大公约数。
PrivateSubpd(xAsInteger,yAsInteger,zAsInteger)
Forj=1Toy
IfxModj=0AndyModj=0Then
z=j
EndIf
Nextj
EndSub
PrivateSubCommand1_Click()
DimaAsInteger
DimbAsInteger
DimcAsInteger
a=Val(Text1.Text)
b=Val(Text2.Text)
Callpd(a,b,c)
Printc
EndSub
4.编写一个计算平方根的Function过程
PrivateFunctionpf(xAsLong,yAsLong)AsLong
s=Sqr(x^2+y^2)
pf=s
EndFunction
PrivateSubCommand1_Click()
DimaAsLong
DimbAsLong
DimsAsLong
a=Val(Text1.Text)
b=Val(Text2.Text)
s=pf(a,b)
Prints
EndSub
判断一个数是奇数还是偶数
PrivateSubpd(aAsInteger,bAsString)
IfaMod2=0Then
b="偶数"
Else
b="奇数"
EndIf
EndSub
PrivateSubCommand1_Click()
DimxAsInteger
DimyAsString
x=Val(Text1.Text)
Callpd(x,y)
Printy
EndSub
10.有5个人坐在一起,问第5个人多少岁?
他说比第4个人大2岁。
问第4个人岁数,他说比第3个人大2岁。
问第3个人,又说比第2个人大2岁。
问第2个人,说比第1个人大2岁。
最后问第1个人,他说是10岁。
请问第5个人有多大岁数?
第一种
PrivateSubpd(aAsInteger,bAsInteger,cAsInteger,dAsInteger,eAsInteger)
a=10
b=a+2
c=b+2
d=c+2
e=d+2
EndSub
PrivateSubCommand1_Click()
DimmAsInteger
DimnAsInteger
DimlAsInteger
DimkAsInteger
Callpd(10,m,n,l,k)
Print10,m,n,l,k
EndSub
第二种
PrivateFunctionpd(aAsInteger)AsInteger
a=10
Fori=1To4
a=a+2
Printa
Nexti
pd=a
EndFunction
PrivateSubCommand1_Click()
DimsAsInteger
DimaAsInteger
s=pd(10)
Print10
Prints
EndSub
1+2+3+…….100=?
方法一
PrivateSubCommand1_Click()
DimiAsInteger
s=0
DoWhilei<=100
s=s+i
i=i+1
Loop
Prints
EndSub
方法二
PrivateSubCommand1_Click()
s=0
Fori=1To100
s=s+i
Nexti
Prints
EndSub
角度转换
PrivateSubCommand1_Click()
DimdfmAsDouble
dfm=Val(Text1.Text)
DimhdAsDouble
Calldfmtohd(dfm,hd)
Text2.Text=hd
EndSub
PrivateSubdfmtohd(dfm1AsDouble,hd1AsDouble)
DimduAsInteger
DimfenAsDouble
DimmiaoAsDouble
DimpiAsDouble
pi=3.1415926
du=Int(dfm1)
fen=Int((dfm1-du)*100)
miao=((dfm1-du)*100-fen)*100
Printdu,fen,miao
hd1=(du+fen/60+miao/3600)*pi/180
EndSub
弧度换算角度
PrivateSubCommand2_Click()
DimhdAsDouble
hd=Val(Text3.Text)
DimdfmAsDouble
Callhdtodfm(hd,dfm)
Text4.Text=dfm
EndSub
PrivateSubhdtodfm(hd2,dfm1)
Dimdu1AsInteger
DimfenAsInteger
DimmiaoAsDouble
DimpiAsDouble
pi=3.1415926
dfm1=hd2*180/pi
du=Int(dfm1)
fen=Int((dfm1-du)*60)
miao=((dfm1-du)*60-fen)*60
dfm1=du+fen/100+miao/10000
EndSub
坐标正算代码
PrivateSubCommand1_Click()
DimxaAsDouble
DimyaAsDouble
DimpjAsDouble
DimfwjAsDouble
xa=Val(Text1.Text)
ya=Val(Text2.Text)
pj=Val(Text3.Text)
fwj=Val(Text4.Text)
DimxbAsDouble
DimybAsDouble
Callzbzs(xa,ya,pj,fwj,xb,yb)
Text5.Text=Format(xb,"0.000")
Text6.Text=Format(yb,"0.000")
EndSub
PrivateSubzbzs(xa1AsDouble,ya1AsDouble,pj1AsDouble,fwj1AsDouble,xb1AsDouble,yb1AsDouble)
Dimfwj2AsDouble
Calldfmtohd(fwj1,fwj2)
xb1=xa1+pj1*Cos(fwj2)
yb1=ya1+pj1*Sin(fwj2)
EndSub
PrivateSubdfmtohd(szj1AsDouble,fwj2AsDouble)
DimduAsInteger
DimfenAsDouble
DimmiaoAsDouble
DimpiAsDouble
pi=3.1415926
du=Int(szj1)
fen=Int((szj1-du)*100)
miao=((szj1-du)*100-fen)*100
fwj2=(du+fen/60+miao/3600)*pi/180
EndSub
三角高差计算
PrivateSubCommand1_Click()
DimxjAsDouble
DimszjAsDouble
DimyqgAsDouble
DimljgAsDouble
DimgcAsDouble
xj=Val(Text1.Text)
szj=Val(Text2.Text)
yqg=Val(Text3.Text)
ljg=Val(Text4.Text)
Callgcjs(xj,szj,yqg,ljg,gc)
Text5.Text=gc
EndSub
PrivateSubgcjs(xj1AsDouble,szj1AsDouble,yqg1AsDouble,ljg1AsDouble,gc1AsDouble)
Dimsjz2AsDouble
Calldfmtohd(szj1,sjz2)
gc1=xj1*Sin(sjz2)+yqg1-ljg1
EndSub
PrivateSubdfmtohd(szj1AsDouble,szj2AsDouble)
DimduAsInteger
DimfenAsDouble
DimmiaoAsDouble
DimpiAsDouble
pi=3.1415926
du=Int(szj1)
fen=Int((szj1-du)*100)
miao=((szj1-du)*100-fen)*100
szj2=(du+fen/60+miao/3600)*pi/180
EndSub
坐标反算
PrivateSubCommand1_Click()
DimxaAsDouble
DimyaAsDouble
DimxbAsDouble
DimybAsDouble
xa=Val(Text1.Text)
ya=Val(Text2.Text)
xb=Val(Text3.Text)
yb=Val(Text4.Text)
DimjlAsDouble
DimfwjAsDouble
Callzbfs(xa,ya,xb,yb,jl,fwj)
Text5.Text=jl
Text6.Text=fwj
EndSub
PrivateSubzbfs(xa1AsDouble,ya1AsDouble,xb1AsDouble,yb1AsDouble,jl1AsDouble,fwj1AsDouble)
DimdxAsDouble
DimdyAsDouble
dx=xb1-xa1
dy=yb1-ya1
jl1=Sqr(dx^2+dy^2)
Constpi=3.1415926
Ifdx=0Anddy>0Then
fwj=0
ElseIfdx=0Anddy<0Then
fwj=0
ElseIfdx>0Anddy=0Then
fwj=pi/2
ElseIfdx<0Anddy=0Then
fwj=3/2*pi
ElseIfdx>0Anddy>0Then
fwj=Atn(dy/dx)
ElseIfdx>0Anddy<0Then
fwj=1.5*pi+Atn(Abs(dy/dx))
ElseIfdx<0Anddy>0Then
fwj=pi-Atn(Abs(dy/dx))
ElseIfdx<0Anddy<0Then
fwj=pi+Atn(Abs(dy/dx))
Else
MsgBox"两点重合!
"
EndIf
Callhdtodfm(fwj,fwj2)
fwj1=fwj2
EndSub
PrivateSubhdtodfm(hd2,dfm1)
Dimdu1AsInteger
DimfenAsInteger
DimmiaoAsDouble
DimpiAsDouble
pi=3.1415926
dfm1=hd2*180/pi
du=Int(dfm1)
fen=Int((dfm1-du)*60)
miao=((dfm1-du)*60-fen)*60
dfm1=du+fen/100+miao/10000
EndSub
角度前方交会代码
PrivateSubCommand1_Click()
DimxaAsDouble
DimyaAsDouble
DimxbAsDouble
DimybAsDouble
DimmAsDouble
DimnAsDouble
DimxpAsDouble
DimypAsDouble
xa=Val(Text1.Text)
ya=Val(Text2.Text)
xb=Val(Text3.Text)
yb=Val(Text4.Text)
m=Val(Text5.Text)
n=Val(Text6.Text)
Callqfjh(xa,ya,xb,yb,m,n,xp,yp)
Text7.Text=xp
Text8.Text=yp
EndSub
PrivateSubqfjh(xa1AsDouble,ya1AsDouble,xb1AsDouble,yb1AsDouble,m1AsDouble,n1AsDouble,xp1AsDouble,yp1AsDouble)
DimmAsDouble
DimnAsDouble
Calldfmtohd(m1,m)
Calldfmtohd(n1,n)
Constpi=3.1415926
Ifm+n=piOrm+n>piThen
MsgBox"输入有误不能交会!
"
Else
xp1=(xa1*(1/Tan(n))+xb1*(1/Tan(m))-ya1+yb1)/((1/Tan(m))+(1/Tan(n)))
yp1=(ya1*(1/Tan(n))+yb1*(1/Tan(m))+xa1-xb1)/((1/Tan(m))+(1/Tan(n)))
EndIf
EndSub
PrivateSubdfmtohd(szj1AsDouble,fwj2AsDouble)
DimduAsInteger
DimfenAsDouble
DimmiaoAsDouble
DimpiAsDouble
pi=3.1415926
du=Int(szj1)
fen=Int((szj1-du)*100)
miao=((szj1-du)*100-fen)*100
fwj2=(du+fen/60+miao/3600)*pi/180
EndSub
此代码仅供参考。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 常用 测量 程序 vb 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)