"
D
1 69.2723 0.569
D
2 69.2735 0.569
D
3 69.2735 0.569
D
4 69.2734 0.568
D
D1 304.4237 0.490
D
5 81.1011 0.490
D
6 99.1348 1.00
D1
7 0.0008 0.977
D1
8 0.0006 0.976"
怎样将以上的数据读取 然后放到vb 的grid控件中显示出来。可以不要空格但是显示的格式要和上面的一样。
D
1 69.2723 0.569
D
2 69.2735 0.569
D
3 69.2735 0.569
D
4 69.2734 0.568
D
D1 304.4237 0.490
D
5 81.1011 0.490
D
6 99.1348 1.00
D1
7 0.0008 0.977
D1
8 0.0006 0.976"
怎样将以上的数据读取 然后放到vb 的grid控件中显示出来。可以不要空格但是显示的格式要和上面的一样。
dim s as string
dim i as long Open App.Path & "d:\aa.txt" For Input As #1
s = StrConv(InputB(LOF(1), #1), vbUnicode)
Close #1ls_Content = Split(s, vbCrLf)
for i=0 to UBound(ls_Content, 1)
debug.print ls_Content(i)'这里就将你的文件一行行分开了
next i
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set readFile = objFSO.OpenTextFile ("c:\11.txt", ForReading)
Do while not readFile.AtEndOfStream
StrLine = readFile.Readline
'读出行后在这里对字符串做处理,解析出有用的数据
Loop
readFile.Close
Set readFile = Nothing
Set objFSO = Nothing
这一步我做出来了,我的意思是 能不能将每行再按列分割阿?
如果仅仅是 Tab:
Dim strFields() As String
......
strFields = Split(strRow(i), vbTab)
For j = 0 To Ubound(strFields)
msFlexGrid1.TextMatrix(i, j) = strFields(j)
Next j
......如果是多个空格,首先合并空格:
......
Do While Instr(strRow(i), Space(2))
strRow(i) = Replace(strRow(i), Space(2), Space(1))
Loop
strFields = Split(strRow(i), Space(1))
For j = 0 To Ubound(strFields)
msFlexGrid1.TextMatrix(i, j) = strFields(j)
Next j
......
http://community.csdn.net/Expert/topic/3095/3095485.xml?temp=.9600489