Results 1 to 5 of 5

Thread: [UNRESOLVED] Need help with a collection in an array

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Thumbs down [UNRESOLVED] Need help with a collection in an array

    Hi all

    Im having trouble displaying part of my structure when reading it back out of an array

    basicly

    i read in from a csv file
    grab the user name and the total the use was charged
    create a entry into a sorted list useing the usersname as the key
    then for the value i have a collection and add the name , department , total)

    if the user shows up again while going through the csv file i will simply add the total to the existing total


    when i watch the variables in the watcher everything adds up fine
    but when i display it it comes out as the first entry into the collection



    Now i first thought mabey it was just doing something funky with the conversion between int and dec or soemthing like that
    but then i checked in the csv file and 47.02 is the frist entry for this user

    so basicly i am completely lost
    Last edited by Crash893; Jul 5th, 2006 at 02:56 PM.

  2. #2

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Need help with a collection in an array

    VB Code:
    1. Imports System.IO
    2. Imports System.Text.Encoding
    3. Imports System.Text.RegularExpressions
    4.  
    5. Public Class Form1
    6.  
    7.     Private Sub ExitToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    8.         Me.Close()
    9.     End Sub
    10.  
    11.     Private strSourcePath As String
    12.     Dim ipassinfo As New SortedList
    13.     Public Structure user
    14.         'Declare data members
    15.         Public username As String
    16.         Public department As String
    17.         Public domestictotal As Decimal
    18.     End Structure
    19.     Dim userinfo As New user
    20.     Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    21.         Tb_totals.Clear()
    22.         tb_usertotals.Clear()
    23.         tb_linesproccessed.Clear()
    24.  
    25.  
    26.         With Me.OpenFileDialog1
    27.             .InitialDirectory = "C:\"
    28.             ' The file could be of any type. The Filter is restricted to Text Format
    29.             ' files only for demonstration purposes.
    30.             .Filter = "Tab delmited (*.csv)|*.csv"
    31.             .FilterIndex = 1
    32.  
    33.             ' The OpenFileDialog control only has an Open button, not an OK button.
    34.             ' However, there is no DialogResult.Open enum so use DialogResult.OK.
    35.             If .ShowDialog() = Windows.Forms.DialogResult.OK Then
    36.                 strSourcePath = .FileName
    37.  
    38.  
    39.                 Dim datipass As New StreamReader(.FileName)
    40.                 '*'' Dim totalChargeByName As New SortedList
    41.                 Dim fields As String()
    42.                 Dim count As Int16
    43.  
    44.                 Do Until datipass.Peek() = -1
    45.                     Dim MyLine As String = datipass.ReadLine
    46.                     Dim myparse As String
    47.  
    48.                     'create variable for "'"
    49.                     myparse = (ControlChars.Quote & "," & ControlChars.Quote)
    50.                     'Replace "," with tab's
    51.                     MyLine = MyLine.Replace(myparse, ControlChars.Tab)
    52.                     'remove certian words
    53.                     MyLine = MyLine.Replace("usatoday\", "")
    54.                     MyLine = MyLine.Replace("eu\", "")
    55.                     'forces everythign to lower
    56.                     MyLine = MyLine.ToLower
    57.                     'break feild up on tabs
    58.                     fields = MyLine.Split(ControlChars.Tab) 'Or Convert.ToChar(Keys.Tab)
    59.  
    60.  
    61.                     'check to see if entrie already exists if not create it
    62.                     If ipassinfo(fields(2)) Is Nothing Then
    63.                         'loading the structure
    64.                         userinfo.username = fields(2)
    65.                         userinfo.department = "???"
    66.                         userinfo.domestictotal = fields(9)
    67.                         'adding the structure to the sortedlist under key username
    68.                         ipassinfo.Add((fields(2)), userinfo)
    69.                     Else
    70.                         ' adds charges to total if allready exists
    71.                         userinfo.domestictotal = userinfo.domestictotal + fields(9)
    72.                     End If
    73.                     count = count + 1
    74.                 Loop
    75.                 Me.tb_linesproccessed.Text = count
    76.                 'release the access of the file
    77.                 datipass.Close()
    78.  
    79.                 Dim x As String
    80.                 Dim y As Decimal
    81.                 Dim total As Decimal
    82.                 Dim i As Integer
    83.  
    84.                 For i = 0 To ipassinfo.Count - 1
    85.                     x = ipassinfo.GetKey(i)
    86.  
    87.                     y = DirectCast(ipassinfo.GetByIndex(i), user).domestictotal
    88.                     total = y + total
    89.  
    90.                     tb_usertotals.AppendText(x.PadRight(20) & ControlChars.Tab & y.ToString("C") & vbNewLine)
    91.                     Me.tb_usersmade.Text = i
    92.                 Next i
    93.                 Me.Tb_totals.Text = total.ToString("c")
    94.              
    95.             End If
    96.         End With
    97.     End Sub

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Need help with a collection in an array

    anyone

    i could use a hand

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,242

    Re: Need help with a collection in an array

    I'm afraid I don't have a real answer, just some suggestions as to how to dig further.

    From your first post, it certainly appears like Y should be the same as domestictotal, since you are assigning the domestictotal property of the User type to Y. If you were to break on that very line, and look at ipassinfo.GetByIndex(i), does this value look correct? You should be able to see all the properties of that, without the DirectCast.


    Ok, just re-re-read your first post. You seem to suggest with the final phrase that Y is correct, and the domestictotal being shown is in error. I guess I do not fully understand that phrase, or this one:

    when i watch the variables in the watcher everything adds up fine
    but when i display it it comes out as the first entry into the collection
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Need help with a collection in an array

    ill check on that
    thanks
    Last edited by Crash893; May 5th, 2006 at 11:04 AM.

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