2014-04-04 10 views
0

VB6을 사용하여 구문 분석하고 특정 데이터 만 가져 오는 Raw 데이터가 있습니다. 이미 특정 데이터를 얻었습니다. 내 문제는 바로 이것이다. writeline을 사용하여 특정 데이터를 다른 Excel/CSV 파일에 작성합니다. 내 문제는 이것입니다. 이미 CSV/Excel 파일에 데이터를 쓸 수는 있지만 첫 번째 열에 만 쓰여지므로 모든 데이터가 첫 번째 열에 만 쓰게됩니다. 누군가 제발 나를 도울 수 있습니까, 어떻게하면 컬럼 당 만들 수 있습니까? 예를 들어 필요한 첫 번째 줄은 첫 번째 줄에 있고 두 번째 줄은 두 번째 줄에 있습니다. 사전에 도움을 주셔서 감사합니다 :)VB6을 사용하는 Excel/CSV 파일

아래 코드는 내 코드입니다.

Dim i, ii, num As Long 
Dim ff As Integer 
Dim sText As String 
Dim itmX As ListItem 
Dim x, y As Integer 
Dim ex As Excel.Application 
Dim sheet As Excel.Workbook 
Dim Csheet As Excel.Range 
Dim wsheet As Excel.Worksheet, snum As Long 

Dim strTransform() As String 
Dim strTemp() As String 
Dim intI As Integer 
Dim intJ As Integer 
Dim intMax As Integer 
Dim p(29) As String 
Dim adata() As String 
Dim time1() As String 
Dim holder1, holder2, holder3 
Dim time2() As String 
Dim lngIndex As Integer 
Dim lngIndexx As Integer 
Dim totaltime() As String 

Dim myFSOww As New FileSystemObject 
Dim myFSOr As New FileSystemObject 
Dim myFSOw 
Dim ft1 As TextStream 
Dim ts, ts2, ts3, ft2, r, a, b, z, c, minus, time_num1, time_num2, time_num3, time_num4, comp 
Dim date_num1, date_num2, d_t, total_parse, flow_total, req_flow, aia, air, cer, cla, clr, dsa 
Dim dsr, dwa, dwr, ida, idr, noa, nor, pua, pur, rsa, rsr, ula, ulr 
Set myFSOw = myFSOww.GetFile("C:\Users\user\Documents\bebe folder\Projects SSD\LTE Raw Data\Peek_data.csv") 
Set myFSOr = CreateObject("Scripting.FileSystemObject") 
Set ts = myFSOr.GetFile(txtfilename.Text) 
Set ft1 = ts.OpenAsTextStream(ForReading, TristateUseDefault) 
Set ft2 = myFSOw.OpenAsTextStream(ForWriting) 

Do Until ft1.AtEndOfStream 
    On Error Resume Next 
     a = ft1.ReadLine 
     b = a 
     p(0) = a 
     r = r + 1 
     Text1.Text = r 
     z = Left(b, 1) 

     If Not IsNumeric(z) Then 
      adata = Split(a, ",") 
      For i = 0 To UBound(adata) 
       Text3 = adata(i) 
        If Text3 <> "Time Stamp" And txt_tag = Empty Then 
         ft2.WriteLine Text3 

        End If 
      Next 
     txt_tag = 1 

     Else 

     'FOR TIME 
     p0 = "00:00" 
     p1 = "01:00" 
     p2 = "02:00" 
     p3 = "03:00" 
     p4 = "04:00" 
     p5 = "05:00" 
     p6 = "06:00" 
     p7 = "07:00" 
     p8 = "08:00" 
     p9 = "09:00" 
     p11 = "11:00" 
     p12 = "12:00" 
     p13 = "13:00" 
     p14 = "14:00" 
     p16 = "16:00" 
     p17 = "17:00" 
     p18 = "18:00" 
     p19 = "19:00" 
     p20 = "20:00" 
     p21 = "21:00" 
     p22 = "22:00" 
     p23 = "23:00" 

     h1 = "1:00" 
     h2 = "2:00" 
     h3 = "3:00" 
     h4 = "4:00" 
     h5 = "5:00" 
     h6 = "6:00" 
     h7 = "7:00" 
     h8 = "8:00" 
     h9 = "9:00" 

     If holder1 = "" Then 
      time1 = Split(a, ",") 

      For lngIndex = 0 To UBound(time1) 
       holder1 = time1(lngIndex) 
        If holder1 = time1(1) Then 
         txt_dt = holder1 
         If Len(txt_dt) = 19 Then 
          txt_t = Right(txt_dt, 8) 
          txt_d = Left(txt_dt, 10) 
          txt_t = Left(txt_t, 5) 
         ElseIf Len(txt_dt) = 14 Then 
          txt_t = Right(txt_dt, 4) 
          txt_d = Left(txt_dt, 10) 
         ElseIf Len(txt_dt) = 15 Then 
          txt_t = Right(txt_dt, 5) 
          txt_d = Left(txt_dt, 10) 
         End If 

         txt_trm = Trim(txt_t) 
         txt_t = txt_trm 

         If txt_t = p0 Or txt_t = p1 Or txt_t = p2 Or txt_t = p3 Or txt_t = p4 Or txt_t = p5 Or txt_t = p6 Or txt_t = p7 Or txt_t = p8 _ 
          Or txt_t = p9 Or txt_t = p10 Or txt_t = p11 Or txt_t = p12 Or txt_t = p13 Or txt_t = p14 Or txt_t = p15 Or txt_t = p16 _ 
          Or txt_t = p17 Or txt_t = p18 Or txt_t = p19 Or txt_t = p20 Or txt_t = p21 Or txt_t = p22 Or txt_t = p23 _ 
          Or txt_t = h1 Or txt_t = h2 Or txt_t = h3 Or txt_t = h4 Or txt_t = h5 Or txt_t = h6 Or txt_t = h7 Or txt_t = h8 _ 
          Or txt_t = h9 Then 
           holder1 = time1(lngIndex) 
         Else 
           holder1 = "" 
           GoTo 1 
         End If 
        End If 

      Next lngIndex 

     Else 
      time2 = Split(a, ",") 
      For lngIndexx = 0 To UBound(time2) 
       holder2 = time2(lngIndexx) 
        If holder2 = time2(1) Then 
         txt_dt = holder2 'this is my time 
          If Len(txt_dt) = 19 Then 
           txt_t = Right(txt_dt, 8) 
           txt_d = Left(txt_dt, 10) 
           txt_t = Left(txt_t, 5) 
          ElseIf Len(txt_dt) = 14 Then 
           txt_t = Right(txt_dt, 4) 
           txt_d = Left(txt_dt, 10) 
          ElseIf Len(txt_dt) = 15 Then 
           txt_t = Right(txt_dt, 5) 
           txt_d = Left(txt_dt, 10) 
          End If 
         txt_trm = Trim(txt_t) 
         txt_t = txt_trm 

         If txt_t = p0 Or txt_t = p1 Or txt_t = p2 Or txt_t = p3 Or txt_t = p4 Or txt_t = p5 Or txt_t = p6 Or txt_t = p7 Or txt_t = p8 _ 
          Or txt_t = p9 Or txt_t = p10 Or txt_t = p11 Or txt_t = p12 Or txt_t = p13 Or txt_t = p14 Or txt_t = p15 Or txt_t = p16 _ 
          Or txt_t = p17 Or txt_t = p18 Or txt_t = p19 Or txt_t = p20 Or txt_t = p21 Or txt_t = p22 Or txt_t = p23 _ 
          Or txt_t = h1 Or txt_t = h2 Or txt_t = h3 Or txt_t = h4 Or txt_t = h5 Or txt_t = h6 Or txt_t = h7 Or txt_t = h8 _ 
          Or txt_t = h9 Then 
           holder2 = time2(lngIndexx) 
         Else 
           holder2 = "" 
           GoTo 1 
         End If 

        End If 
      Next lngIndexx 

     End If 

    'subtract array time1 from time2 
