vb实验代码大全.docx

上传人:b****5 文档编号:5751773 上传时间:2022-12-31 格式:DOCX 页数:31 大小:23.21KB
下载 相关 举报
vb实验代码大全.docx_第1页
第1页 / 共31页
vb实验代码大全.docx_第2页
第2页 / 共31页
vb实验代码大全.docx_第3页
第3页 / 共31页
vb实验代码大全.docx_第4页
第4页 / 共31页
vb实验代码大全.docx_第5页
第5页 / 共31页
点击查看更多>>
下载资源
资源描述

vb实验代码大全.docx

《vb实验代码大全.docx》由会员分享,可在线阅读,更多相关《vb实验代码大全.docx(31页珍藏版)》请在冰豆网上搜索。

vb实验代码大全.docx

vb实验代码大全

实验31

PublicClassForm1

PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click

DimiAsInteger

DimnAsInteger

DimsAsSingle

s=0

n=InputBox("请输入n")

Fori=1Ton

s=s+1/(i*(i+1))

Next

MsgBox("s="&s)

EndSub

PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click

Dima(10)AsInteger

DimiAsInteger

DimxAsInteger

DimyAsInteger

x=0

y=0

Fori=1To10

a(i)=InputBox("请输入第"&i&"个数")

IfiMod2=0Then

x=x+a(i)

Else

y=y+a(i)

EndIf

Next

MsgBox("下标为奇数的元素和为"&y&"下标为偶数的元素和为"&x)

EndSub

PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click

DimrAsInteger,sAsInteger,cAsInteger,y(5)AsString,jAsInteger,ysAsString

ys=""

r=1

DoWhiler<=4

c=10-r:

s=1

y(r)=y(r)&Space(c+s)

DoWhiles<=2*r-1

y(r)=y(r)&"*"

s=s+1

Loop

r=r+1

Loop

Forj=1To4

ys=ys&y(j)&Chr(10)

Next

MsgBox(ys)

EndSub

PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click

DimrAsInteger,sAsInteger,cAsInteger,y(5)AsString,ysAsString

ys=""

r=4

DoWhiler>=1

c=10-r:

s=1

ys=ys&Space(c+s)

DoWhiles<=2*r-1

ys=ys&"*"

s=s+1

Loop

r=r-1

ys=ys&Chr(10)

Loop

MsgBox(ys)

EndSub

PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click

EndSub

PrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton6.Click

Dima(19)AsInteger

DimsAsString

DimiAsInteger

DimxAsInteger

DimyAsInteger

x=0

y=0

s=""

Fori=0To19

a(i)=Int(Rnd()*100)

s=s&a(i)&","

Ifa(i)>50Then

x=x+1

ElseIfa(i)<10Then

y=y+1

EndIf

Next

MsgBox(s&vbCrLf&"50万元以上的业务人数为"&x&",10万元以下的业务人数为"&y)

EndSub

PrivateSubButton7_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton7.Click

Dima(19)AsInteger

DimtAsInteger

DimiAsInteger

DimjAsInteger

DimxAsString

DimyAsString

x=""

y=""

 

Fori=0To19

a(i)=Int(Rnd()*100)

x=x&a(i)&","

Next

Fori=0To19

Forj=19Toi+1Step-1

Ifa(j)

t=a(j)

a(j)=a(j-1)

a(j-1)=t

EndIf

Next

y=y&a(i)&","

Next

 

MsgBox(x&vbCrLf&y)

EndSub

PrivateSubButton8_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton8.Click

DimaAsInteger

Dimb(9)AsInteger

DimsAsInteger

DimuAsString

DimiAsInteger

Randomize()

a=Int(Rnd()*90000000+10000000)

Fori=0To7

s=Mid(a,i+1,1)

b(s)=b(s)+1

Next

u="8位数为:

("&a&")"&vbCrLf

Fori=0To9

u=u&i&"出现次数:

"&b(i)&vbCrLf

Next

MsgBox(u)

EndSub

PrivateSubButton9_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton9.Click

Dimb(19)AsInteger

DimiAsInteger

DimsAsString

s=""

Fori=0To19

b(i)=Int(Rnd()*90000000+10000000)

s=s&b(i)&vbCrLf

Next

MsgBox(s)

EndSub

PrivateSubButton10_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton10.Click

DimiAsInteger

DimtAsSingle

DimsAsSingle

i=1

t=1/(i*(i+1))

s=0

DoWhilet>=0.000001

s=s+t

i=i+1

t=1/(i*(i+1))

Loop

MsgBox("s="&s)

EndSub

PrivateSubButton11_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton11.Click

DimiAsInteger

DimtAsSingle

DimsAsSingle

i=1

t=1/(i*(i+1))

s=0

Do

s=s+t

i=i+1

t=1/(i*(i+1))

LoopWhilet>=0.000001

MsgBox("s="&s)

EndSub

PrivateSubButton14_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton14.Click

Dima()AsInteger

DimiAsInteger

DimnAsInteger

DimxAsInteger

DimyAsInteger

x=0

y=0

n=InputBox("请输入数组的数量")

ReDima(n)

Fori=1Ton

a(i)=InputBox("请输入第"&i&"个数")

IfiMod2=0Then

x=x+a(i)

Else

y=y+a(i)

EndIf

Next

MsgBox("下标为奇数的元素和为"&y&"下标为偶数的元素和为"&x)

EndSub

PrivateSubButton15_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton15.Click

DimsAsString

DimyAsString

DimtAsString

Dima()AsString

DimiAsInteger

DimjAsInteger

DimlAsInteger

t=""

y=""

s=InputBox("请输入要排序的字符串")

l=Len(s)

ReDima(l)

Fori=1Tol

a(i)=Mid(s,i,1)

Next

Fori=1Tol

Forj=lToi+1Step-1

Ifa(j)

t=a(j)

a(j)=a(j-1)

a(j-1)=t

EndIf

Next

y=y&a(i)

Next

MsgBox(s&vbCrLf&y)

EndSub

PrivateSubButton16_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton16.Click

DimnAsInteger

DimiAsInteger

DimjAsInteger

DimsAsString

DimtAsString

Dimi_0AsInteger

Dimj_0AsInteger

Dimmfz_bz(9,9)AsString

Dimmfz(9,9)AsString

 

n=InputBox("请输入魔方阵阶数N")

Ifn<3Orn>9OrnMod2<>1Then

MsgBox("您输入的魔方阵阶数N不在范围内,请输入3-9之间的奇数")

ExitSub

EndIf

'初始化

Fori=1To9

Forj=1To9

mfz_bz(i,j)=0

mfz(i,j)=""

Nextj

Nexti

mfz(1,n\2+1)=1

mfz_bz(1,n\2+1)=1

i_0=1

j_0=n\2+1

Forysz=2Ton*n

Ifmfz(i_0,j_0)>nAnd(mfz(i_0,j_0)Modn=0)Then

i=i_0+1

j=j_0

ElseIfi_0=1Then

i=n

j=j_0+1

ElseIfj_0=nThen

i=i_0-1

j=1

Else

i=i_0-1

j=j_0+1

EndIf

Ifmfz_bz(i,j)=1Then

i=i_0+1

j=j_0

EndIf

mfz(i,j)=ysz

mfz_bz(i,j)=1

i_0=i

j_0=j

Nextysz

MsgBox("魔方阵排列完毕")

s=""

Fori=1To9

Forj=1To9

t=mfz(i,j)

s=s&Format(t,"{0,4}")

Next

s=s&vbCrLf

Next

MsgBox(s)

EndSub

EndClass

 

实验30

PublicClassForm1

PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click

DimaAsString,bAsString,cAsString

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

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

PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click

DimxAsInteger

x=Int(Rnd()*100)

IfxMod2=0Then

MsgBox(x&"是偶数")

Else

MsgBox(x&"是奇数")

EndIf

EndSub

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

EndIf

Ifc>xThen

x=c

Else

Ifc

y=c

EndIf

EndIf

MsgBox("最大数"&x&"最小数"&y)

EndSub

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

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

MsgBox("成绩"&x&"等级为"&y)

EndSub

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)/

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 文化宗教

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1