min=a(i
EndIf
Nexti
EndSub
9-2
PrivateSubCommand1_Click(
DimxAsLong
x=Val(Text1.Text
Ifverify(xThen
List1.AddItemx
Else
MsgBoxStr(x&"不是自守数。
",vbInformationEndIf
EndSub
PrivateSubCommand2_Click(
Text1.Text=""
EndSub
PrivateSubCommand3_Click(
End
EndSub
PrivateFunctionverify(xAsLongAsBoolean
DimyAsLong,sAsInteger
verify=False
s=Len(CStr(x
y=x*x
Ifx=Val(Right(CStr(y,sThen
verify=True
EndIf
EndFunction
9-3
OptionExplicit
OptionBase1
PrivateSubCommand1_Click(
DimaAsInteger,bAsInteger,iAsInteger
a=Val(Text1.Text:
b=Val(Text2.Text
Fori=aTob
Ifsx(i=TrueThen
List1.AddItemi
8EndIf
Nexti
IfList1.ListCount=0ThenList1.AddItem"无升序数"EndSub
PrivateSubCommand2_Click(
Text1.Text=""
Text2.Text=""
List1.Clear
Text1.SetFocus
EndSub
PrivateSubCommand3_Click(
End
EndSub
PrivateFunctionsx(ByValnAsIntegerAsBooleanDima(AsInteger,kAsInteger,iAsInteger
Do
k=k+1
ReDimPreservea(k
a(k=nMod10
n=n\10
LoopUntiln<=0
Fori=1ToUBound(a-1
Ifa(i+1>=a(iThenExitFunction
Nexti
sx=True
EndFunction
9-4
OptionExplicit
PrivateSubCommand1_Click(
Text1.Text=""
Text2.Text=""
Text3.Text=""
EndSub
PrivateSubCommand2_Click(
End
EndSub
PrivateFunctioncommon(ByValaAsInteger,ByValbAsIntegerAsIntegerDimrAsInteger
Do
r=aModb
a=b
b=r
LoopWhiler<>0
common=a
EndFunction
PrivateSubOption1_Click(IndexAsInteger
DimaAsInteger,bAsInteger
DimmAsInteger,dAsInteger
a=Text1
b=Text2
m=common(a,b
IfIndex=0Then
Text3=m
Else
d=a*b/m
Text3=d
EndIf
EndSub
9-5
OptionExplicit
PrivateFunctionJudge(nAsIntegerAsBoolean
DimiAsInteger
Fori=2ToSqr(n
IfnModi=0ThenExitFunction
Nexti
Judge=True
EndFunction
PrivateSubCommand1_Click(
DimxAsInteger,iAsInteger
x=Text1.Text
Ifx=4Then
Text2="2+2"
Else
i=3
DoWhileText2=""
IfJudge(iAndJudge(x-iThen
Text2=i&"+"&x-i
Else
i=i+2
EndIf
Loop
EndIf
EndSub
PrivateSubCommand2_Click(
Text1.Text=""
Text2.Text=""
EndSub
PrivateSubCommand3_Click(
End
EndSub
9-6
PrivateFunctionchange(sAsString,nAsIntegerAsStringDimiAsInteger,kAsInteger,sumAsInteger
DimpAsString*1,qAsInteger
k=0
Fori=Len(CStr(Text2.TextTo1Step-1
p=Mid(CStr(Text2.Text,i,1
Ifp>="0"Andp<="9"Then
q=Val(p
Else
q=Asc(p-55
EndIf
sum=sum+q*n^k
k=k+1
Nexti
change=sum
EndFunction
PrivateSubCommand1_Click(
DimsAsString,nAsInteger
Label2.Caption=Text1.Text&"进制数:
"
s=Text1.Text
SelectCases
Case"二"
n=2
Case"八"
n=8
Case"十六"
n=16
EndSelect
Text3.Text=change(s,n
EndSub
PrivateSubCommand2_Click(
Text1.Text=""
Text2.Text=""
Text3.Text=""
EndSub
PrivateSubCommand3_Click(
End
EndSub
9-7
OptionExplicit
PrivateSubCommand1_Click(
DimnAsLong
n=Text1.Text
IfRight(CStr(n,1="0"Then
Text2="尾数为0,无反序数"
Else
Text2.Text=nx(n
EndIf
EndSub
PrivateSubCommand2_Click(
Text1.Text=""
Text2.Text=""
EndSub
PrivateSubCommand3_Click(
End
EndSub
PrivateFunctionnx(nAsLongAsLong
DimkAsInteger,stAsString
Do
k=k+1
st=Mid(CStr(n,k,1&st
LoopUntilk>=Len(Text1.Text
nx=Val(st
EndFunction
9-8
PrivateSubCommand1_Click(
DimnAsInteger,iAsInteger,sAsString,a(AsInteger
Forn=153To9999
Ifarm(n=TrueThen
ReDima(Len(CStr(n
Fori=1ToLen(CStr(n
a(i=Mid(CStr(n,i,1
Nexti
s=""
Fori=1ToLen(CStr(n-1
s=s&CStr(a(i&"^"&CStr(Len(CStr(n&"+"
Nexti
List1.AddItemCStr(n&"="&s&CStr(a(i&"^"&CStr(Len(CStr(nEndIf
Nextn
EndSub
End
EndSub
PrivateFunctionarm(nAsIntegerAsBoolean
Dima(AsInteger,iAsInteger,stAsString,sumAsInteger
arm=False
st=CStr(n
ReDima(Len(st
Fori=1ToLen(st
a(i=Mid(st,i,1
Nexti
Fori=1ToLen(st
sum=Val(a(i^(Len(st+sum
Nexti
Ifn=sumThen
arm=True
Else
ExitFunction
EndIf
EndFunction
9-9
Dimsco(5AsSingle
PrivateSubCommand1_Click(
DimiAsInteger
Fori=0To5
sco(i=(Int(Rnd*61+40/10
Text1(i.Text=sco(i
Nexti
EndSub
PrivateSubCommand2_Click(
DimiAsInteger,sumAsInteger,minAsSingle,maxAsSingleCalla(min,max
Fori=0To5
sum=sum+sco(i
Nexti
Text7.Text=(sum-min-max/4
EndSub
PrivateSuba(minAsSingle,maxAsSingle
DimiAsInteger,kAsInteger
max=sco(0:
min=sco(0
Fori=1To5
Ifsco(i>maxThen
max=sco(i
ElseIfsco(imin=sco(i
EndIf
Nexti
EndSub
Fori=0To5
Text1(i=""
Nexti
Text7.Text=""
EndSub
PrivateSubCommand4_Click(
End
EndSub
9-10
PrivateSubCommand1_Click(
DimmaxAsLong,minAsLong
Callat(max,min
Text2.Text=max
Text3.Text=min
EndSub
PrivateSubCommand2_Click(
Text1.Text=""
Text2.Text=""
Text3.Text=""
EndSub
PrivateSubCommand3_Click(
End
EndSub
PrivateSubat(maxAsLong,minAsLong
DimsAsString,iAsInteger,a(AsInteger,kAsInteger,tempAsInteger,stAsString,st1AsStrings=CStr(Text1.Text
ReDima(Len(s
Fori=1ToLen(s
k=k+1
a(k=Val(Mid(s,i,1
Nexti
max=a(1:
min=a(1
Fori=1ToLen(s
Forj=1ToLen(s
Ifa(itemp=a(i
a(i=a(j
a(j=temp
EndIf
Nextj
Nexti
Ifa(1=0Then
Fori=2ToLen(s
Ifa(i<>0ThenExitFor
Nexti
temp=a(i
a(i=a(1
a(1=temp
EndIf
Fori=1ToLen(s
st=st&a(i
Nexti
min=Val(st
Fori=1ToLen(s
Forj=1ToLen(s
Ifa(i>a(jThen
temp=a(i
a(i=a(j
a(j=temp
EndIf
Nextj
Nexti
Fori=1ToLen(s
st1=st1&a(i
Nexti
max=Val(st1
EndSub
7-2
OptionExplicit
OptionBase1
PrivateSubCommand1_Click(
Dima(20AsInteger,iAsInteger,stAsString
DimmaxAsInteger,minAsInteger,maxpAsInteger,minpAsIntegerFori=1To20
a(i=Int(Rnd*(100-1+1+1
st=st&Str(a(i
IfiMod10=0Thenst=st&vbCrLf
Nexti
Text1.Text=st
max=a(1:
min=a(1
maxp=1:
minp=1
Fori=2To20
Ifa(i>maxThen
max=a(i
maxp=i
ElseIfa(imin=a(i
minp=i
EndIf
Nexti
Text2.Text=max&"位置是"&maxp
Text3.Text=min&"位置是"&minp
EndSub
PrivateSubCommand2_Click(
Text1.Text=""
Text2.Text="":
Text3.Text=""
EndSub
PrivateSubCommand3_Click(
End
EndSub
7-5
PrivateSubcmdExit_Click(
UnloadMe
EndSub
PrivateSubcmdJudge_Click(
DimmAsInteger,iAsInteger,jAsInteger,sumAsIntegerDima(
m=Text1.Text
Fori=1Tom/2
IfmModi=0Then
sum=sum+i
j=j+1
ReDimPreservea(j
a(j=i
EndIf
Nexti
Ifm=sumThen
Picture1.Printm&"是完数,因为"
Picture1.Printm;"=";
Fori=1ToUBound(a-1
Picture1.Printa(i;"+";
Nexti
Picture1.Printa(i
Else
Picture1.Printm&"不是完数"
EndIf
EndSub
PrivateSubcmdNext_Click(
Picture1.Cls
Text1.Text=""
Text1.SetFocus
EndSub
7-6
OptionExplicit
OptionBase1
PrivateSubCommand1_Click(
Dimfn(AsInteger,iAsInteger,kAsInteger
DimjAsInteger,stAsString
Fori=10To50
k=0
Forj=1Toi-1
IfiModj=0Then
k=k+1
ReDimPreservefn(k
fn(k=j
EndIf
Nextj
IfUBound(fn=3Then
st=i&":
"
Forj=1ToUBound(fn-1
st=st&fn(j&","
Nextj
List1.AddItemst&fn(j
EndIf
Nexti
EndSub
PrivateSubCommand2_Click(
List1.Clear
EndSub
7-7
PrivateSubCommand1_Click(
Dimword(AsString,SAsString
DimnAsInteger,kAsInteger,maxwAsStringS=Text1.Text
Do
n=InStr(S,""
Ifn<>0Then
k=k+1
ReDimPreserveword(k
word(k=Left(S,n-1
List1.AddItemword(k
S=Right(S,Len(S-n
EndIf
LoopUntiln=0
ReDimPreserveword(k+1
word(k+1=Left(S,Len(S-1
List1.AddItemword(k+1
maxw=word(k+1
Forn=2ToUBound(word
IfLen(word(n>Len(maxwThen
maxw=word(n
EndIf
Nextn
Text2.Text=maxw
EndSub
PrivateSubCommand2_Click(
Text1.Text=""
Text2.Text=""
List1.Clear
Text1.SetFocus
EndSub
PrivateSubCommand3_Click(EndEndSub7-9OptionBase1PrivateSubCommand1_Click(DimrndArray(10AsIntegerDimiAsInteger,jAsInteger,tempAsIntegerRandomizePicture1.Print"排序前:
"Fori=1To10rndArray(i=Int(90*Rnd+10Picture1.PrintrndArray(i;NextiFori=1To9Forj=1To9IfrndArray(j>rndArray(j+1Thentemp=rndArray(jrndArray(j=rndArray(j+1:
rndArray(j+1=tempEndIfNextjNextiPicture1.PrintPicture1.Print"排序后:
"Fori=1To10Picture1.PrintrndArray(i;NextiPicture1.PrintEndSubPrivateSubCommand2_Click(Picture1.ClsEndSubPrivateSubCommand3_Click(EndEndSub