vb 部分课件整理.docx
《vb 部分课件整理.docx》由会员分享,可在线阅读,更多相关《vb 部分课件整理.docx(26页珍藏版)》请在冰豆网上搜索。
vb部分课件整理
Typesalary
nameAsString*8'姓名,定长字符串
salaryAsLong'工资
EndType
PrivateSubForm_Load()
DimsalAssalary
DimnoAsString*3,recnoAsInteger
Open"data2.dat"ForRandomAs#1Len=Len(sal)
Fori=1To5
s$="输入第"+Str(i)+"个职工的"
no=InputBox(s$+"编号")
sal.name=InputBox(s$+"姓名")
sal.salary=Val(InputBox(s$+"工资"))
recno=Val(no)'记录号
Put#1,recno,sal'存入记录
Nexti
Close#1
End
EndSub
Typesalary
nameAsString*8salaryAsLong
EndType'recno表示记录号
PublicsalAssalary,recnoAsInteger'检查编号的通用过程
Functioncheno(noAsString)AsBoolean
recno=Val(no)
Ifrecno<0Orrecno>999Then
MsgBox"输入的职工号超出范围",0,"检查编号"
cheno=True
Else
cheno=False
EndIf
EndFunction
PrivateSubForm_Load()
Open"data2.dat"ForRandomAs#1Len=Len(sal)
Get#1,1,sal
Text1.Text=Format(1,"000")
Text2.Text=sal.name
Text3.Text=sal.salary
EndSub
'"查询"按钮的click事件过程
PrivateSubCommand1_Click()
Ifcheno(Text1.Text)ThenExitSub
Ifrecno>LOF
(1)/Len(sal)Then
MsgBox"无此记录"
ExitSub
EndIf
Get#1,recno,sal
Text2.Text=sal.name
Text3.Text=Str(sal.salary)
Text1.SetFocus'设置焦点
EndSub
'"增加"按钮的click事件过程
PrivateSubCommand2_Click()
Ifcheno(Text1.Text)ThenExitSub
sal.name=Text2.Text
sal.salary=Val(Text3.Text)
Put#1,recno,sal
Text1.SetFocus
EndSub
'"清除"按钮的click事件过程
PrivateSubCommand3_Click()
Ifcheno(Text1.Text)ThenExitSub
Ifrecno>LOF
(1)/Len(sal)Then
MsgBox"无此记录"
ExitSub
EndIf
sal.name=""'记录内容清空
sal.salary=0
Text2.Text=""'文本框清空
Text3.Text=""
Put#1,recno,sal
Text1.SetFocus
EndSub'"关闭"按钮的click事件过程
PrivateSubCommand4_Click()
Close#1
UnloadMe
EndSub
PrivateTypenumval
squreAsInteger
cubeAsLong
sqrootAsSingle
EndType
DimnvAsnumval'定义一个numval类型的变量nu
PrivateSubForm_Load()
Open"data1.dat"ForRandomAs#1Len=Len(nv)
Fori=1To10'写入记录程序段
nv.squre=i*i
nv.cube=i*i*i
nv.sqroot=Sqr(i)
Put#1,i,nv
Nexti
Show'读出记录程序段
Fori=2To10Step4'读出3个记录
Get#1,i,nv
Print"第";i;"号记录:
",nv.squre,nv.cube,nv.sqroot
Nexti
Close#1
EndSub
PrivateSubForm_Load()
Show
Open"mytxt.txt"ForOutputAs#1
a=1234:
b$="ABCD"
Print#1,a,b$'写入第1个记录
Print#1,a;b$'写入第2个记录
Close#1
Open"mytxt.txt"ForInputAs#1
LineInput#1,x$'读出第1个记录
Printx$
LineInput#1,x$'读出第2个记录
Printx$
Close#1
EndSub
PrivateSubCommand1_Click()
Open"c:
\mydocuments\cj2.txt"ForInputAs#1
'Open"d:
\temp\cj2.txt"ForInputAs#1
DimnAsString,mAsString,sAsInteger
DimxAsString,tAsInteger,cAsInteger
t=0:
c=5
Fori=1Toc
Input#1,n,m,s
x=n+String(2,32)+m+Str(s)
List1.AddItemx
t=t+s
Nexti
Close#1
Text1.Text=t/5
EndSub
PrivateSubForm_Load()
Show
k=0
Open"num2.txt"ForInputAs#1
DoWhileNotEOF
(1)'文件未结束时,循环
Input#1,x
Printx,
k=k+1
IfkMod4=0ThenPrint'每显示4个数后换行
Loop
Close#1
EndSub
PrivateSubForm_Load()
Show
Open"data1.txt"ForOutputAs#1
a=1234:
b$="ABCD"
Write#1,a,b$'存入
Close#1
Open"data1.txt"ForInputAs#1
Input#1,c,d$'读出
Close#1
Printc,d$
EndSub
PrivateSubForm_Load()
Open"c:
\mydocuments\cj2.txt"ForOutputAs#1
'Open"d:
\temp\cj2.txt"ForOutputAs#1
EndSub
PrivateSubCommand1_Click()
DimnumAsString*6,nameAsString*8,scoreAsInteger
num=Text1.Text
name=Text2.Text
score=Val(Text3.Text)
Write#1,num,name,score'存入记录
Text1.Text=""'存完1个记录后清空
Text2.Text=""
Text3.Text=""
Text1.SetFocus'设置焦点
EndSub
PrivateSubCommand2_Click()
Close#1
End
EndSub
PrivateSubForm_Load()
Open"num2.txt"ForAppendAs#1
Fori=51To200
IfiMod7=0ThenWrite#1,i
Nexti
Close#1
UnloadMe
EndSub
PrivateSubForm_Load()
Open"num1.txt"ForOutputAs#1
Open"num2.txt"ForOutputAs#2
Fori=1To50
Write#1,i
IfiMod7=0ThenWrite#2,i
Nexti
Close#1,#2
UnloadMe
EndSub
DimaxAsSingle,ayAsSingle
DimpxAsSingle,pyAsSingle
DimtempAsInteger
PrivateSubForm_Load()
Picture2.BackColor=RGB(VScroll1(0).Value,VScroll1
(1).Value,VScroll1
(2).Value)
ax=0
ay=0
px=0
py=0
EndSub
PrivateSubOption1_Click()
temp=1
Label2.Caption="按下鼠标左键并拖动到终点绘直线"
EndSub
PrivateSubOption2_Click()
temp=2
Label2.Caption="按下鼠标左键并拖动绘矩形"
EndSub
PrivateSubOption3_Click()
temp=3
Label2.Caption="按下鼠标左键并拖动绘圆"
EndSub
PrivateSubOption4_Click()
temp=4
Label2.Caption="按下鼠标左键并拖动绘曲线"
EndSub
PrivateSubPicture1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfButton=1Then
ax=X
ay=Y
EndIf
Iftemp=4Then
Picture1.CurrentX=X
Picture1.CurrentY=Y
EndIf
EndSub
PrivateSubPicture1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
Iftemp=1Then
Picture1.Line(ax,ay)-(px,py),Picture1.BackColor
EndIf
Iftemp=2Then
Picture1.Line(ax,ay)-(ax,py),Picture1.BackColor
Picture1.Line(ax,ay)-(px,ay),Picture1.BackColor
Picture1.Line(px,ay)-(px,py),Picture1.BackColor
Picture1.Line(ax,py)-(px,ay),Picture1.BackColor
EndIf
Iftemp=3Then
Picture1.Circle((ax+px)/2,(ax+py)/2),0.5*Sqr((px-ax)^2+(py-ay)^2),Picture1.BackColor
EndIf
IfButton=1Then
Iftemp=1Then
Picture1.Line(ax,ay)-(X,Y)
px=X
py=Y
EndIf
Iftemp=2Then
Picture1.Line(ax,ay)-(X,ay)
Picture1.Line(ax,ay)-(ax,Y)
Picture1.Line(ax,Y)-(X,Y)
Picture1.Line(X,ay)-(X,Y)
px=X
py=Y
EndIf
Iftemp=3Then
Picture1.Circle((ax+X)/2,(ay+Y)/2),0.5*Sqr((X-ax)^2+(Y-ay)^2)
px=X
py=Y
EndIf
Iftemp=4Then
Picture1.Line-(X,Y)
px=X
py=Y
EndIf
EndIf
EndSub
PrivateSubPicture1_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfButton=1Then
Iftemp=1Then
Picture1.Line(ax,ay)-(X,Y)
Else
Iftemp=2Then
Picture1.Line(ax,ay)-(X,ay)
Picture1.Line(ax,ay)-(ax,Y)
Picture1.Line(ax,Y)-(X,Y)
Picture1.Line(X,ay)-(X,Y)
Else
Iftemp=3Then
Picture1.Circle((ax+X)/2,(ay+Y)/2),0.5*Sqr((X-ax)^2+(Y-ay)^2)
EndIf
EndIf
EndIf
ax=0
ay=0
px=0
py=0
EndIf
EndSub
PrivateSubPicture1_Resize()
Picture1.Refresh
EndSub
PrivateSubVScroll1_Change(IndexAsInteger)
Picture1.ForeColor=RGB(VScroll1(0).Value,VScroll1
(1).Value,VScroll1
(2).Value)
Picture2.BackColor=RGB(VScroll1(0).Value,VScroll1
(1).Value,VScroll1
(2).Value)
EndSub
DimxAsSingle,yAsSingle
ConstpiAsDouble=3.1415926
PrivateSubCommand1_Click()
Timer1.Enabled=True
EndSub
PrivateSubForm_Load()
Form1.Scale(-10,10)-(10,-10)
Me.Line(-10,0)-(10,0)
Me.Line(0,10)-(0,-10)
CurrentX=-2*pi:
CurrentY=0:
Print"-2π"
CurrentX=-pi:
CurrentY=0:
Print"-π"
CurrentX=0.1:
CurrentY=0”Print"0":
CurrentX=pi:
CurrentY=0:
Print"π"
CurrentX=2*pi:
CurrentY=0:
Print"2π":
x=-10:
y=-10:
EndSub
PrivateSubTimer1_Timer()
x=x+0.01
y=y+0.01
PSet(x,y)
EndSub
DimxAsSingle,yAsSingle
ConstpiAsDouble=3.1415926
PrivateSubCommand1_Click()
Timer1.Enabled=True
EndSub
PrivateSubForm_Load()
Form1.Scale(-10,10)-(10,-10)
Me.Line(-10,0)-(10,0)
Me.Line(0,10)-(0,-10)
CurrentX=-2*pi
CurrentY=0
Print"-2π"
CurrentX=-pi
CurrentY=0
Print"-π"
CurrentX=0.1
CurrentY=0
Print"0"
CurrentX=pi
CurrentY=0
Print"π"
CurrentX=2*pi
CurrentY=0
Print"2π"
x=-10
y=-10
EndSub
PrivateSubTimer1_Timer()
x=x+0.01
y=y+0.01
PSet(x,y)
EndSub
OptionExplicit
PrivateSubOption1_Click(IndexAsInteger)
SelectCaseIndex
Case0
Shape1.BorderColor=vbRed
Case1
Shape1.BorderColor=vbGreen
Case2
Shape1.BorderColor=vbBlue
EndSelect
EndSub
PrivateSubOption2_Click(IndexAsInteger)
SelectCaseIndex
Case0
Shape1.FillColor=vbRed
Case1
Shape1.FillColor=vbGreen
Case2
Shape1.FillColor=vbBlue
EndSelect
EndSub
PrivateSubOption3_Click(IndexAsInteger)
SelectCaseIndex
Case0
Shape1.Shape=vbShapeCircle
Case1
Shape1.Shape=vbShapeOval
Case2
Shape1.Shape=vbShapeRectangle
EndSelect
EndSub
OptionExplicit
Dimarlph
Constpi=3.14159265
PrivateSubCommand1_Click()
Line1.X2=0
Line1.Y2=1.2
arlph=pi/2
Timer1.Enabled=True
EndSub
PrivateSubCommand2_Click()
Timer1.Enabled=False
EndSub
PrivateSubForm_Load()
Picture1.Scale(-2,2)-(2,-2)
Line1.X1=0
Line1.Y1=0
Line1.X2=0
Line1.Y2=1.2
arlph=pi/2
EndSub
PrivateSubTimer1_Timer()
arlph=arlph-360/60*pi/180
Line1.X2=1.2*Cos(arlph)
Line1.Y2=1.2*Sin(arlph)
EndSub
OptionExplicit
PrivateSubForm_Click()
Dimt
Dimx
Dimy
Form1.Scale(-1,1)-(1,-1)
DrawWidth=2
Fort=0To2*3.1415926Step0.001
x=Sin(2*t)*Cos(t)
y=Sin(2*t)*Sin(t)
PSet(x,y),QBColor
(2)
CallWait
Nextt
EndSub
PrivateSubWait()
DimxAsInteger
x=10000
Whilex
x=x-1
Wend
EndSub
PrivateSubCommand1_Click()
'CommonDialog1.Action=1
CommonDialog1.ShowOpen
Image1.Picture=LoadPicture(CommonDialog1.FileName)
EndSub
PrivateSubCommand1_Click()
CommonDialog1.ShowColor
Text1.ForeColor=CommonDialog1.Color
EndSub
PrivateSubCommand2_Click()
CommonDialog1.ShowColor
Text1.BackColor=CommonDialog1.Color
EndSub
PrivateSubCommand3_Click()
CommonDialog1.Flags=cdlCFBothOrcdlCFEffects
CommonDialog1.ShowFont
Text1.FontName=CommonDialog1.FontName
Text1.FontSize=CommonDialog1.FontSize
Text1.FontBold=CommonDialog1.FontBold
Text1.FontItalic=CommonDialog1.FontItalic
Text1.FontStrikethru=