1.請問如何將一個文字檔讀取內容放置陣列中,再從陣列中選擇(擷取)自己要的值(數據&文字)顯示在TEXTBOX 或 MSFlexGrid控制項?
2.例如文字檔內容如下:
TEST 123456N02 123456AA 53 G ** **** ************ 600 0 6 594 CROD
9900 IBOT17 O3W006VG 152634 20060724210715 20060724210715 20060724211307 20060724211307
#
123456AA01 N S Q99R J/c 1 0 0 4095 50 200 25 *** * 0 1 99
6.88 0.00 ****** ****** ***********************************
%
1 -599717 731110 11 65 -245 606 GP ND ** **** * -
************ 123456AA010011_1 OTHERS
2 -598646 732522 3 67 -234 615 BP ND ** **** * R
************ ******************* OTHERS
3 -598646 731640 8 67 -244 618 GP ND ** **** * -
************ ******************* OTHERS
4 -596503 731993 6 71 -279 624 BP ND ** **** * -
************ 123456AA010014_1 OTHERS
5 -590075 731110 11 83 -159 606 GP ND X 65 * -
V/r 123456AA010015_1 OTHERS
@
3.怎樣才能從資料中將 % 以下的數值輸出至TEXTBOX 或 MSFlexGrid控制項中? @為此檔結尾 *代表可能有數值
2007-01-11 10:44:09 · 1 個解答 · 發問者 小欽仔 1 in 電腦與網際網路 ➔ 程式設計
'版本VB6.0
'表單放1個TextBox,Name=Text1,MultiLine = True,ScrollBars = 3
Private Sub Command1_Click()
Dim nPath As String, A() As Byte, f As Long, S() As String, B As Boolean, K As Variant
nPath = 檔案路徑 '如("C:\Test.txt")
'用Binary讀檔至A陣列
ReDim A(FileLen(nPath) - 1)
f = FreeFile
Open nPath For Binary As #f
Get #f, , A
Close #f
'以vbCrLf換行字元分割至S陣列
S = Split(StrConv(A, vbUnicode), vbCrLf)
'找出%跟@中間的資料放到Text1
For Each K In S
If B Then
If K = "@" Then Exit For
Text1 = Text1 & K & vbCrLf
Else
If K = "%" Then B = True
End If
Next
If Text1 <> "" Then Text1 = Left(Text1, Len(Text1) - 2)
End Sub
2007-01-11 13:57:45 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