Results 1 to 3 of 3

Thread: [RESOLVED] If then else Score

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    England
    Posts
    79

    Resolved [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

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    England
    Posts
    79

    Re: If then else Score

    VB Code:
    1. Dim groupList As New SortedList
    2. Dim lineParts As String()
    3. Dim reader As New IO.StreamReader("user_answer.csv")
    4.  
    5. labelQuestion.Text = "Processing..."
    6.  
    7. While reader.Peek() <> -1
    8.   lineParts = reader.ReadLine().Split(","c)
    9.   If Not groupList.ContainsKey(lineParts(1)) Then
    10.     groupList.Add(lineParts(1), New ArrayList)
    11.   End If
    12.   DirectCast(groupList(lineParts(1)), ArrayList).Add(lineParts(2))
    13. End While
    14.  
    15. Dim tempStr As New System.Text.StringBuilder
    16.  
    17. For Each groupNumber As String In groupList.GetKeyList()
    18.   If tempStr.Length > 0 Then
    19.     tempStr.Append(Environment.NewLine)
    20.   End If
    21.  
    22.   Dim fsQuestion As New IO.StreamReader("Question.csv")
    23.   Dim fsAnswer As New IO.StreamReader("answer.csv")
    24.   Dim aLine As String = String.Empty
    25.   Dim bLine As String = String.Empty
    26.   Dim counter As Int32 = 0
    27.   Dim counterB As Int32 = 0
    28.   Dim counterC As Int32 = 0
    29.   Dim arQuestion() As String
    30.   Dim arAnswer() As String
    31.  
    32.   While counter <> groupNumber
    33.     aLine = fsQuestion.ReadLine
    34.     counter += 1
    35.   End While
    36.  
    37.   fsQuestion.Close()
    38.   arQuestion = aLine.Split(ControlChars.Tab)
    39.  
    40.   tempStr.Append(arQuestion(2))
    41.   tempStr.Append("<br>")
    42.   While counterB < (DirectCast(groupList(groupNumber), ArrayList).Count)
    43.     tempStr.Append(DirectCast(groupList(groupNumber), ArrayList(counterB))
    44.     tempStr.Append(" - ")
    45.     While counterC <> (DirectCast(groupList(groupNumber), ArrayList)(counterB))
    46.       bLine = fsAnswer.ReadLine
    47.       counterC += 1
    48.     End While
    49.     arAnswer = bLine.Split(ControlChars.Tab)
    50.     tempStr.Append(arAnswer(2))
    51.     tempStr.Append("<br>")
    52.     counterB += 1
    53.   End While
    54. Next
    55.  
    56. Dim writer As StreamWriter = File.CreateText("report.html")
    57. writer.Write(tempStr.ToString())
    58. writer.Close()
    59.  
    60. labelQuestion.Text = "File Export Complete"

    Sorry it took so long :-/

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    England
    Posts
    79

    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
  •  



Click Here to Expand Forum to Full Width