实验8-3
VB程序题:设计一个如图2.8.4所示的应用程序,要求如下:
(1.)单击“打开文件”按钮弹出一个通用对话框,选择文件后显示在文本框中
(2).单击“保存文件”按钮后弹出通用对话框,确定文件名后保存。
(3) 单击“查找下一个”按钮后在文本文件中查找单词“VB”,找到后以高亮度显示。
解题,画4个按钮,1个文本框控件,再加上一个通用对话框控件,代码如下:
Private Sub Command1_Click()
CommonDialog1.Action = 1
Text1.Text = ""
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
Text1.Text = Text1.Text & inputdata & vbCrLf
Loop
Close #1
End Sub
Private Sub Command2_Click()
CommonDialog1.FileName = "Default.Txt"
CommonDialog1.DefaultExt = "Txt"
CommonDialog1.Action = 2
Open CommonDialog1.FileName For Output As #1
Print #1, Text1.Text
Close #1
End Sub
Private Sub Command3_Click()
Static j%
Text1.SetFocus
j = InStr(j + 1, Text1, "VB")
If j > 0 Then
Text1.SelStart = j - 1
Text1.SelLength = 2
j = j + 1
Else:
MsgBox "找不到!"
End If
End Sub
Private Sub Command4_Click()
End
End Sub