【VB开源代码栏目提醒】:网学会员在VB开源代码频道为大家收集整理了Ex14_3.frm提供大家参考,希望对大家有所帮助!
VERSION 5.00
Begin VB.Form Ex14_3
Caption = "顺序文件的读操作"
ClientHeight = 3285
ClientLeft = 60
ClientTop = 450
ClientWidth = 4530
LinkTopic = "Form1"
ScaleHeight = 3285
ScaleWidth = 4530
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "Input函数"
Height = 375
Left = 3240
TabIndex = 3
Top = 2640
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "Line Input#语句"
Height = 375
Left = 1440
TabIndex = 2
Top = 2640
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "Input#语句"
Height = 375
Left = 240
TabIndex = 1
Top = 2640
Width = 1095
End
Begin VB.PictureBox Picture1
Height = 2055
Left = 480
ScaleHeight = 1995
ScaleWidth = 3435
TabIndex = 0
Top = 360
Width = 3495
End
End
Attribute VB_Name = "Ex14_3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Base 1
Private Sub Command1_Click()
Const N = 5
Const m = 5
Dim Mat(m, N)
Dim i, j
Open App.Path & "\" & "Ex14_3.txt" For Input As #1 '打开文件
For i = 1 To N
For j = 1 To m
Input #1, Mat(i, j) '读取文件中的各个数据
Next j
Next i
Close #1 '关闭文件
Picture1.Print
Picture1.Print "Mat矩阵为:"
Picture1.Print
For i = 1 To N
For j = 1 To m
Picture1.Print Tab(5 * j); Mat(i, j); '打印数据中的各元素值
Next j
Picture1.Print
Next i
Picture1.Print
End Sub
Private Sub Command2_Click()
Dim Lines, NextLine As String
Picture1.Cls
Open "c:\Myfile1.dat" For Input As #1 '打开Myfile1.dat文件
Do Until EOF(1) '判断是否到文件结尾
Line Input #1, NextLine '读取一行
Lines = Lines + NextLine + Chr(13) + Chr(10) '用回车换行符连接各行字符串
Loop
Close #1
Picture1.Print Lines '打印文件内容
End Sub
Private Sub Command3_Click()
Dim InputData As String
Dim str As String
Open "c:\Myfile2.dat" For Input As 1 '打开文件
Do While Not EOF(1)
InputData = Input(1, #1) '读取一个字符
str = str + InputData '将字符连接到str字符串str之后
Loop
Close #1 '关闭文件
Picture1.Print str '打印结果
End Sub
上一篇:
Ex14_2.frm
下一篇:
数控回转工作台设计 毕业设计word2003