If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VBA class problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-20-04, 17:19
TheShrike TheShrike is offline
Registered User
 
Join Date: May 2004
Posts: 1
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)

Loop

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.
Reply With Quote
  #2 (permalink)  
Old 05-24-04, 09:20
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
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

MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On