|
-
Nov 14th, 2006, 03:49 PM
#1
Thread Starter
Fanatic Member
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:
Private Sub AddScores()
Dim lonLoop As Long, strCur() As String
Dim ff As Integer
ff = FreeFile
Open "test.xml" For Output As #ff
Print #ff, "<?xml version=""1.0"" encoding=""ISO-8859-1"" ?>"
Print #ff, "<rss version=""2.0"">"
With lvScore
.ListItems.Clear
For lonLoop = 1 To colScores.Count
strCur = Split(colScores.Item(lonLoop), ":")
.ListItems.Add , , strCur(0)
.ListItems(.ListItems.Count).ListSubItems.Add , , strCur(1)
Print #ff, "<game>"
Print #ff, "<teama>" & Trim(strCur(0)) & "</teama>"
If Val(strCur(1)) > 0 Then
Print #ff, "<sce>" & strCur(1) & "</sce>"
Else
Print #ff, "<sce>" & Replace(strCur(1), " ", "", vbTextCompare) & "</sce>"
End If
Print #ff, "</game>"
Next lonLoop
End With
Print #ff, "</rss>"
Close #ff
End Sub
-
Nov 14th, 2006, 03:59 PM
#2
Thread Starter
Fanatic Member
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:
Private Sub AddScores()
Dim lonLoop As Long, strCur() As String
Dim ff As Integer
ff = FreeFile
Open "test.xml" For Output As #ff
Print #ff, "<?xml version=""1.0"" encoding=""ISO-8859-1"" ?>"
Print #ff, "<rss version=""2.0"">"
With lvScore
.ListItems.Clear
Dim i As Integer
i = 1
For lonLoop = 1 To colScores.Count
strCur = Split(colScores.Item(lonLoop), ":")
.ListItems.Add , , strCur(0)
.ListItems(.ListItems.Count).ListSubItems.Add , , strCur(1)
If i > 2 Then
i = 1
End If
If i = 1 Then
Print #ff, "<game>"
End If
Print #ff, "<teama>" & Trim(strCur(0)) & "</teama>"
If Val(strCur(1)) > 0 Then
Print #ff, "<sce>" & strCur(1) & "</sce>"
Else
Print #ff, "<sce>" & Replace(strCur(1), " ", "", vbTextCompare) & "</sce>"
End If
i = i + 1
If i > 2 Then
Print #ff, "</game>"
End If
Next lonLoop
End With
Print #ff, "</rss>"
Close #ff
End Sub
-
Nov 14th, 2006, 04:19 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|