Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004

    Unanswered: VBA class problem

    Alright, I am trying to load a bunch of info from an excel spreadsheet into a list. I made a class that holds all this crap for me. I work with C++ mostly and I just started using VBA this week, so the answer is probably simple, but for some reason the following code does not work:

    Do Until ProgSheet.Cells(Row, 15).Text = ""

    Dim NewProduct As New Product
    NewProduct.Name = ProgSheet.Cells(Row, 15).Text
    NewProduct.Row = Row
    Products(Hash(Temp.Name)).Add (NewProduct)


    Products has already been declared, it is a linked list of the Product class. But for some reason, there is an error on the line:

    NewProduct.Name = ProgSheet.Cells(Row, 15).Text

    It tells me <Object variable or With block variable not set>

    Now this is supposed to be the same as a NULL reference exception in C++, it means that NewProduct isnt actually set to a Product. But isnt that what:
    Dim NewProduct As New Product
    is supposed to do?

    What am I doing wrong here? I;ve tried changing it to:
    Dim NewProduct as Product
    Set NewProduct = New Product

    But it won't even let me do the set, it comes up with the same error.

  2. #2
    Join Date
    Apr 2004
    Derbyshire, UK
    Provided Answers: 2
    Hi TheShrike

    Comments and observation as follows:-

    I believe that either the New keyword in the the Dim statment Or in a set statment will work (but not both!)

    I assume the Row variable has been dimensioned (integer or long !) and set to 1 or more

    The Row variable is not updated in the loop which will therefore never exit !!?

    You have not indicated what 'Products(Hash(Temp.Name)).Add (NewProduct)'
    is trying to do (ie what are 'Products', 'Hash' and 'Temp.Name')

    You also seem to be trying to add an instance of the Products class and not a Property of the Object to a ??
    If list is a List or Combo control then I am not sure this is possible !!

    I also assume the properties of the class have been defined ie Name, Row

    Any more info would help


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts