河南大學VB程序設(shè)計課后習題參考答案_第1頁
河南大學VB程序設(shè)計課后習題參考答案_第2頁
河南大學VB程序設(shè)計課后習題參考答案_第3頁
河南大學VB程序設(shè)計課后習題參考答案_第4頁
河南大學VB程序設(shè)計課后習題參考答案_第5頁
已閱讀5頁,還剩41頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

河南大學VB程序設(shè)計課后習題參考

答案(編碼)

2-1

PrivateSubForm_Click()

Cis

EndSub

PrivateSubForm_DblClick()

FontSize=40

FontName=”隸書”

ForeColor=vbRed

Print”熱烈慶祝”

FontSize=60

FontName="宋體"

ForeColor=vbGreen

Print”河南大學運動會召開”

EndSub

2-2

PrivateSubCommand1_Click()

Label1.MoveWidth*Rnd,Height*Rnd

EndSub

2-3

PrivateSubCommand1_Click()

Labell.Visible=True

EndSub

PrivateSubCommand2_Click()

Labell.Visible=False

EndSub

2-4

PrivateSubTimer1_Timer()

Textl.Text=Now

Caption=Textl.Text

EndSub

2-5

PrivateSubTimer1_Timer()

IfBackColor=vbRedThen

BackColor=vbYellow

Else

BackColor=vbRed

EndIf

EndSub

2-6

PrivateSubTimeri_Timer()

IfLabell.Left<Forml.WidthThen

Label1.Left=Label1.Left+200

Else

Label1.Left=-Label1.Left

EndIf

EndSub

2-7

PrivateSubCommand1_Click()

Textl.Visible=True

EndSub

PrivateSubCommand2_Click()

Textl.Visible=False

EndSub

2-8

PrivateSubText1_Change()

Text2.Text=Textl.Text

EndSub

2-9

PrivateSubCommand1_Click()

FontSize=20

FontBold=True

Print”歡迎來到”

Print"河南大學”

EndSub

PrivateSubCommand2_Click()

Cis

EndSub

PrivateSubCommand3_Click()

End

EndSub

2-10

PrivateSubCommand1_Click()

r=Textl.Text

Text2.Text=3.14*2*r

EndSub

PrivateSubCommand2_Click()

Textl.Text=""

Text2.Text=

Textl.SetFocus

EndSub

2-11

PrivateSubForm_Load()

Textl.Text="河南大學歡迎您!”

Textl.FontName="宋體"

Textl.FontSize=50

Textl.BackColor=vbYellow

Textl.ForeColor=vbBlue

EndSub

2-12

DimsAsString

PrivateSubCommand1_Click()

s=Textl.SelText

EndSub

PrivateSubCommand2_Click()

Text2.SelText=s

EndSub

2-13

PrivateSubTimer1_Timer()

IfLabell.Top>-Labell.HeightThen

Labell.Top=Labell.Top-100

Else

Labell.Top=Forml.Height

EndIf

EndSub

3-2

PrivateSubForm_Click()

DimnAsInteger

Randomize

n=lnt((90*Rnd)+10)

Printn

EndSub

3-3

PrivateSubTimeri_Timer()

Cis

Print”河南大學環(huán)境與規(guī)劃學院”

FontSize=lnt(71*Rnd+10)

EndSub

3-4

PrivateSubCommand1_Click()

n=Textl.Text

Text2.Text=Hex(Asc(Right(Text1.Text,1)))

EndSub

PrivateSubCommand2_Click()

Textl.Text=""

Text2.Text="”

Textl.SetFocus

EndSub

3-5

PrivateSubCommand1_Click()

DimmAsDate

m=Textl.Text

n=Date

Text2.Text=n-m

EndSub

PrivateSubCommand2_Click()

Textl.Text=

Text2.Text=""

Textl.SetFocus

EndSub

3-6

DimbAsString

DimnAsString

DimmAsString

PrivateSubCommand1_Click()

m=Left(Text1,1)

n=Right(Text1,1)

