t=b
b=c
c=t
EndIf
PrintTab
(2);"降序排序后"
PrintTab(4);a;b;c
Print
PrintTab
(2);"其中最大值为";a
PrintTab
(2);"其中最小值是";c
EndSub
.练习题4.15
PrivateSubCommand1_Click()
s=1
n=Val(Text1)
Fori=1Ton
s=s*i
Nexti
Text2=s
EndSub
PrivateSubCommand2_Click()
s=1
n=Val(Text1)
Fori=1To(n+2)
s=s*i
Nexti
Text3=s
EndSub
练习题4.16
PrivateSubForm_Click()
s=1:
i=1
Whiles<=100000
s=s*i*2
i=i+1
Wend
Text1.Text=s
EndSub
练习4.23
PrivateSubCommand1_Click()
Text1=Int(Rnd*100+1)
Text2=Int(Rnd*100+1)
m=Val(Text1)
n=Val(Text2)
r=mModn
p=m*n
Whiler<>0
m=n
n=r
r=mModn
Wend
Label1.Caption="最大公约数是:
"&n
Label2.Caption="最小公倍数是:
"&p/n
EndSub
练习4.。
24
PrivateSubPicture1_Click()
Picture1.PrintTab(50);"九九乘法表"
Fori=1To9
Forj=1To9
Picture1.PrintTab((j-1)*15);i;"*";j;"=";i*j;
Nextj
Picture1.Print
Nexti
Line1.Visible=True
Line2.Visible=True
EndSub
练习4.25
PrivateSubText4_Change()
EndSub
PrivateSubCommand1_Click()
Picture1.Cls
p="FEDCBA"
Fori=1To6
Picture1.PrintRight(p,i)
Nexti
EndSub
PrivateSubCommand2_Click()
Picture2.Cls
Fori=6To1Step-1
Picture1.PrintTab(7-i);
Forj=1Toi
Picture2.PrintChr(64+j);
Nextj
Picture2.Print
Nexti
EndSub
PrivateSubCommand3_Click()
Fori=1To6
Picture1.PrintTab(7-i);
Forj=iTo1Step-1
Picture3.PrintChr(71-j);
Nextj
Picture3.Print
Nexti
EndSub
PrivateSubCommand4_Click()
Fori=6To1Step-1
Forj=1Toi
Picture4.PrintChr(64+(i-j+1));
Nextj
Picture4.Print
Nexti
EndSub
练习4.27
PrivateSubCommand1_Click()
m=Int(Rnd*101)
Text1.Text=m
EndSub
PrivateSubCommand2_Click()
DimnAsLong,iAsInteger
n=Val(Text1.Text)
Fori=2ToSqr(n)
IfnModi=0ThenExitFor
NextI
Ifi>Sqr(n)Then
Text2.Text="是素数"
Else
Text2.Text="不是素数"
EndIf
EndSub
第五章
5.7
PrivateSubForm_Click()
IfOption1.Value=TrueThenLabel3.FontSize=10
IfOption2.Value=TrueThenLabel3.FontSize=13
IfOption3.Value=TrueThenLabel3.FontSize=15
IfCheck1.Value=1ThenLabel3.FontItalic=True
IfCheck2.Value=1ThenLabel3.FontUnderline=True
IfCheck1.Value=0ThenLabel3.FontItalic=false
IfCheck1.Value=0ThenLabel3.FontItalic=false
EndSub
5.8
PrivateSubOption1_Click()
Shape1.Shape=3
EndSub
PrivateSubOption2_Click()
Shape1.Shape=1
EndSub
PrivateSubOption3_Click()
Shape1.Shape=0
EndSub
PrivateSubOption4_Click()
Shape1.Shape=2
EndSub
5.9
PrivateSubCommand1_Click()
List1.AddItemText1.Text
EndSub
PrivateSubCommand2_Click()
IfList1.SelCount>0Then
List1.RemoveItemList1.ListIndex
Else
MsgBox"请选择要删除的列表项"
EndIf
EndSub
PrivateSubCommand3_Click()
List1.Clear
EndSub
5.10
PrivateSubCombo1_Click()
SelectCaseCombo1.ListIndex
Case0
Text1.ForeColor=vbWhite
Case1
Text1.ForeColor=vbBlack
Case2
Text1.ForeColor=vbRed
Case3
Text1.ForeColor=vbGreen
Case4
Text1.ForeColor=vbBlue
Case5
Text1.ForeColor=vbYellow
EndSelect
EndSub
PrivateSubCombo2_Click()
SelectCaseCombo2.ListIndex
Case0
Text1.BackColor=vbWhite
Case1
Text1.BackColor=vbBlack
Case2
Text1.BackColor=vbRed
Case3
Text1.BackColor=vbGreen
Case4
Text1.BackColor=vbBlue
Case5
Text1.BackColor=vbYellow
EndSelect
EndSub
PrivateSubCombo3_Click()
SelectCaseCombo3.ListIndex
Case0
Text1.Alignment=0
Case1
Text1.Alignment=2
Case2
Text1.Alignment=1
EndSelect
EndSub
5.11
PrivateSubVScroll1_Change()
Label6.Caption=VScroll1.Value
Label5.Caption=(VScroll1.Value)*9/5+32
EndSub
5-14(注意要将计时器的interval属性设为1000)
PrivateSubTimer1_Timer()
StaticiAsInteger
SelectCaseiMod2
Case0
Text1.BackColor=vbRed
Case1
Text1.BackColor=vbGreen
EndSelect
i=i+1
EndSub
练习5.6
PrivateSubCommand1_Click()
Picture1.Picture=LoadPicture("c:
\99ksw\ksm3\house.jpg")
EndSub
PrivateSubCommand2_Click()
Picture1.Picture=LoadPicture("")
EndSub
练习5.8
(在属性窗口将定时器的interval的值改为500)
DimsAsInteger
PrivateSubCommand1_Click()
Timer1.Enabled=True
EndSub
PrivateSubCommand2_Click()
Timer1.Enabled=False
EndSub
PrivateSubForm_Load()
Timer1.Enabled=False
EndSub
PrivateSubTimer1_Timer()
StaticaAsInteger
SelectCases
Case0
Text1.BackColor=vbRed
Case1
Text1.BackColor=vbGreen
Case2
Text1.BackColor=vbBlue
EndSelect
s=s+1
Ifs>2Thens=0
SelectCasea
Case0
Label1.Left=Label1.Left+1000
IfLabel1.Left>=(Form1.Width-Label1.Width)Then
a=1
EndIf
Case1
Label1.Left=Label1.Left-1000
IfLabel1.Left<=0Then
a=0
EndIf
EndSelect
EndSub
练习5.11
PrivateSubList1_DblClick()
Fori=0ToList1.ListCount-1
s=s+Val(List1.List(i))
Nexti
List1.AddItems
EndSub
第六章
6.1
OptionBase1
PrivateSubCommand1_Click()
Cls
ReDima(10)
Fori=1To10
a(i)=Int(90*Rnd+10)
s=s+a(i)
Picture1.Printa(i);
Nexti
Forj=1To10
Fork=jTo10
Ifa(j)u=a(j)
a(j)=a(k)
a(k)=u
EndIf
Nextk
Nextj
Picture1.Print"最大值";a
(1)
Picture1.Print"最小值";a(10)
Picture1.Print"和是";s
Picture1.Print"平均值是";s/10
EndSub
6.3
OptionBase1
Dima()AsInteger
PrivateSubCommand1_Click()
Picture1.Cls