Results 1 to 3 of 3

Thread: just some logic.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    just some logic.

    ok I have some info stored. im making a rss feed out of it,

    so the info is about nfl.

    it has a team, then the score, then goes on to the next team, and gets a score.

    now

    for my rss feed, i need this layout.

    Code:
    <game>
    <teamA></teamA>
    <scoreA> </scoreA>
    <teamB></teamB>
    <scoreB> </scoreB>
    </game>
    <game>
    <teamA></teamA>
    <scoreA> </scoreA>
    <teamB></teamB>
    <scoreB> </scoreB>
    </game>
    the <game> style repeats after the first two teams, cuz it takes the first two teams and puts a "VS" in between. (in my asp script).

    now the problem im hainvg is puting the "<game></game>" in there.

    heres the code:

    VB Code:
    1. Private Sub AddScores()
    2.     Dim lonLoop As Long, strCur() As String
    3.     Dim ff As Integer
    4.  
    5.     ff = FreeFile
    6.     Open "test.xml" For Output As #ff
    7.    
    8.      Print #ff, "<?xml version=""1.0"" encoding=""ISO-8859-1"" ?>"
    9.      Print #ff, "<rss version=""2.0"">"
    10.  
    11.    
    12.     With lvScore
    13.         .ListItems.Clear
    14.        
    15.         For lonLoop = 1 To colScores.Count
    16.            
    17.             strCur = Split(colScores.Item(lonLoop), ":")
    18.            
    19.            
    20.             .ListItems.Add , , strCur(0)
    21.             .ListItems(.ListItems.Count).ListSubItems.Add , , strCur(1)
    22.            
    23.            
    24.           Print #ff, "<game>"
    25.        
    26.           Print #ff, "<teama>" & Trim(strCur(0)) & "</teama>"
    27.          
    28.           If Val(strCur(1)) > 0 Then
    29.              Print #ff, "<sce>" & strCur(1) & "</sce>"
    30.           Else
    31.              Print #ff, "<sce>" & Replace(strCur(1), "&nbsp;", "", vbTextCompare) & "</sce>"
    32.           End If
    33.          
    34.          
    35.         Print #ff, "</game>"
    36.          
    37.         Next lonLoop
    38.    
    39.  
    40.     End With
    41.     Print #ff, "</rss>"
    42.     Close #ff
    43. End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: just some logic.

    This is what i did,
    i just declared i as an integer, and used it as a counter.

    can anyone recommend a better way.

    VB Code:
    1. Private Sub AddScores()
    2.     Dim lonLoop As Long, strCur() As String
    3.     Dim ff As Integer
    4.  
    5.     ff = FreeFile
    6.     Open "test.xml" For Output As #ff
    7.    
    8.      Print #ff, "<?xml version=""1.0"" encoding=""ISO-8859-1"" ?>"
    9.      Print #ff, "<rss version=""2.0"">"
    10.  
    11.    
    12.     With lvScore
    13.         .ListItems.Clear
    14.         Dim i As Integer
    15.         i = 1
    16.         For lonLoop = 1 To colScores.Count
    17.            
    18.             strCur = Split(colScores.Item(lonLoop), ":")
    19.            
    20.            
    21.             .ListItems.Add , , strCur(0)
    22.             .ListItems(.ListItems.Count).ListSubItems.Add , , strCur(1)
    23.            
    24.             If i > 2 Then
    25.             i = 1
    26.             End If
    27.          
    28.             If i = 1 Then
    29.                 Print #ff, "<game>"
    30.             End If
    31.        
    32.             Print #ff, "<teama>" & Trim(strCur(0)) & "</teama>"
    33.              
    34.             If Val(strCur(1)) > 0 Then
    35.              Print #ff, "<sce>" & strCur(1) & "</sce>"
    36.             Else
    37.              Print #ff, "<sce>" & Replace(strCur(1), "&nbsp;", "", vbTextCompare) & "</sce>"
    38.             End If
    39.            
    40.             i = i + 1
    41.            
    42.             If i > 2 Then
    43.              Print #ff, "</game>"
    44.             End If
    45.        
    46.        
    47.          
    48.         Next lonLoop
    49.    
    50.  
    51.     End With
    52.     Print #ff, "</rss>"
    53.     Close #ff
    54. End Sub

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: just some logic.

    Add this function to the code:

    Code:
    Private Function ScoresToXML() As String
        Dim lonLoop As Long, lonCount As Long
        Dim strCur() As String, strRet As String
        
        With colScores
            lonCount = .Count
            
            For lonLoop = 1 To lonCount Step 2
            
                If InStr(1, .Item(lonLoop), ":") > 0 Then
                    strCur() = Split(.Item(lonLoop), ":")
                    
                    strRet = strRet & "<game>" & vbCrLf
                    strRet = strRet & "<teamA>" & strCur(0) & "</teamA>" & vbCrLf
                    strRet = strRet & "<scoreA>" & strCur(1) & "</scoreA>" & vbCrLf
                    
                    If (lonLoop + 1) <= .Count Then
                        strCur() = Split(.Item(lonLoop + 1), ":")
                        strRet = strRet & "<teamB>" & strCur(0) & "</teamB>" & vbCrLf
                        strRet = strRet & "<scoreA>" & strCur(1) & "</scoreB>" & vbCrLf
                    End If
                    
                    strRet = strRet & "</game>" & vbCrLf
                End If
            
            Next lonLoop
        
        End With
        
        ScoresToXML = strRet
    End Function
    Then in a command button or something, put:

    Code:
    Private Sub Command1_Click()
        Dim strXML As String
        
        strXML = ScoresToXML
        
        Open App.Path & "\scores.xml" For Output As #1
            
            Print #1, "<?xml version=""1.0"" encoding=""ISO-8859-1"" ?>"
            Print #1, "<rss version=""2.0"">"
            
            Print #1, strXML
            
            Print #1, "</rss>" & vbCrLf
            
        Close #1
        
    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