如何使用VB6在下一列中添加其他数据

时间:2014-03-31 05:45:02

标签: excel csv vb6

我在VB6中有一个脚本,它将解析CSV文件并只获取所需的数据。我使用 Writeline CSV文件中写入数据。我的问题是如何使用VB6将下一个数据写入CSV文件的下一列?

喜欢此示例输出。

enter image description here

不喜欢

enter image description here

以下是我解析数据和写入CSV / Excel文件的代码

Dim myFSOww As New FileSystemObject
Dim myFSOr As New FileSystemObject
Dim myFSOw
Dim ft1 As TextStream
//This myFSOw is where my CSV file located which I will use for the write
Set myFSOw = myFSOww.GetFile("C:\Users\user\Documents\bebe folder\Desktop\LTE Raw Data\b.csv")
Set myFSOr = CreateObject("Scripting.FileSystemObject")
Set ts = myFSOr.GetFile(txtfilename.Text)
Set ft1 = ts.OpenAsTextStream(ForReading, TristateUseDefault)
Set ft2 = myFSOw.OpenAsTextStream(ForWriting)
//
//This is the start of reading data. It will parse the CSV file
Do Until ft1.AtEndOfStream
    On Error Resume Next
      a = ft1.ReadLine
      b = a
      r = r + 1
      a = Split(a, ",")
      z = left(b, 1)
If Not IsNumeric(z) Then
   For i = 0 To Ubound(a)
      Text1 = a(i)
         If Text1 <> "" And txt1 = ""  Then
            txt1 = Text1
            Text1 = ""
         ElseIf txt1 <> "" And txt2 = "" Then
            txt2 = Text1
            Text1 = ""
         ElseIf txt3 = "" Then
            txt3 = Text1
            Text1 = ""
         ElseIf txt4 = "" Then
            txt4 = Text1
            Text1 = ""
         End If
   Next
//
//In this code, it will write the parse data in another CSV file which the output must be like the first picture below

If txt1 <> "" And txt2 <> "" And txt3 <> "" And txt4 <> "" Then
    ft2.WriteLine txt1
    ft2.WriteLine txt2
    ft2.WriteLine txt3
    ft2.WriteLine txt4
End If

Loop

1 个答案:

答案 0 :(得分:0)

writeline ExistingLine & "," & NewField

您的数据文字是否引用。

writeline ExistingLine & "," & """NewField"""