Results 1 to 3 of 3

Thread: [RESOLVED] Beginner need some help with an Array that gets a System.NullReferenceException

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    2

    Resolved [RESOLVED] Beginner need some help with an Array that gets a System.NullReferenceException

    Hi all, I am making a program that gets some information from a file, splits the data and stores it in an Array. Problem is I get the following error after using the split method and trying to assign the values to the array(called inventory for a quick search):

    System.NullReferenceException: 'Object reference not set to an instance of an object.'

    inventory was Nothing.
    I don't really get this error. Does it mean that I need to give the array some values before doing anything with it? Here's my code so far:

    <cd here>

    Any help would be appreciated for a newbie like me.
    Last edited by Soap; May 19th, 2022 at 07:01 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Beginner need some help with an Array that gets a System.NullReferenceException

    The problem is that you haven't dimensioned the array - you're attempting to use elements that don't exist

    Code:
    Redim Preserve inventory(intCount)
    With inventory(intCount)
        .strProductNumber = strFields(0)
        .strProductDescription = strFields(1)
        .intProductQuantity = CInt(strFields(2))
        .dblProductCost = CDbl(strFields(3))
        .dblProductMarkup = CDbl(strFields(4))
    End With

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    2

    Re: Beginner need some help with an Array that gets a System.NullReferenceException

    Quote Originally Posted by .paul. View Post
    The problem is that you haven't dimensioned the array - you're attempting to use elements that don't exist

    Code:
    Redim Preserve inventory(intCount)
    With inventory(intCount)
        .strProductNumber = strFields(0)
        .strProductDescription = strFields(1)
        .intProductQuantity = CInt(strFields(2))
        .dblProductCost = CDbl(strFields(3))
        .dblProductMarkup = CDbl(strFields(4))
    End With

    Thank you, that worked. You may not think it, but you just made my day.

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