上面是程序运行的界面!(程序运行界面已上传到相册的VB6栏目)
以下就是VB6的源代码:
依次添加5个按钮控件,一个timer控件和一个microsoft common dialog control 6.0控件
Private Sub Command1_Click() '输入文字
Dim n%
On Error Resume Next ' 如果出现错误,不理它
n = InputBox("你想输入几段文字?")
For i = 1 To n
temp = InputBox("请输入第" + Str(i) + "段文字,共有" + Str(n) + "段")
Text1 = Text1 & temp & vbCrLf 'Vbcrlf有回车换行的功能,CR回车,LF换行
x = DoEvents '在FOR循环过大时,此句可避免死机
Next
End Sub
Private Sub Command2_Click()
CommonDialog1.Action = 3 '选择颜色
Text1.BackColor = CommonDialog1.Color
End Sub
Private Sub Command3_Click()
On Error Resume Next
CommonDialog1.Flags = 259
CommonDialog1.Action = 4 '选择字体
With Text1 '用此句可省略前辍
.FontName = CommonDialog1.FontName
.FontBold = CommonDialog1.FontBold
.FontItalic = CommonDialog1.FontItalic
.FontSize = CommonDialog1.FontSize
.FontStrikethru = CommonDialog1.FontStrikethru
.FontUnderline = CommonDialog1.FontUnderline
.ForeColor = CommonDialog1.Color
End With
End Sub
Private Sub Command4_Click()
On Error Resume Next
CommonDialog1.Filter = "记事本类型.txt|*.txt|word文档.word|*.doc|all files.*|*.*"
CommonDialog1.Action = 2
Open CommonDialog1.FileName For Output As #1 '以读方式自动创建不存在的新文件
Print #1, Text1
Close #1
End Sub
Private Sub Command5_Click()
If CommonDialog1.FileName = "" Then
MsgBox ("你还没有保存文件,请先保存,再退出!")
Else
End
End If
End Sub
Private Sub Form_Load()
Text1.FontSize = 12
End Sub
Private Sub Form_Unload(Cancel As Integer)
If CommonDialog1.FileName = "" Then
MsgBox "你还没有保存文件,请先保存,再退出!"
Cancel = 1
Else
End
End If
End Sub
Private Sub Timer1_Timer() ‘在属性窗口中将timer1的interval值为1000(ms)
Me.Caption = "小型记事本(made by keenweiwei) 现在时间:" + Str(Now)
End Sub