标题:VB 对 CSV 格式文件的操作------小弟入门刚入门
只看楼主
shi521min
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-10-8
结帖率:80%
 问题点数:0 回复次数:2 
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

搜索更多相关主题的帖子: 文件夹 测量 
2014-08-21 09:18
vbvcr51
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:18
帖 子:364
专家分:1724
注 册:2013-11-3
得分:0 
刚入门就能写这些代码,佩服佩服!
2014-08-22 09:40
shi521min
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-10-8
得分:0 
这也是借鉴高手加上一些自己的想法的代码!版主见笑了!(*^__^*) 嘻嘻……
2014-08-22 20:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-435212-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.574525 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved