Results 1 to 2 of 2

Thread: Algorithm problem. Just not recording the info ... *resolved*

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Algorithm problem. Just not recording the info ... *resolved*

    Okay. In the below Sub, sqlAddHeaders(), its nearly working.
    I have a file in the form :
    Code:
    791755	Backup Solutions|Backup Software|Computer Associates	BrightStor Arcserve Backup Version 9 Tape Raid Option for Netware		506		Product Information	BABFBNW900NE2	0	0
    791772	Backup Solutions|Backup Software|Computer Associates	BrightStor Arcserve Backup Version 9 Tape Library Option for Netware		455		Product Information	BABFBNW900NE4	0	0
    872095	Backup Solutions|Backup Software|Computer Associates	BrightStor Arcserve Backup Version 9 Universal Client Agent for windows Upgrade from any previous evrsion 		69		Product Information	BABWUP2900E22?BDL	122	0
    702346	Backup Solutions|Backup Software|Computer Associates	OLP BrightStor ARCserve for Small Business Server 2000 with Open Files Agent 2 Year Upgrade Protection		231		Product Information	ARCBBN2700WG0U2	0	0
    804202	Backup Solutions|Backup Software|Veritas	Backup Exec,Windows,Microsoft Exchange Server Agent Upgrade,v9.0,E/F/G/S/I/C,Full Package Product 		114		Product Information	E094018	0	14
    749605	Backup Solutions|Backup Software|Veritas	NetBackup BusinesServer NDMP Agent version 4.5, Cross Platform		1043		Product Information	A08587C-000000	0	0
    755887	Backup Solutions|Backup Software|Veritas	Netbackup BusinesServer Exchange Agent version 4.5 VS1 12x5 1yr		144		Product Information	W085805-000112	0	0
    I'm passing 2 parameters into the sub, namely, strData (which is the 2nd field above (Backup Solutions|Backup Software|Veritas)), and strChildSAPCode, eg. 791755

    Now. I am them reprinting the info back out using a logging function at the bottom. It works fine for all the Computer Associates fields. But once it hits veritas, its not working.
    Here's an example:
    Code:
    Backup Solutions:Backup Software:Computer Associates:791755
    Backup Solutions:Backup Software:Computer Associates:791755791772
    . . . 
    ::Veritas:804202
    ::Veritas:804202749605
    So. Why is it storing all the infomation correctly, until the first time the 3rd section in the 2nd field changes...?

    VB Code:
    1. Imports System.Data.SqlClient
    2.  
    3. Module modMisc
    4.  
    5. #Region "Declarations ..."
    6.     Private blnHaveCleared As Boolean
    7.  
    8.     Private colMasterHeaders() As clsColumnReference
    9.     Private colSecondHeaders() As clsColumnReference
    10.     Private colThirdHeaders() As clsColumnReference
    11. #End Region
    12.  
    13.  
    14. #Region "clsColumnReference()"
    15.     Class clsColumnReference
    16.         Public strColumnText As String
    17.         Public lngParentIndex As Long
    18.         Public blnIsMasterParent As Boolean
    19.         Public strChildSAPCodes As String
    20.     End Class
    21. #End Region
    22.  
    23.  
    24. #Region "doInitHeaders()"
    25.     Private Sub doInitHeaders()
    26.         If colMasterHeaders Is Nothing Then ReDim colMasterHeaders(0) : colMasterHeaders(0) = New clsColumnReference()
    27.         If colSecondHeaders Is Nothing Then ReDim colSecondHeaders(0) : colSecondHeaders(0) = New clsColumnReference()
    28.         If colThirdHeaders Is Nothing Then ReDim colThirdHeaders(0) : colThirdHeaders(0) = New clsColumnReference()
    29.     End Sub
    30. #End Region
    31.  
    32.  
    33. #Region "sqlAddHeaders()"
    34.     Public Sub sqlAddHeaders(ByVal strData As String, ByVal strChildSAPCode As String)
    35.         Dim i As Long, strHeaders() As String = Split(strData, "|"), lngParentIndex As Long
    36.         Dim blnFoundText As Boolean = False : doInitHeaders()
    37.  
    38.  
    39.         '' Master Headers
    40.         ''
    41.         For i = 0 To UBound(colMasterHeaders)
    42.             With colMasterHeaders(i)                
    43.                 If strHeaders(0) = .strColumnText Then
    44.                     blnFoundText = True
    45.                     Exit For
    46.                 End If
    47.             End With
    48.         Next
    49.         If Not blnFoundText Then
    50.             ReDim Preserve colMasterHeaders(UBound(colMasterHeaders) + 1)
    51.             colMasterHeaders(UBound(colMasterHeaders)) = New clsColumnReference()
    52.             With colMasterHeaders(UBound(colMasterHeaders))
    53.                 .blnIsMasterParent = True
    54.                 .lngParentIndex = -1
    55.                 .strColumnText = strHeaders(0)
    56.                 lngParentIndex = UBound(colMasterHeaders)                
    57.             End With
    58.         End If
    59.         blnFoundText = False
    60.  
    61.  
    62.         '' Secondary Headers
    63.         ''
    64.         For i = 0 To UBound(colSecondHeaders)
    65.             With colSecondHeaders(i)
    66.                 If strHeaders(1) = .strColumnText Then
    67.                     blnFoundText = True                    
    68.                     Exit For
    69.                 End If
    70.             End With
    71.         Next
    72.         If Not blnFoundText Then
    73.             ReDim Preserve colSecondHeaders(UBound(colSecondHeaders) + 1)
    74.             colSecondHeaders(UBound(colSecondHeaders)) = New clsColumnReference()
    75.             With colSecondHeaders(UBound(colSecondHeaders))
    76.                 .blnIsMasterParent = False
    77.                 .lngParentIndex = lngParentIndex
    78.                 .strColumnText = strHeaders(1)
    79.                 lngParentIndex = i                
    80.             End With
    81.         End If
    82.         blnFoundText = False
    83.  
    84.  
    85.         '' Third Headers
    86.         ''
    87.         For i = 0 To UBound(colThirdHeaders)
    88.             If strHeaders(2) = colThirdHeaders(i).strColumnText Then
    89.                 colThirdHeaders(i).strChildSAPCodes += strChildSAPCode
    90.                 blnFoundText = True
    91.                 Exit For
    92.             End If
    93.         Next
    94.         If Not blnFoundText Then
    95.             ReDim Preserve colThirdHeaders(UBound(colThirdHeaders) + 1)
    96.             colThirdHeaders(UBound(colThirdHeaders)) = New clsColumnReference()
    97.             With colThirdHeaders(UBound(colThirdHeaders))
    98.                 .blnIsMasterParent = False
    99.                 .lngParentIndex = lngParentIndex
    100.                 .strColumnText = strHeaders(2)                
    101.                 .strChildSAPCodes = strChildSAPCode
    102.             End With
    103.         End If
    104.  
    105.         Dim colThirdLevel As New clsColumnReference()
    106.         colThirdLevel = colThirdHeaders(UBound(colThirdHeaders))
    107.  
    108.         Dim colSecondLevel As New clsColumnReference()
    109.         colSecondLevel = colSecondHeaders(colThirdLevel.lngParentIndex)
    110.  
    111.         Dim colMasterLevel As New clsColumnReference()
    112.         colMasterLevel = colMasterHeaders(colSecondLevel.lngParentIndex)
    113.  
    114.         doLogFile(colMasterLevel.strColumnText & ":" & _
    115.                     colSecondLevel.strColumnText & ":" & _
    116.                     colThirdLevel.strColumnText & ":" & _
    117.                     colThirdLevel.strChildSAPCodes)
    118.  
    119.  
    120.     End Sub
    121.  
    122.     Private Sub doLogFile(ByVal strString As String)
    123.         Dim lngFileHandle As Long = FreeFile()
    124.         FileOpen(lngFileHandle, "c:\mylog.txt", OpenMode.Append)
    125.         Print(lngFileHandle, strString & vbCrLf)
    126.         FileClose(lngFileHandle)
    127.     End Sub
    128.  
    129. #End Region
    130. End Module
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Was a small hitch in my logic. Fixed now. I needed the bolded parts included

    VB Code:
    1. Imports System.Data.SqlClient
    2.  
    3. Module modMisc
    4.  
    5. #Region "Declarations ..."
    6.     Private blnHaveCleared As Boolean
    7.  
    8.     Private colMasterHeaders() As clsColumnReference
    9.     Private colSecondHeaders() As clsColumnReference
    10.     Private colThirdHeaders() As clsColumnReference
    11. #End Region
    12.  
    13.  
    14. #Region "clsColumnReference()"
    15.     Class clsColumnReference
    16.         Public strColumnText As String
    17.         Public lngParentIndex As Long
    18.         Public blnIsMasterParent As Boolean
    19.         Public strChildSAPCodes As String
    20.     End Class
    21. #End Region
    22.  
    23.  
    24. #Region "sqlAddProductToDB()"
    25.     Public Sub sqlAddProductToDB(ByVal strData As String, ByVal mySqlConnection As SqlConnection)
    26.         Dim strSQLStatement As String
    27.         If Not blnHaveCleared Then
    28.             strSQLStatement = "DELETE FROM tblProducts WHERE strProductReference = strProductReference;"
    29.         Else
    30.             strData = Replace$(strData, "'", vbNullString)
    31.             strData = Replace$(strData, vbTab, "','")
    32.             strSQLStatement = _
    33.                 "INSERT INTO tblProducts " & _
    34.                 "(strProductReference, strSectionText, strShortDescription, strDetailURL, strTradePrice, strPrice, strDetailLink, strFullDescription, strRRP, strStock) VALUES " & _
    35.                 "(" & "'" & strData & "'" & ");"
    36.         End If
    37.         Dim mySQLCommand As New SqlCommand(strSQLStatement, mySqlConnection)
    38.         'ListBox1.Items.Add(strPrepare(strSQLStatement))        
    39.         Try
    40.             mySQLCommand.ExecuteNonQuery()
    41.         Catch ex As Exception
    42.             MsgBox(ex.Message & vbCrLf & ex.StackTrace & vbCrLf & vbCrLf & strSQLStatement)
    43.         End Try
    44.         If Not blnHaveCleared Then
    45.             blnHaveCleared = True
    46.             sqlAddProductToDB(strData, mySqlConnection)
    47.         End If
    48.     End Sub
    49. #End Region
    50.  
    51.  
    52. #Region "doInitHeaders()"
    53.     Private Sub doInitHeaders()
    54.         If colMasterHeaders Is Nothing Then ReDim colMasterHeaders(0) : colMasterHeaders(0) = New clsColumnReference()
    55.         If colSecondHeaders Is Nothing Then ReDim colSecondHeaders(0) : colSecondHeaders(0) = New clsColumnReference()
    56.         If colThirdHeaders Is Nothing Then ReDim colThirdHeaders(0) : colThirdHeaders(0) = New clsColumnReference()
    57.     End Sub
    58. #End Region
    59.  
    60.  
    61. #Region "sqlAddHeaders()"
    62.     Public Sub sqlAddHeaders(ByVal strData As String, ByVal strChildSAPCode As String)
    63.         Dim i As Long, strHeaders() As String = Split(strData, "|"), lngParentIndex As Long
    64.         Dim blnFoundText As Boolean = False : doInitHeaders()
    65.  
    66.  
    67.         '' Master Headers
    68.         ''
    69.         For i = 0 To UBound(colMasterHeaders)
    70.             With colMasterHeaders(i)                
    71.                 If strHeaders(0) = .strColumnText Then
    72.                     blnFoundText = True
    73. [b]                    lngParentIndex = i[/b]
    74.                     Exit For
    75.                 End If
    76.             End With
    77.         Next
    78.         If Not blnFoundText Then
    79.             ReDim Preserve colMasterHeaders(UBound(colMasterHeaders) + 1)
    80.             colMasterHeaders(UBound(colMasterHeaders)) = New clsColumnReference()
    81.             With colMasterHeaders(UBound(colMasterHeaders))
    82.                 .blnIsMasterParent = True
    83.                 .lngParentIndex = -1
    84.                 .strColumnText = strHeaders(0)
    85.                 lngParentIndex = UBound(colMasterHeaders)                
    86.             End With
    87.         End If
    88.         blnFoundText = False
    89.  
    90.  
    91.         '' Secondary Headers
    92.         ''
    93.         For i = 0 To UBound(colSecondHeaders)
    94.             With colSecondHeaders(i)
    95.                 If strHeaders(1) = .strColumnText Then
    96.                     blnFoundText = True
    97. [b]                    lngParentIndex = i[/b]
    98.                     Exit For
    99.                 End If
    100.             End With
    101.         Next
    102.         If Not blnFoundText Then
    103.             ReDim Preserve colSecondHeaders(UBound(colSecondHeaders) + 1)
    104.             colSecondHeaders(UBound(colSecondHeaders)) = New clsColumnReference()
    105.             With colSecondHeaders(UBound(colSecondHeaders))
    106.                 .blnIsMasterParent = False
    107.                 .lngParentIndex = lngParentIndex
    108.                 .strColumnText = strHeaders(1)
    109.                 lngParentIndex = i                
    110.             End With
    111.         End If
    112.         blnFoundText = False
    113.  
    114.  
    115.         '' Third Headers
    116.         ''
    117.         For i = 0 To UBound(colThirdHeaders)
    118.             If strHeaders(2) = colThirdHeaders(i).strColumnText Then
    119.                 colThirdHeaders(i).strChildSAPCodes += strChildSAPCode
    120.                 blnFoundText = True
    121.                 Exit For
    122.             End If
    123.         Next
    124.         If Not blnFoundText Then
    125.             ReDim Preserve colThirdHeaders(UBound(colThirdHeaders) + 1)
    126.             colThirdHeaders(UBound(colThirdHeaders)) = New clsColumnReference()
    127.             With colThirdHeaders(UBound(colThirdHeaders))
    128.                 .blnIsMasterParent = False
    129.                 .lngParentIndex = lngParentIndex
    130.                 .strColumnText = strHeaders(2)
    131.                 .strChildSAPCodes = strChildSAPCode
    132.             End With
    133.         End If
    134.  
    135.         Dim colThirdLevel As New clsColumnReference()
    136.         colThirdLevel = colThirdHeaders(UBound(colThirdHeaders))
    137.  
    138.         Dim colSecondLevel As New clsColumnReference()
    139.         colSecondLevel = colSecondHeaders(colThirdLevel.lngParentIndex)
    140.  
    141.         Dim colMasterLevel As New clsColumnReference()
    142.         colMasterLevel = colMasterHeaders(colSecondLevel.lngParentIndex)
    143.  
    144.         doLogFile(colMasterLevel.strColumnText & ":" & _
    145.                     colSecondLevel.strColumnText & ":" & _
    146.                     colThirdLevel.strColumnText & ":" & _
    147.                     colThirdLevel.strChildSAPCodes)
    148.  
    149.  
    150.     End Sub
    151.  
    152.     Private Sub doLogFile(ByVal strString As String)
    153.         Dim lngFileHandle As Long = FreeFile()
    154.         FileOpen(lngFileHandle, "c:\mylog.txt", OpenMode.Append)
    155.         Print(lngFileHandle, strString & vbCrLf)
    156.         FileClose(lngFileHandle)
    157.     End Sub
    158.  
    159. #End Region
    160. End Module
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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