b=Mid(Text1,2,1)

Text2.Text=n&b&m

EndSub

PrivateSubCommand2_Click()

Textl.Text=""

Text2.Text=""

Textl.SetFocus

EndSub

3-7

PrivateSubForm_click()

r=InputBox("請輸入字符”)

PrintLeft(r,1)&Mid(r,3,1)&Right(r,1)

EndSub

3-8

PrivateSubTimer1_Timer()

Label1.FontSize=Rnd*40+10

Labell.BackColor=RGB(Rnd*256,Rnd*256,

Rnd*256)

Labell.ForeColor=QBColor(lnt(16*Rnd))

EndSub

3-10

PrivateSubForm_Click()

r!=InputBox("請輸入您的工資:")

a=r\100

b=(r-100*a)\50

c=(r-100*a-b*50)\10

d=(r-100*a-b*50-c*10)\5

e=(r-100*a-b*50-c*10-d*5)\2

f=r-100*a-b*50-c*10-d*5-e*2

Print”您的工資是:“&r

Print”100元張數(shù):n&a

Print”50元張數(shù):"&b

Print”10元張數(shù):"&c

Print”5元張數(shù):"&d

Print”2元張數(shù):"&e

Print」元張數(shù):"&f

EndSub

4-1

PrivateSubCommand1_Click()

DimpAsSingle,rAsSingle,nAsSingle

p=Textl

r=Text2

n=Text3

s=p*(1+r)An

MsgBox”您的本息是:"&Round(s,2)

EndSub

4-2

PrivateSubForm_click()

DimmaxAsSingle,minAsSingle

a!=InputBox("請輸入第一個實數(shù)”)

b!=InputBox("請輸入第二個實數(shù)”)

Ifa>bThen

Printa,b

Else

Printb,a

EndIf

EndSub

4-3

PrivateSubForm_click()

Cis

a!=InputBox("請輸入年份")

IfaMod4=0AndaMod100<>0&aMod400=0

Then

Print”您剛剛輸入的年份為閏年!”

Else

Print”您剛剛輸入的年份不是閏年!”

EndIf

EndSub

4-4

PrivateSubForm_click()

a!=lnputBox("a=H)

b!=lnputBox("b=")

c!=lnputBox(“c=")

d!=b*b-4*a*c

Ifd>=0Then

m!=(-b+Sqr(d))/(2*a)

n!=(-b-Sqr(d))/(2*a)

Print”X1=";m,”X2=";n

Else

r=(-b)/(2*a)

i=Sqr(Abs(-d))/(2*a)

Print"X1=n;r&&Abs(i)&"i“,”二"X2=n;r&

&Abs(i)&"i”

EndIf

EndSub

4-5

PrivateSubCommand1_Click()

Dimx!

x=Textl

Ifx<60Then

Text2="重考!”

Elselfx<70Then

Text2="及格!"

Elselfx<80Then

Text2="中等!”

Elselfx<90Then

Text2="良好!”

Else

Text2=”優(yōu)秀!”

EndIf

EndSub

PrivateSubCommand2_Click()

Textl=

Text2='H,

EndSub

4-6

PrivateSubCommand1_Click()

Dimx!

x=Textl

SelectCasex

CaseIs<60

Text2="重考!"

CaseIs<70

Text2="及格!”

CaseIs<80

Text2="中等!”

CaseIs<90

Text2="良好!"

CaseElse

Text2=”優(yōu)秀!”

EndSelect

EndSub

PrivateSubCommand2_Click()

Textl=

Text2=

EndSub

4-7

DimsAsString

PrivateSubForm_Click()

s=InputBox(”請輸入年齡”)

Ifs<30Then

Print”您的年齡為”;s,7,”請參加長跑運動”

Elselfs<40Then

Print”您的年齡為”;請參加跳繩運動”

Elselfs<50Then

Print”您的年齡為”;s:「請參加競走運動”

Else

Print”您的年齡為”;s,”請參加慢跑運動”

EndIf

EndSub

4-8

PrivateSubForm_Click()

Forn=2To100Step2

Printn;

IfnMod20=0ThenPrint

Nextn

EndSub

4-9

PrivateSubForm_click()

Forn=100To1000

IfnMod3=2AndnMod5=3AndnMod7=2

ThenPrintn;

Nextn

Print

EndSub

4-10

PrivateSubForm_click()

m=0:n=0

Do

r%=InputBox。'請輸入學生成績”)

m=m+r

n=n+1

LoopUntilr=-1

Print”學生平均成績=";(m+1)/(n-1)

EndSub

4-11

PrivateSubForm_click()

DimaAsInteger

DimsAsInteger

a=1

Do

s=s+(-1)A(a+1)*a

a=a+1

LoopUntila>100

Print”1-2+3-4+5-6+…+99-100=";s

EndSub

4-12

PrivateSubForm_Click()

DimnAsInteger

DimmAsInteger

DimsAsInteger

m%=InputBox。'請輸入正整數(shù)”階乘。

n%=InputBox。'請輸入正整數(shù)n(n>=m)",“階乘”)

Form=mTon

t=1

Fori=1Tom

t=t*i

Nexti

s=s+t

Nextm

Print"m!+(m+1)!+...+n!=";s

EndSub

4-13

PrivateSubForm_click()

Dima%

Dimb%

Dimc%

Fora=1To20

Forb=1To20

Forc=1To20

lfa*a+b*b=c*cThen

Printa,b,c

EndIf

Nextc

Nextb

Nexta

EndSub

4-14

PrivateSubForm_click()

Forn=1To500

Fori=1Ton-1

IfnModi=0Thens=s+

Nexti

Ifs=nThenPrinti;

s=0

Nextn

Print

EndSub

4-15

PrivateSubForm_click()

DimiAsInteger

DimnAsLong

n=1

t=1

DoWhilet>0.00001

e=e+1

i=i+1

n=n*i

t=1/n

Loop

Print"e的近似值是";e

EndSub

5—1

PrivateSubForm_Click()

Dimi%,x(1To5)AsString

Fori=LBound(x)ToUBound(x)

x(i)=lnputBox(”x("&i&”)”)

Nexti

Fori=UBound(x)ToLBound(x)Step-1

Printx(i)

Nexti

Print

EndSub

5-2

PrivateSubForm_Click()

Dimi%5s

s=Array(1,2,3,4,5,6,7,8,9,10)

Fori=0To9

Ifs(i)Mod3=0Then

Prints(i);i

Else

Printnu

EndIf

Nexti

Print

EndSub

5-3

OptionBase1

PrivateSubCommand1_Click()

Dimx()

x=Array(1,2,3,4,5,6,7,8,9,10)

t=x(1)

Fori=1To9

x(i)=x(i+1)

Printx(i);

Next

x(10)=t

Printx(i)

EndSub

PrivateSubCommand2_Click()

Dimx()

x=Array(1,2,3,4,5,6,7,8,9,10)

t=x(10)

Fori=9To1Step-1

x(i+1)=x(i)

Nexti

x(1)=t

Fori=1To10

Printx(i);

Nexti

EndSub

5-4

PrivateSubForm_Click()

Dima(5,5)

Fori=1To5

Sum=0

Forj=1To5

a(i,j)=lnt(Rnd*51+10)

Sum=Sum+a(i,j)

Printa(i,j);

Nextj

PrintSum

Nexti

Print

Fori=1To5

Forj=1To5

Ifi=jThenPrinta(i,j);

Nextj

Nexti

Print

EndSub

5-5

PrivateSubForm_Click()

Dima()AsInteger

DimMaxAsInteger,iMaxAsInteger,jMaxAs

Integer

DimMinAsInteger,iMinAsInteger,jMinAsInteger

M=InputBox。'輸入M")

N=lnputBox("輸入N")

ReDima(M,N)

Fori=1ToM

Forj=1ToN

a(i,j)=lnt(Rnd*900)+100

Nextj

Nexti

Fori=1ToM

Forj=1ToN

Printa(i,j);

Nextj

Print

Nexti

Max=a(1,1):Min=a(1,1)

Fori=1ToM

Forj=1ToN

Ifa(i,j)>MaxThenMax=a(i,j):(Max=i:jMax=j

fa(i,j)<MinThenMin=a(i,j):iMin=i:jMin=j

Nextj

Nexti

Print,'Max=n;Max,niMax=H;iMax,MjMax=";jMax

Print"Min^;Min,”iMin=";iMin,njMin=H;jMin

Erasea

EndSub

5-6

PrivateSubForm_Click()

n=lnputBox(,'nH)

ReDima(n,n)

Fori=1Ton

Forj=1Ton

Ifi=jThen

a(i,j)=1

Else

a(i,j)=0

EndIf

Nextj

Nexti

Fori=1Ton

Forj=1Ton

Printa(i,j);

Nextj

Print

Nexti

Erasea

EndSub

5-7

PrivateSubForm_Click()

DimxAsVariant

x=Array(1,2,3,4,5,6,7,8,9,10)

Fori=1To10

Printx(i);

Nexti

Print

Fori=1To7

x(i)=x(i+3)

Printx(i);

Nexti

Print

ReDimPreservex(i)

x=Array(1,2,3,4,5,6,7)

ori=1To7

Printx(i);

Nexti

Print

EndSub

5-8

OptionBase1

PrivateSubCommand1_Click(lndexAsInteger)

SelectCaseIndex

Case1

Text3=Val(Textl)+Val(Text2)

Case2

Text3=Textl-Text2

Case3

Text3=Textl*Text2

Case4

Text3=Textl/Text2

EndSelect

EndSub

6-1

PrivateSubForm_click()

DimxAsSingle

DimyAsSingle

DimzAsSingle

x=lnputBox("請輸入圓柱體的半徑”)

y=lnputBox("請輸入圓柱體的高度”)

volumex,y,z

Print”圓柱體的體積為”;z

EndSub

6-2

窗體模塊

PrivateSubForm_click()

Dima!,b!,c!

a=lnputBox("請輸入圓柱體的半徑”)

b=InputBox。'請輸入圓柱體的高度”)

c=volume(a,b)

Print”圓柱體的體積為”;c

EndSub

標準模塊

Functionvolume(rAsSingle,hAsSingle)AsSingle

volume=3.14*r*r*h

EndFunction

6-3

PrivateSubForm_Click()

Dimy%

y=lnputBox("請輸入一個整數(shù)”)

Callweek(y)

EndSub

6-4

窗體模塊

PrivateSubForm_click()

DimaAsInteger,bAsString

a=lnputBox("請輸入一個整數(shù)”)

b=week(a)

Printb

標準模塊

Functionweek(sAsInteger)AsString

SelectCases

Case0

week="星期H"

Case1

week="星期一"

Case2

week="星期二”

Case3

week="星期三"

Case4

week="星期四”

Case5

week="星期五"

Case6

week="星期六"

CaseElse

MsgBox”數(shù)據(jù)無效”

EndSelect

EndFunction

6-5

窗體模塊

PrivateSubForm_click()

DimnAsSingle,wAsString

n=InputBox("請輸入一個正整數(shù)”)

SelectCasew

Casejudge=0

Print”此數(shù)為偶數(shù)”

CaseElse

Print”此數(shù)為奇數(shù)”

Printw

EndSelect

EndSub

標準模塊

Functionw(nAsSingle)AsString

w=n\2

SelectCasew

Casew=0

Print”此數(shù)為偶數(shù)”

CaseElse

Print”此數(shù)為奇數(shù)”

EndFunction

6-7

SublenUL(ByValsAsString,U%,L%)

DimiAsInteger

Fori=1ToLen(s)

SelectCaseMid(s,i,1)

Case”A”ToZ

U=U+1

Casena"To"z"

L=L+1

EndSelect

Nexti

EndSub

PrivateSubCommand1_Click()

DimU%,L%

CalllenUL(Text1,U,L)

Text2=U

Text3=L

EndSub

PrivateSubCommand2_Click()

Textl=

Text2=

Text3=

Textl.SetFocus

EndSub

7-1

PrivateSubCommand1_Click()

Imagel.Picture=LoadPicture("c:\圖片

\picture5.JPG")

EndSub

PrivateSubCommand2_Click()

Imagel.Picture=LoadPicture("c:\圖片

\picture3.JPG")

EndSub

PrivateSubCommand3_Click()

Imagel.Picture=LoadPicture("c:\圖片

\picture4.JPG")

EndSub

7-2

PrivateSubCommand1_Click()

StaticaAsInteger

a=a+1

IfaMod2<>0Then

Imagel.Picture=LoadPicture("c:\圖片\p2.JPG")

Image2.Picture=LoadPicture("c:\圖片\p1.JPG")

Else

Imagel.Picture=LoadPicture("c:\圖片\p1.JPG")

Image2.Picture=LoadPicture("c:\圖片\p2.JPG")

EndIf

EndSub

PrivateSubForm_Load()

Imagel.Picture=LoadPicture("c:\圖片\p1.JPG")

Image2.Picture=LoadPicture("c:\圖片\p2.JPG")

EndSub

7-3

PrivateSubTimer1_Timer()

Forml.Picture=Image3.Picture

Image3.Picture=Image2.Picture

Image2.Picture=ImagelPicture

Imagel.Picture=Forml.Picture

EndSub

7-4

PrivateSubForm_Load()

Timeri.Enabled=False

EndSub

PrivateSubTimer1_Timer()

Iflmage2.Top>=-Image2.HeightThen

lmage2.Top=lmage2.Top-100

Else

lmage2.Top=-Image2.Height

EndIf

EndSub

7-5

PrivateSubForm_Load()

HScroll1.Min=0

HScrolH.Max=Imagel.Width

Imagel.Width=0

EndSub

PrivateSubHScroll1_Scroll()

Imagel.Width=HScrolH

Label1="當前圖片寬度:"&HScrollLValue

EndSub

7-6

PrivateSubCommand1_Click()

Fori=ProgressBarl.MinToProgressBarl.Max

ProgressBarl.Value=i

(Forj=1To20000

Nextj)(延時)

Nexti

EndSub

7-7

PrivateSubCommand1_Click()

a=llf(Option1,“男”,女)

b=llf(Option3,“碩士“,“博士”)

c=llf(Check1,“音樂”

d=llf(Check2,“演講“,"”)

e=llf(Check3,“體育"

f=llf(Check4,”集郵「”)

Text2="姓名:"&Textl.Text&7&”性別:”&a&7

&”學歷:"&b&7&”特長:"&c&&d&7&e&

7&f

EndSub

PrivateSubCommand2_Click()

Textl=

Text2="n

Textl.SetFocus

EndSub

7-8

PrivateSubForm_Load()

Combol.Additem"河南省"

Combol.Additem"開封市"

Combol.Additem"河南大學"

Combol.Additem"金明校區(qū)”

Combol.Additem”環(huán)境與規(guī)劃學院”

Combol.Additem"09級”

Combol.Additem”地理科學專業(yè)”

Combol.Additem"劉彬"

Combol.Additem"畢業(yè)于"

Combol.Additem”湖南省”

Combol.Additem"衡山縣"

Combol.Additem"第二中學”

Combol.Additem"218班”

EndSub

PrivateSubCombol_Click()

Listl.AdditemCombol.Text

EndSub

PrivateSubList1_DblClick()

Listl.RemoveitemListl.Listindex

EndSub

8-1

DimxAsSingle,yAsSingle

PrivateSubPt1_Click()

Pt1.Scale(0,100)-(100,0)

Pt1.DrawWidth=2

Forx=0To100Step0.02

Ptl.PSet(x,2),vbRed

Nextx

Fory=0To100Step0.02

Ptl.PSet(2,y),vbRed

Nexty

Pt1.CurrentX=2

Ptl.CurrentY=5

Pt1.Print"(0,0)"

EndSub

8-2

PrivateSubP1_Click()

P1.Scale(0,100)-(100,0)

P1.FillStyle=7

P1.DrawWidth=5

P1.FillColor=vbGreen

Pl.Line(10,90)-(90,10),vbRed,B

EndSub

8-3

PrivateSubForm_click()

Scale(-100,100)-(100,-100)

Line(-100,0)-(100,0)

Line(0,-100)-(05100)

CurrentX=2

CurrentY=6

Print”(0,0)”

EndSub

8-4

PrivateSubForm_click()

Scale(-100,100)-(100,-100)

Line(-100,0)-(100,0)

Une(0,-100)-(0,100)

Forx=-100To100Step0.02

y=10*Sin(x)-10*Cos(2*x)

PSet(x,y),vbRed

Nextx

EndSub

8-7

PrivateSubForm_Click()

Timeri.Enabled=True

EndSub

PrivateSubTimeri_Timer()

Randomize

Scale(-120,120)-(120,-120)

DrawWidth=2

Ifr<100Then

r=r+2

Forr=0To100

Circle(0,0),r,RGB(255*Rnd,255*Rnd,255*

Rnd)

Nextr

EndIf

EndSub

9-1

PrivateSubText1_KeyPress(KAsInteger)

K=K+3

EndSub

9-2

PrivateSubText1_KeyPress(KAsInteger)

SelectCaseK

Case48To57

K=K

CaseElse

K=0

EndSelect

EndSub

9-6

PrivateSubCommand1_MouseMove(ButtonAs

Integer,ShiftAsInteger,XAsSingle,YAsSingle)

MousePointer=5

EndSub

PrivateSubText1_MouseMove(ButtonAsInteger,

ShiftAsInteger,XAsSingle,YAsSingle)

MousePointer=11

EndSub

PrivateSubPicture1_Click()

Mouseicon=Picturel.Mouseicon

Picturel.Mouseicon=Imagel.Mouseicon

Imagel.Mouseicon=Forml.Mouseicon

EndSub

9-7

SubForm_MouseMove(ButtonAsInteger,ShiftAs

Integer,XAsSingle,YAsSingle)

IfShift=vbCtrlMaskAndButton=vbLeftButton

ThenPrint”Ctrl+左鍵+移動”

IfShift=vbAltMaskAndButton=vbRightButton

ThenPrint"Alt+右鍵+移動”

EndSub

SubForm_MouseUp(ButtonAsInteger,ShiftAs

Integer,XAsSingle,YAsSingle)

Cis

EndSub

9-8

SubPicture1_MouseMove(ButtonAsInteger,Shift

AsInteger,XAsSingle,YAsSingle)

IfButton=vbLeftButtonThenPicturel.PrintStr(X)+

+Str(Y)

BackColor=RGB(Rnd*256,Rnd*256,Rnd*256)

EndSub

10-1

PrivateSubCommand1_Click()

Open"d:\data1.txt"ForOutputAs#1

Write#1,”601「楊大昌";“4550”

Write#1,“603”,“李文圣“;“3886”

Write#1,“605“,“張燕“;“2235”

Close#1

EndSub

PrivateSubCommand2_Click()

Open"d:\data1.txt'*ForInputAs#2

DoWhileNotEOF(2)

Input#2,X1,X2,x3

PrintX1,X2,x3

Loop

Close

EndSub

10-2

PrivateSubCommand1_Click()

Open"d:\data1.txt"ForAppendAs#3

Write#3,Textl,Text2,Text3

Textl='H,

Text2=

Text3=

Close

EndSub

PrivateSubCommand2_Click()

Close

End

EndSub

10-5

PrivateSubForm_Click()

DimsumAsLong

Forn=1To100Step2

sum=sum+n

Nextn

Printsum

EndSub

PrivateSubForm_Load()

Open"d:\data5.txt"ForOutputAs#1

Forn=1To100Step1

P

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論