请教-----VB 对 CSV 格式文件操作----小弟刚入门没多久
VB将测量结束后的数据存入CSV格式文件里,程序会每天生成一个当天文件夹,然后每天测得的CSV文件存储到当天的文件夹里。以下为代码。
麻烦看一下怎么更改或者用什么思路去修改。先谢谢了
Const FilePath = "D:\123.csv"
Dim iCount As Long
Private Sub Command2_Click()
Timer1 = True
End Sub
Private Sub Form_Initialize()
iCount = 0
End Sub
Private Sub Timer1_Timer()
Dim i As Integer, FileNum As Integer
Dim TempString As String
Dim fileName As String
If Dir("D:\本地数据", vbDirectory) = "" Then
MkDir ("D:\本地数据")
End If
fname = "D:\本地数据\" & Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日"
If Dir(fname, vbDirectory) = "" Then
MkDir (fname)
End If
fileName = fname
TempString = ""
For i = 1 To 7
If i = 1 Then
TempString = Trim(Text1(i).Text)
Else
TempString = TempString & "," & Trim(Text1(i).Text)
End If
Next i
FileNum = FreeFile
If iCount = 0 Then
Open FilePath For Output As #FileNum
Print #FileNum, " 序号" & "," & "日期" & "," & "时间" & "," & "平面度" & "," & "单位"
Print #FileNum, (iCount + 1) & "," & TempString
Close #FileNum
Else
Open FilePath For Append As #FileNum
Print #FileNum, (iCount + 1) & "," & TempString
Close #FileNum
End If
iCount = iCount + 1
End Sub