|
-
Jul 20th, 2005, 04:52 AM
#1
Thread Starter
Lively Member
[RESOLVED] If then else Score
I have some messy code and need to add another feature, but need some help doing so...
Key:
<tab> = I can't type a tab, so I shall put one of these
File contents:
[user_answer.csv]
0,68,285
0,68,286
0,68,287
0,69,290
[question.csv]
... (im not going to type out 100's of lines)
68<tab>0<tab>Question 285
69<tab>0<tab>Question 286
[answer.csv]
...(im not going to type out 110's of lines)
285<tab>0<tab>Answer 285<tab>25
286<tab>0<tab>Answer 286<tab>25
287<tab>0<tab>Answer 187<tab>0
...
290<tab>0<tab>Answer 190<tab>100
What my code created a html file which displays (when viewed in IE):
Question 68
285 - Answer 285
286 - Answer 286
287 - Answer 287
Question 69
290 - Answer 290
Now take note at the last part of answer.csv, the numbers. What I want:
If the the total of the last set of numbers doesn't add up to 100, then I want the answers displayed, but if they do add up to 100, then they are to be ignored.
A better example is this:
If you notice Question 68 adds up to 50, and Question 69 adds up to 100. So only the following should be created:
Question 68
285 - Answer 285
286 - Answer 286
287 - Answer 287
Question 69 ignored as it reaches 100 in total.
I'm now going to have to post my code in my next post under this, as I've used up all my space explaining this in here, lol.
Bear with me while I add it....
Cheers
-
Jul 20th, 2005, 05:11 AM
#2
Thread Starter
Lively Member
Re: If then else Score
VB Code:
Dim groupList As New SortedList
Dim lineParts As String()
Dim reader As New IO.StreamReader("user_answer.csv")
labelQuestion.Text = "Processing..."
While reader.Peek() <> -1
lineParts = reader.ReadLine().Split(","c)
If Not groupList.ContainsKey(lineParts(1)) Then
groupList.Add(lineParts(1), New ArrayList)
End If
DirectCast(groupList(lineParts(1)), ArrayList).Add(lineParts(2))
End While
Dim tempStr As New System.Text.StringBuilder
For Each groupNumber As String In groupList.GetKeyList()
If tempStr.Length > 0 Then
tempStr.Append(Environment.NewLine)
End If
Dim fsQuestion As New IO.StreamReader("Question.csv")
Dim fsAnswer As New IO.StreamReader("answer.csv")
Dim aLine As String = String.Empty
Dim bLine As String = String.Empty
Dim counter As Int32 = 0
Dim counterB As Int32 = 0
Dim counterC As Int32 = 0
Dim arQuestion() As String
Dim arAnswer() As String
While counter <> groupNumber
aLine = fsQuestion.ReadLine
counter += 1
End While
fsQuestion.Close()
arQuestion = aLine.Split(ControlChars.Tab)
tempStr.Append(arQuestion(2))
tempStr.Append("<br>")
While counterB < (DirectCast(groupList(groupNumber), ArrayList).Count)
tempStr.Append(DirectCast(groupList(groupNumber), ArrayList(counterB))
tempStr.Append(" - ")
While counterC <> (DirectCast(groupList(groupNumber), ArrayList)(counterB))
bLine = fsAnswer.ReadLine
counterC += 1
End While
arAnswer = bLine.Split(ControlChars.Tab)
tempStr.Append(arAnswer(2))
tempStr.Append("<br>")
counterB += 1
End While
Next
Dim writer As StreamWriter = File.CreateText("report.html")
writer.Write(tempStr.ToString())
writer.Close()
labelQuestion.Text = "File Export Complete"
Sorry it took so long :-/
-
Jul 20th, 2005, 09:51 AM
#3
Thread Starter
Lively Member
Re: If then else Score
Just shoved everything in arrays, and then read them out just after the little loop in the middle which let me take more control over what is displayed.
Now works.
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
|