Private Sub Command1_Click()
Dim id$, name$, price$, store$ '宣告變數屬性
Open "fetch.txt" For Input As #1
Do While Not EOF(1)
Input #1, id, name, price, store ' 將資料讀入到四個變數中
Print id, name, price, store '輸出資料
Loop
Close #1
MsgBox "完成"
End Sub
Private Sub Command1_Click() On Error Resume Next
Dim id$, name$, price$, store$ '宣告變數屬性
Open "fetch.txt" For Input As #1
Do While Not EOF(1)
Input #1, id, name, price, store ' 將資料讀入到四個變數中
Print id, name, price, store '輸出資料
Loop
Close #1
MsgBox "完成"
End Sub
uj5u.com熱心網友回復:
最討厭的就是這種“掩耳盜鈴”的做法!
uj5u.com熱心網友回復:
尺有所短,寸有所長。
uj5u.com熱心網友回復:
Private Sub Command1_Click() On Error Resume Next
........
End Sub
對于樓主的內容
我建議這樣處理
用Lineinput
然后每行讀入的資料再進行判斷
如果是格式不對的話,就丟棄掉.
下面是偽代碼,懶得開vb了
line input#1,data1
Dim x() as string
x=Split(data1,",")
if ubound(x)=4'如果他分出來是4項就說明格式正常
id=x(0)
name=x(1)
price=x(2)
store=x(3)
Print id, name, price, store '輸出資料
end if
uj5u.com熱心網友回復:
Private Sub Command1_Click()
Dim FileName as string,FN as integer,DataStr as string,DaraArr() as string
Dim I As integer,Arr() As string
FileName=App.Path &"\fetch.txt"
FN=FreeFile
Open FileName For Binary As FN
DataStr=Space(LOF(FN))
Get #FN,,DataStr
Close #fn
DataArr=Split(DataStr,vbCrLf)
For I=0 To Ubound(DataArr)
if Len(DataArr(i))>0 Then
Arr=Split(DataArr(i),",")
Print Arr(0),Arr(1),Arr(2),Arr(3)
End if
next
MsgBox "完成"
End Sub
Private Sub Command1_Click()
Dim id As String, name As String, price As String, store As String 'éù?÷±?á?ê?D?
Dim strLine As String, strCol() As String
Open "c:/test/fetch.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strLine
If strLine > "" Then
strCol = Split(strLine, ",")
id = strCol(0)
name = strCol(1)
price = strCol(2)
store = strCol(3)
Debug.Print id, name, price, store 'ê?3?êy?Y
End If
Loop
Close #1
MsgBox "完成"
End Sub