VB 如何读取文本文档中定的某一行,某一段!

miaomiao820 2005-09-19 08:47:45
文档格式如下:
11:41:15 0 32 32 32 31 31 31 64 50 26 26 26
11:41:16 1 32 32 32 25 31 31 65 50 26 26 26

每个值都要读入不同的变量,请问如何用程序实现?
...全文
342 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chen2831278 2005-09-20
  • 打赏
  • 举报
回复
ding yi xia
wangdeshui 2005-09-20
  • 打赏
  • 举报
回复
接分
jxgzay 2005-09-20
  • 打赏
  • 举报
回复
接分。
简单问题
zlt982001 2005-09-19
  • 打赏
  • 举报
回复
来晚了,
northwolves 2005-09-19
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim x() As String, y() As String, b() As Byte, temp() As String, i As Integer, j As Integer
Open "c:\xx.txt" For Binary As #1
ReDim b(LOF(1))
Get #1, , b
Close #1
x = Split(StrConv(b, vbUnicode), vbCrLf)
Erase b
ReDim y(UBound(x), 13)
For i = 0 To UBound(x)
temp = Split(x(i), " ")
If UBound(temp) = 1 Then
Exit For
Else
For j = 0 To UBound(temp)
y(i, j) = temp(j)
Next
MsgBox Join(temp, vbCrLf), 0, y(i, 0)
End If
Next
End Sub
DW2005 2005-09-19
  • 打赏
  • 举报
回复
'ReadFileLine用于读取任意一行,行号从1开始
'GetAllElement用于取得各列的值。


public type Mydata
Element1 as string
...............
Element13 as string
end type

public function GetAllElement(byval strLine as string,optional SplitChar=space(1)) as mydata

dim AllElement

AllElement=split(strline,splitchar)
with GetAllElement
.Element1=AllElement(0)
........
end with


end function



public function ReadFileLine(ByVal strFile As String,byval lngLineNo as long) as string
dim strContent as string
dim ALLLine
strcontent=ReadFileAsString(strfile)
allline=split(strcontent,vbcrlf)
ReadFileLine=allline(lnglineno-1)
end function




Public Function ReadFileAsByte(ByVal strFile As String, ByRef FileByte() As Byte) As Long
Dim hFile As Long
Dim lngFileSize As Long
Dim bRead As Long
Dim TmpPos As Long
Dim Sum As Long
Dim dwBytesRead As Long
Dim pBuffer(64511) As Byte

'If FileExist(strFile) = False Then Exit Function
hFile = CreateFile(strFile, GENERIC_READ, FILE_SHARE_READ, 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)
If hFile = INVALID_HANDLE_VALUE Then Exit Function
lngFileSize = GetFileSize(hFile, 0&)
If lngFileSize <= 0 Then Exit Function
ReDim FileByte(lngFileSize) As Byte
Sum = 0
Do
DoEvents: DoEvents: DoEvents
bRead = ReadFile(hFile, pBuffer(0), 64511, dwBytesRead, 0&)
TmpPos = VarPtr(FileByte(0)) + Sum
CopyMemory ByVal TmpPos, ByVal VarPtr(pBuffer(0)), ByVal dwBytesRead
Sum = Sum + dwBytesRead
DoEvents: DoEvents: DoEvents
Loop Until Sum >= lngFileSize

ReadFileAsByte = lngFileSize
CloseHandle hFile
End Function
Public Function ReadFileAsString(ByVal strFile As String) As String
Dim FileByte() As Byte
ReadFileAsByte strFile, FileByte()
ReadFileAsString = StrConv(FileByte(), vbUnicode) 'Byte2String

End Function

7,759

社区成员

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

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