VB程序实训报告
任务一,简易记事本:
其主要功能是对文本的打开、保存,对文字的编辑等。其界面如下图所示:
其主要实现该功能的主要代码如下:
Option Explicit
Dim Where As Integer Dim Length As Integer
Private Sub munc_Click() Clipboard.Clear
Clipboard.SetText Text1.SelText End Sub
Private Sub muncolour_Click() CommonDialog1.ShowColor
Text1.ForeColor = CommonDialog1.Color End Sub
Private Sub munf_Click()
CommonDialog1.Flags = cdlCFScreenFonts CommonDialog1.ShowFont
6
VB程序实训报告
Text1.Font = CommonDialog1.FontName Text1.FontSize = CommonDialog1.FontSize Text1.FontBold = CommonDialog1.FontBold End Sub
Private Sub munnew_Click() MsgBox \创建文件成功!\Text1.Text = \End Sub
Private Sub munopen_Click() Dim temp As String Dim all As String
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1 Do While Not EOF(1) Input #1, temp
all = all & temp & Chr(13) & Chr(10) Loop Close #1
Text1.Text = all End Sub
Private Sub munprint_Click() CommonDialog1.ShowPrinter
End Sub
Private Sub munsave_Click()
CommonDialog1.Filter = \文档文件(*.txt)|*.txt|所有文件(*.*)|*.*\CommonDialog1.ShowSave
If CommonDialog1.FileName = \ Open CommonDialog1.FileName For Output As #1 Print #1, Text1.Text Close #1
MsgBox \保存成功!\End Sub
Private Sub munt_Click() Dim l As Integer Clipboard.Clear
Clipboard.SetText Text1.SelText l = Len(Text1.Text)
Text1.Text = Left(Text1.Text, Where) & Right(Text1.Text, l - Where - Length)
7
VB程序实训报告
Text1 = \End Sub
Private Sub munv_Click() Dim l As Integer l = Len(Text1.Text) Where = Text1.SelStart
Text1.Text = Left(Text1.Text, Where) & Clipboard.GetText() & Right(Text1.Text, 1 - Where) End Sub
Private Sub Text1_LostFocus() Where = Text1.SelStart Length = Text1.SelLength End Sub
Private Sub Timer1_Timer()
StatusBar1.Panels(1) = \当前时间:\StatusBar1.Panels(2) = Now
End Sub
任务二:多媒体播放器:
主要是实现对mp3和视频的播放,其界面如下图所示:
其主要实现代码如下:
8
VB程序实训报告
Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub
Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub
Private Sub File1_Click()
WindowsMediaPlayer1.URL = File1.Path & \Text1.Text = File1.FileName End Sub
任务三,简易计算器:
其主要功能是实现对数据的基本运算,其界面如下图所示:
其主要代码如下:
Dim ct1 As Integer Dim ct2 As Integer Dim n As Single
Dim beiss As Boolean
Private Sub Cmd_Click() Text1.Text = 0 End Sub
Private Sub Cmd0_Click()
If Val(Text1.Text) <> 0 Then Text1.Text = Text1.Text & 0 If beiss = True Then Text1 = 0: beiss = False
9
VB程序实训报告
End Sub
Private Sub Cmd1_Click() Text1 = Val(Text1 & 1)
If beiss = True Then Text1 = 1: beiss = False End Sub
Private Sub Cmd2_Click() Text1 = Val(Text1 & 2)
If beiss = True Then Text1 = 2: beiss = False End Sub
Private Sub Cmd3_Click() Text1 = Val(Text1 & 3)
If beiss = True Then Text1 = 3: beiss = False End Sub
Private Sub Cmd4_Click() Text1 = Val(Text1 & 4)
If beiss = True Then Text1 = 4: beiss = False End Sub
Private Sub Cmd5_Click() Text1 = Val(Text1 & 5)
If beiss = True Then Text1 = 5: beiss = False End Sub
Private Sub Cmd6_Click() Text1 = Val(Text1 & 6)
If beiss = True Then Text1 = 6: beiss = False End Sub
Private Sub Cmd7_Click() Text1 = Val(Text1 & 7)
If beiss = True Then Text1 = 7: beiss = False End Sub
Private Sub Cmd8_Click() Text1 = Val(Text1 & 8)
If beiss = True Then Text1 = 8: beiss = False End Sub
Private Sub Cmd9_Click() Text1 = Val(Text1 & 9)
If beiss = True Then Text1 = 9: beiss = False End Sub
Private Sub CmdOK_Click() If Label1.Caption = \
Text1.Text = n + Val(Text1.Text) End If
If Label1.Caption = \
Text1.Text = n - Val(Text1.Text) End If
10