Avatar of NCSA SCADA
NCSA SCADA
Flag for United States of America asked on

VB.net 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


        Try
            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))


                colCities.Add(objCity)
            Loop
            Return True
        Catch ex As Exception
            strError = c_strCityInvalidFormat
            Return False
        Finally
            srCity.Close()
        End Try

    End Function

Open in new window

Visual Basic.NETASP.NET

Avatar of undefined
Last Comment
NCSA SCADA

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dirk Haest

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
NCSA SCADA

ASKER
Thank you..... I have been trying to figure this out for a few hours... it seems so simple now :)
thanks again
Your help has saved me hundreds of hours of internet surfing.
fblack61