Link to home
Start Free TrialLog in
Avatar of NCSA SCADA
NCSA SCADAFlag for United States of America

asked on adding to array list error

I have a project I am working on that is giving me fits.
I read in a comma seperated file.  loop until EndofStream - works great to this point - I have an object named city with the following properties (name, airfare, carrental, hotel)
i set the value of the properties based on what is read from the text file... everything still works great.... last but not least I add properties to a collection list... well i try... this is where it errors..... +            System.NullReferenceException      {"Object reference not set to an instance of an object."}      System.NullReferenceException

I am just stuck here .. any help would be great
 Private Shared Function Build(ByVal srCity As IO.StreamReader, _
                           ByRef colCities As List(Of City), _
                           ByRef strError As String) As Boolean
        '*  Reads through the City file designated by srFile
        '*  Building the City collection colCities
        '*  Parameters: 
        '*      srCity      stream reader of the City filr
        '*      colCities   collection of cities with names and prices
        '*      strError    If there is an error, it is returned here
        '*  Returns True if file was successfully read
        '*          False if not
        Const c_chrComma As Char = ","c
        Const c_strCityInvalidFormat As String = mc_strCity + " invalid format"

        Dim a_strCity() As String
        Dim objCity As New City

            Do Until srCity.EndOfStream

                a_strCity = srCity.ReadLine.Split(c_chrComma)

                objCity.Name = a_strCity(0)
                objCity.Airfare = Convert.ToDecimal(a_strCity(1))
                objCity.CarRental = Convert.ToDecimal(a_strCity(2))
                objCity.Hotel = Convert.ToDecimal(a_strCity(3))

            Return True
        Catch ex As Exception
            strError = c_strCityInvalidFormat
            Return False
        End Try

    End Function

Open in new window

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NCSA SCADA


Thank you..... I have been trying to figure this out for a few hours... it seems so simple now :)
thanks again