标题:求助:vb读取txt数据文件中具体数据
只看楼主
fuyong922
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-5-3
得分:0 
大哥是南京人?我在南京找好工作,等我到南京请你吃饭!!
2006-05-06 10:33
风沙雪雨
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2006-5-4
得分:0 
Function readfile(seekid As Integer, fileid As Integer, hao As Integer) As String
'seekid是功能码用来说明本次是何操作
'fileid是文件号说明要对哪个文件进行操作
'hao:备用说明,在seekid为5或2指明要前进或后退多少,0为退2,1就是退3或进1(两行就是进2)
Dim st As String
Dim sa As String * 1
Dim sb As String * 1
Select Case seekid
Case 0
'get next
If Seek(fileid) >= LOF(fileid) Then
readfile = "seek_end"
Exit Function
End If
Do While 1
Get #fileid, , sa
If sa = Chr(16) Then
Get #fileid, , sb
If sb = Chr(17) Then
readfile = st
Seek #fileid, Seek(fileid) + 2
Exit Function
Else
Seek #fileid, Seek(fileid) - 1
End If
End If
st = st & sa
If Seek(fileid) >= LOF(fileid) Then
readfile = st
Exit Function
End If
Loop
Case 1
' go top
Seek #fileid, 1
readfile = readfile(0, fileid, 0)
Exit Function
Case 2
' go -1
If Seek(fileid) = 1 Then
readfile = readfile(0, fileid, 0)
Exit Function
End If
Dim ba As Byte
Dim bb As Byte
Dim bc As Byte
Dim bd As Byte
bc = &H10
bd = &H11
Seek #fileid, Seek(fileid) - 5
Do While 1
If Seek(fileid) = 1 Then
readfile = readfile(0, fileid, 0)
Exit Function
End If
Get #fileid, , ba
If ba = bc Then
Get #fileid, , bb
If bb = bd Then
Seek #fileid, Seek(fileid) + 2
If hao = -1 Then
readfile = readfile(0, fileid, 0)
Exit Function
Else
readfile = readfile(2, fileid, hao - 1)
Exit Function
End If
Else
Seek #fileid, Seek(fileid) - 1
End If
End If
Seek #fileid, Seek(fileid) - 2
Loop
Case 3
'go boot
Seek #fileid, LOF(fileid)
readfile = readfile(0, fileid, 0)
Exit Function

Case 4
If hao = 1 Then
readfile = readfile(0, fileid, 0)
Exit Function
End If
Dim isee As Integer
For isee = 1 To hao
readfile = readfile(0, fileid, 0)
Next
Exit Function

Case 5
'go N
If hao = 0 Then
readfile = readfile(0, fileid, 0)
Exit Function
End If
Dim X As Integer
For X = 1 To hao * 2
readfile = readfile(0, fileid, 0)
If readfile = "seek_end" Then
Exit Function
End If
Next
readfile = readfile(0, fileid, 0)
Exit Function
Case 9
Dim stra, strb As String
stra = ""
strb = ""
stra = readfile(0, fileid, 0)
Do While 1
strb = strb & stra & Chr(16) & Chr(17) & Chr(13) & Chr(10)
stra = readfile(0, fileid, 0)
If stra = "seek_end" Then
readfile = strb
Exit Function
End If
Loop
End Select
End Function

[此贴子已经被作者于2006-5-6 15:36:14编辑过]

2006-05-06 15:31
fuyong922
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-5-3
得分:0 
谢谢大哥了!!!大哥调试过吗?
你那中间的读取程序我有些看不懂,还有要是把需要的内容放进另一个文件,怎么办?
在读取文件如"F\new.txt",我想让读取的所需内容存储在另一个文件.麻烦大哥了,请赐教!!
2006-05-06 23:52
fuyong922
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-5-3
得分:0 

楼上的兄弟,能不能把开始的读取部分的也写下,小弟时间紧急,vb又比较菜,没有办法把他补充完整,
在文件读取和写出部分的,能不能把你的程序完善可以直接运行,就一上面的例子吧,麻烦大哥了!

2006-05-07 01:18
fuyong922
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-5-3
得分:0 

大哥,帮帮小弟呀,回头请你们吃饭去!!

2006-05-07 12:51
fuyong922
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-5-3
得分:0 

大哥.能不能按开头字母PG01读取!!!!
给个程序呀!!!

2006-05-08 11:13
chenmo83
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-6-28
得分:0 

哎,sp3数据提取啊 !

2006-06-28 11:25
chenmo83
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-6-28
得分:0 

呵呵, 要交流相关专业知识的 , 加我啊,学习中! QQ:343965576 认证请注明:GPS交流!

2006-06-28 11:28
liqun725
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-8-3
得分:0 

都是废话

2006-08-03 16:36
学习VB才2天
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1653
专家分:0
注 册:2006-5-4
得分:0 
............

[GLOW=255,DeepPink,3]我的免费网盘[/GLOW]
2006-08-04 08:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-61674-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.234109 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved