Results 1 to 3 of 3

Thread: Data export to text file problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    18

    Data export to text file problem

    i'm having problem exporting my data. my last item data went mising and not display out in the text file after the program has been ran. but i've run the query in sql everything works well.what is the problem, anyone please help me to check why did the data went missing?is there any problem with my query or my looping?


    ---results from program---
    **************************************** BOF ****************************************
    Production reported from : 24/09/2007 23:00 to : 25/09/2007 23:00
    Report run at : Wednesday 26/09/2007 11:53
    =====================================================================================

    WKSFCL: BE1PE| WKSPRD: SFH6156-4-ASY| WKSROU: DIP4-MAIN| FT1OPR: 7310|

    WKSLOT| OUTDTE| INPUT_| OUTPUT| REJECT| YIELD|



    WKSFCL: BE1PE| WKSPRD: IL205AM-ASY| WKSROU: SO8AMATRIX| FT1OPR: 7310|

    WKSLOT| OUTDTE| INPUT_| OUTPUT| REJECT| YIELD|
    1|M1738468| 1|9/25/2007 4:04:18 AM| 1|9506| 1|9258| 1|248| 1|0.9739|
    2|M1738470| 2|9/25/2007 4:05:52 AM| 2|9702| 2|9582| 2|120| 2|0.9876|



    WKSFCL: BE1PE| WKSPRD: LH1510-ASY| WKSROU: SSR-MAIN| FT1OPR: 7320|

    WKSLOT| OUTDTE| INPUT_| OUTPUT| REJECT| YIELD|
    1|M1737704| 1|9/25/2007 4:23:32 AM| 1|3345| 1|3217| 1|128| 1|0.9617|




    ---results retrieve directly from db---
    WKSFCL| WKSLOT| WKSPRD| OUTDTE| INPUT_| OUTPUT| REJECT| YIELD| TIMESTAMP|
    BE1PE M1738468 IL205AM-ASY 9/25/2007 4:04:18 AM 9506 9258 248 0.9739 9/26/2007 8:20:37 AM
    BE1PE M1738470 IL205AM-ASY 9/25/2007 4:05:52 AM 9702 9582 120 0.9876 9/26/2007 8:20:37 AM
    BE1PE M1737704 LH1510-ASY 9/25/2007 4:23:32 AM 3345 3217 128 0.9617 9/26/2007 8:20:37 AM
    BE1PE M1737B92 SFH6156-4-ASY 9/25/2007 7:23:16 AM 45852 44004 1848 0.9597 9/26/2007 8:20:37 AM
    BE1PE M1738978 SFH6156-4-ASY 9/25/2007 3:49:08 PM 84306 82131 2175 0.9742 9/26/2007 8:20:37 AM



    ---missing data from the program results---
    BE1PE M1737B92 SFH6156-4-ASY 9/25/2007 7:23:16 AM 45852 44004 1848 0.9597 9/26/2007 8:20:37 AM
    BE1PE M1738978 SFH6156-4-ASY 9/25/2007 3:49:08 PM 84306 82131 2175 0.9742 9/26/2007 8:20:37 AM

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    18

    Re: Data export to text file problem

    code part1
    vb Code:
    1. Private Sub OpenDatabaseConnection()
    2.  
    3.     On Error GoTo ErrorHandler
    4.    
    5.     Set m_objConn = New ADODB.Connection
    6.     m_objConn.Open "Provider=OraOLEDB.Oracle;Data Source=acsp.world;User Id=acsrpt;Password=acsrpt;"
    7.    
    8.     Debug.Print "Open Database connection..."
    9.     Call LogEvent("Open Database connection...", "OpenDatabaseConnection")
    10.    
    11.     Exit Sub
    12.    
    13. ErrorHandler:
    14.     If m_objConn.State = adStateClosed Then
    15.         MsgBox "No Connection to The Server. Please try again later."
    16.     End If
    17.     Call LogError(Name, "OpenDatabaseConnection", Err.Number, Err.Description)
    18.            
    19. End Sub
    20.  
    21. Private Sub DelTbl()
    22.  
    23. On Error GoTo ErrorHandler
    24.  
    25. Dim stmt As String
    26.  
    27.     stmt = "delete from ACSRPT.FT1YLD_LOTLIST"
    28.  
    29.     Debug.Print "Truncating the data source file..."
    30.     ' Truncate the lotlist table if it already exists
    31. ''    m_objConn.Execute "truncate table ACSRPT.FT1YLD_LOTLIST"
    32. ''    m_objConn.Execute "truncate table ACSRPT.FT1YLD_LOTLIST reuse storage"
    33. ''    m_objConn.Execute "delete from ACSRPT.FT1YLD_LOTLIST"
    34.     m_objConn.Execute stmt, , adCmdText
    35.    
    36.     Exit Sub
    37. ErrorHandler:
    38.    
    39.     Call LogError(Name, "DelTbl", Err.Number, Err.Description)
    40.  
    41. End Sub
    42.  
    43. Private Sub InsTbl()
    44.  
    45. On Error GoTo ErrorHandler
    46.  
    47. Dim sqlQuery As String
    48.    
    49.     sqlQuery = "insert into ACSRPT.FT1YLD_LOTLIST " & _
    50.                 "   (WKSFCL, WKSLOT, WKSPRD, OUTDTE, INPUT_, OUTPUT, REJECT, YIELD) " & _
    51.                 "select WKSFCL, WKSLOT, WKSPRD, OUTDTE, INPUT_, OUTPUT, REJECT, " & _
    52.                 "decode(INPUT_, NULL, 'In Qty is Null', " & _
    53.                 "  decode(sign(INPUT_), 1, to_char(round(OUTPUT/INPUT_, 4)), 0, 'In Qty is 0', -1, 'In Qty is negative'))" & _
    54.                 "from ACS.WKSLOT " & _
    55.                 "   where (WKSPRD, WKSOPR) in " & _
    56.                 "   (   select WKSPRD, FT1OPR from ACSRPT.FT1YLD_PRDOPR) " & _
    57.                 "       and OUTDTE >= (select to_date(max(PERIOD_END), 'YYYYMMDDHH24MISS') - 1 + 1/86400 " & _
    58.                 "       from ACS.TMPSEQ) " & _
    59.                 "       and OUTDTE <= (select to_date(max(PERIOD_END), 'YYYYMMDDHH24MISS') " & _
    60.                 "       from ACS.TMPSEQ)"
    61. ''        "insert into ACSRPT.FT1YLD_LOTLIST " & _
    62.             "   (WKSFCL, WKSLOT, WKSPRD, OUTDTE, INPUT_, OUTPUT, REJECT, YIELD) " & _
    63.             "select a.WKSFCL, a.WKSLOT, a.WKSPRD, a.OUTDTE, a.INPUT_, a.OUTPUT, " & _
    64.             "   a.REJECT, decode(a.INPUT_, NULL, 'In Qty is Null', " & _
    65.             "   decode(sign(a.INPUT_), 1, round(a.OUTPUT/a.INPUT_, 4), 0, 'In Qty is 0', -1, 'In Qty is negative')) " & _
    66.             "from " & _
    67.             "(  select * from ACS.WKSLOT " & _
    68.             "   where WKSFCL = 'BE1PE' " & _
    69.             "   and OUTDTE >= (select to_date(max(PERIOD_END), 'YYYYMMDDHH24MISS') - 1 + 1/86400 " & _
    70.             "   from ACS.TMPSEQ) " & _
    71.             "   and OUTDTE <= (select to_date(max(PERIOD_END), 'YYYYMMDDHH24MISS') " & _
    72.             "   from ACS.TMPSEQ)) a, " & _
    73.             "(  select WKSPRD, FT1OPR from ACSRPT.FT1YLD_PRDOPR) b " & _
    74.             "where a.WKSPRD = b.WKSPRD And a.WKSOPR = b.FT1OPR"
    75.            
    76.     Debug.Print "Populating the data source file..."
    77.     ' Populate the table.
    78.     m_objConn.Execute sqlQuery, , adCmdText
    79.     Debug.Print "Data source file populated."
    80.    
    81. ''    m_objConn.Execute "commit write immediate NOWAIT"
    82. ''    m_objConn.Execute "commit"
    83.  
    84.     Exit Sub
    85. ErrorHandler:
    86.    
    87.     Call LogError(Name, "InsTbl", Err.Number, Err.Description)
    88.  
    89. End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    18

    Re: Data export to text file problem

    vb Code:
    1. Private Sub ExtractDataToText()
    2.  
    3. On Error GoTo ErrorHandler
    4.  
    5.     'Declare the ADO objects variables
    6.     Dim objRsParent As ADODB.Recordset
    7.     Dim objRsChild As ADODB.Recordset
    8.    
    9.     'Other variables
    10.     Dim strSQLQueryParent As String
    11.     Dim strSQLQueryChild As String
    12. ''    Dim g_strExportLogFileName As String
    13.  
    14.     'Define the Log filename
    15.     g_strExportLogFileName = App.Path & "\" & Trim(GetINISetting(m_strINIFile, "ExecutionControl", "ExportDataFilename", "?"))
    16.    
    17.     ' Open the forward-only, read-only recordset
    18.    
    19.     strSQLQueryParent = "select * from ACSRPT.FT1YLD_PRDOPR b " & _
    20.             "where exists(" & _
    21.             "select 1 from ACSRPT.FT1YLD_LOTLIST a " & _
    22.             "where a.WKSPRD = b.WKSPRD)"
    23.    
    24.     Set objRsParent = New ADODB.Recordset
    25.     objRsParent.Open strSQLQueryParent, m_objConn, adOpenStatic, adLockReadOnly
    26.            
    27.     strSQLQueryChild = "select WKSPRD, WKSLOT, OUTDTE, INPUT_, OUTPUT, REJECT, YIELD " & _
    28.             "from ACSRPT.FT1YLD_LOTLIST"
    29.    
    30.     Set objRsChild = New ADODB.Recordset
    31.     objRsChild.Open strSQLQueryChild, m_objConn, adOpenStatic, adLockReadOnly
    32.  
    33.     If Not objRsChild.BOF Then
    34.    
    35.         '' MsgBox "Active Recordsets opened. Start writing data to text..."
    36.         Debug.Print "Active Recordsets opened. Start writing data to text..."
    37.         Open g_strExportLogFileName For Output As #1
    38.  
    39.         'Write the header
    40.         Print #1, "**************************************** BOF ****************************************"
    41.         Print #1, "Production reported from : " & Format(Now - 2, "dd/mm/yyyy 23:00") & _
    42.             " to : " & Format(Now - 1, "dd/mm/yyyy 23:00")
    43.         Print #1, "Report run at : " & Format(Now, "dddd") & "  " & Format(Now, "dd/mm/yyyy hh:mm")
    44.         Print #1, "====================================================================================="
    45.         'Write a blank line to the log file.
    46.         Print #1, ""
    47.  
    48.         Debug.Print "Connected to the data source file."
    49.         Call LogEvent("Connected to the data source file.", "ExtractDataToText")
    50.        
    51.         '' MsgBox "Writing file to " & g_strExportLogFileName
    52.         Debug.Print "Retrieving data from recordset..."
    53.         Call LogEvent("Retrieving data from recordset...", "ExtractDataToText")
    54.        
    55.         Dim strParentRow As String
    56.         Dim strChildRow As String
    57.         Dim sDelimiter As String
    58.             sDelimiter = "|  "
    59.         Dim i As Long, j As Integer ' i = row counter, j = column counter
    60.         Dim strProductFlag As String
    61.        
    62.         i = 0
    63.        
    64.         ''MsgBox "Get product list..."
    65.         Debug.Print "Retrieving product list from recordset..."
    66.         ' Write the data from recordset
    67.         Do While Not objRsParent.EOF
    68.              '' MsgBox objRsParent(0).Name
    69.             strParentRow = ""
    70.             For j = 0 To 3
    71.                 strParentRow = strParentRow & objRsParent(j).Name & ": " & objRsParent(j).Value & sDelimiter
    72.             Next j
    73.  
    74.             'Write new line
    75.             Print #1, strParentRow
    76.            
    77.             strProductFlag = objRsParent(1)
    78.            
    79.             objRsParent.MoveNext
    80.                        
    81.             '' Do While Not objRsChild.EOF
    82.             ''MsgBox objRsChild(0) & " +++ " & strProductFlag
    83.            
    84.             Print #1, "" 'write a new blank line
    85.            
    86.             '' MsgBox "Get product details..."
    87.             Debug.Print "Retrieving product details from recordset..."
    88.            
    89.             For j = 1 To 6
    90.                 Print #1, objRsChild(j).Name & sDelimiter;
    91.             Next j
    92.            
    93.             Print #1, "" 'write a new blank line
    94.            
    95.             i = 0
    96. ''            Do While Not objRsChild.EOF ' Write the child data
    97.             Do While Not objRsChild.BOF ' Write the child data
    98.                 If objRsChild(0) = strProductFlag Then
    99.                     i = i + 1
    100.                     For j = 1 To 6
    101.                         Print #1, i & "|" & objRsChild(j).Value & sDelimiter & " "; ;
    102. ''                        strChildRow = strChildRow & objRsChild(j).Value & sDelimiter
    103.                     Next j
    104. ''                    Print #1, strChildRow & " "; ;
    105.                 Else
    106.                     Print #1, vbCrLf
    107.                     Exit Do
    108.                 End If
    109.                 objRsChild.MoveNext
    110.                
    111.                 Print #1, 'Write new line
    112.            
    113.             Loop
    114.            
    115.             i = i + 1
    116.             '' Exit Do
    117.            
    118.             Print #1, "" 'write a new blank line
    119.            
    120.         Loop
    121.    
    122.         'write a new blank line
    123.         Print #1, ""
    124.         'write to new line
    125.         Print #1,
    126.        
    127.         Close #1 ' Close the log file.
    128.    
    129.     Else
    130.         MsgBox "Recordset has no data. Automation will not proceed. ", vbExclamation, "Automation Not Run"
    131.     End If
    132.        
    133.  
    134. '' MsgBox "Complete loop"
    135. Debug.Print "Report generation completed and the Text file was saved to disk."
    136. Call LogEvent("Report generation completed and the Text file was saved to disk.", "ExtractDataToText")
    137.  
    138.    
    139. 'Close the objects
    140. objRsParent.Close
    141. objRsChild.Close
    142. '' m_objConn.Close
    143.  
    144. 'Release the memory associated with the objects
    145. Set objRsParent = Nothing
    146. Set objRsChild = Nothing
    147. '' Set m_objConn = Nothing
    148.  
    149. Call LogEvent("Close the data source connection and release ADO objects.", "ExtractDataToText")
    150.  
    151.     Exit Sub
    152. ErrorHandler:
    153.     ''Resume Next
    154.      Call LogError(Me.Name, "ExtractDataToText", Err.Number, Err.Description)
    155.  
    156. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width