怎么实现读取文件内容

rimancool 2003-10-26 12:03:13
文件:a.txt
内容:1000 a
1100 aa
2000 b
两列分别读入两个数组中
...全文
51 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
rimancool 2003-10-26
  • 打赏
  • 举报
回复
比如data1[]中是1000,1100,2000;data2[]中是a,aa,b
没行是一个空格分开两个数据
mmcgzs 2003-10-26
  • 打赏
  • 举报
回复
什么意思,不明白
一个数组不行吗?
taosihai1only 2003-10-26
  • 打赏
  • 举报
回复
dim FileSystemObject,TextStream as Object
dim aryfile() as string
dim strtemp as string
dim intCount as integer
dim datal() as integer
dim data2() as string

set FileSystemObject = createObject("Scripting.FileSystemObject")
set TextStream = fileSystemobject.openTextFile("C:\a.txt")
do while not textstream.AtEndOfStream<> true
strTemp = TextStream.ReadLine
intCount = intCount + 1
ReDim Preserve aryFile(0 To intCount - 1)
aryFile(intCount - 1) = Trim(strTemp)
Loop
TextStream.Close

for i = 0 to intCount -1 step 2
....
next i
for i = 1 to intCount step 2
....
next i
lzywj998 2003-10-26
  • 打赏
  • 举报
回复
用这个也可以:
object.Read(characters)

characters: Required. Number of characters you want to read from the file. (读入的字符数)
lyjlee 2003-10-26
  • 打赏
  • 举报
回复

Private Sub Form_Load()
Dim strTmp As String, strArray() As String, F(10) As Integer, C(10) As String
Dim i As Integer
Open "C:\aa.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strTmp
strArray() = Split(strTmp, " ")
F(i) = strArray(0)
C(i) = strArray(1)

Debug.Print F(i) & vbTab & C(i)
i = i + 1
Loop

Close #1

End Sub
lzywj998 2003-10-26
  • 打赏
  • 举报
回复
这样做吧:
dim FileSystemObject,TextStream as Object
dim aryfile() as string
dim strtemp as string
dim intCount as integer
dim datal() as integer
dim data2() as string

set FileSystemObject = createObject("Scripting.FileSystemObject")
set TextStream = fileSystemobject.openTextFile("C:\a.txt")
do while not textstream.AtEndOfStream<> true
strTemp = TextStream.ReadLine
intCount = intCount + 1
ReDim Preserve aryFile(0 To intCount - 1)
aryFile(intCount - 1) = Trim(strTemp)
Loop
TextStream.Close

for i = 0 to intCount -1 step 2
....
next i
for i = 1 to intCount step 2
....
next i
mingtian2008 2003-10-26
  • 打赏
  • 举报
回复
你是说打开文件吗? 然后读去他到一个 数组中的是吗/
用打开 顺序文件的方式。

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