1 

     If holder1 <> "" And holder2 <> "" Then 
      For lngIndex = 0 To UBound(time2) 
       holder3 = time2(lngIndex) - time1(lngIndex) 
       If write1 = 0 And lngIndex = 1 Then 
        ft2.WriteLine time2(1) 
        write1 = 1 
       ElseIf write1 = 1 And lngIndex <> 1 Then 
        ft2.WriteLine holder3 
       End If 

      Next 
      ft2.WriteBlankLines 1 
     End If 
     write1 = 0 
    End If 
DoEvents 

Loop 
List1.AddItem Format(Now, "YYYY-MM-DD HH:MM:SS") & " Time end" 
Set ft2 = Nothing 
+1

무엇을 쓰고 있습니까? CSV 형식 또는 Excel? 엄청난 차이가 있습니다. "서면"이란 무엇입니까? 이것은 VB6 명령이 아닙니다. 마지막으로 정답을 원한다면 몇 가지 코드를 게시해야합니다. 문제를 재현하기에 충분합니다. –

+1

FSO가 여기에 연관되어있을 것 같습니다. – Bob77

+0

왜 FSO를 사용합니까? VB6에는 자체 파일 핸들링이 있습니다. –

답변

2

bebebe, 실제 상황이나 예제 코드없이 질문에 대답하기 어렵습니다. 이 "RAW"데이터는 무엇이고 내보내기 형식은 무엇입니까? 당신이 CSV를 만들려면이 같은 것을 사용할 수 있습니다 - 당신은 실제 파일을 엑셀이 필요하지만, 이드 COM을 사용하여 Excel 인스턴스를 생성 건의 경우 (배열에 따라 데모)

Dim ff As Long, strFilePath As String 
Dim rLoop As Long, cLoop As Long 
Dim strLine as String 
ff = Freefile 
strFilePath = App.Path 
If Right$(strFilePath, 1)<>"\" Then strFilePath = strFilePath & "\" 

Open strFilePath&"demo.csv" For Output As ff 

For rLoop = 0 To numRows -1 'Could use uBound or set a value if fixed - I dont know how you have this RAW DATA 
    strLine = "" 
    For cLoop = 0 To numCols -1 'Could use uBound if array 
    If cLoop>0 Then strLine = strLine & "," 
    strLine = strLine & """" & rawDataArray(rLoop, cLoop) & """" 
    Next cLoop 
    Print #ff, strLine 
Next rLoop 
Close #ff 

을 - MS에 참조 사이트 : http://msdn.microsoft.com/en-us/library/7t9k08y5(v=vs.90).aspx

+0

주석 주셔서 감사합니다. 그러나 FSO가 사용해야하는 다른 방법이 있습니다. – bebebe

관련 문제