Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Dim item As ListItem

Hi,

I get an error on line 2 in this code:

Dim item As ListItem
item.Text = product.Name
ListBox1.AddItem item
products.Add product, product.Name

The error is

Object variable of With block variable not set

For some reason, the ListItem object won't let itself be instantiated:

Dim item As ListItem
Set tem = New ListItem ' Compile error

My idea is to first instantiate a ListItem, set some properties to it and THEN add it to the ListBox. Why doesn't that work?

Gustaf
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Dim item As ListItem

What object library is ListItem from? Do you have a reference set to
its object library?

--JP

On Sep 24, 11:17*am, Gustaf wrote:
Hi,

I get an error on line 2 in this code:

* Dim item As ListItem
* item.Text = product.Name
* ListBox1.AddItem item
* products.Add product, product.Name

The error is

* Object variable of With block variable not set

For some reason, the ListItem object won't let itself be instantiated:

* Dim item As ListItem
* Set tem = New ListItem *' Compile error

My idea is to first instantiate a ListItem, set some properties to it and THEN add it to the ListBox. Why doesn't that work?

Gustaf


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Dim item As ListItem

afaik there is no listobject item. you can put text into a list , but not an
object unless its a string

Dim oitem As Object
Set oitem = New Class1
oitem.val = "A"
ListBox1.AddItem oitem.val

here class1 is an object with one property, val defined as string.
your method would work with a collection - such as the scripting dictionary





"Gustaf" wrote:

Hi,

I get an error on line 2 in this code:

Dim item As ListItem
item.Text = product.Name
ListBox1.AddItem item
products.Add product, product.Name

The error is

Object variable of With block variable not set

For some reason, the ListItem object won't let itself be instantiated:

Dim item As ListItem
Set tem = New ListItem ' Compile error

My idea is to first instantiate a ListItem, set some properties to it and THEN add it to the ListBox. Why doesn't that work?

Gustaf

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Dim item As ListItem

Hi,

Right, I had mistakenly added a reference to mscomctl.ocx, where ListItem is. Unfortunately, I can't add any dependencies to this project, since it will cause problems for the users. I assume there is no way to tie an object to a listbox item without using controls not available by default in VBA, so I'll have to find another way.

Gustaf

--
Patrick Molloy wrote:
afaik there is no listobject item. you can put text into a list , but not an
object unless its a string

Dim oitem As Object
Set oitem = New Class1
oitem.val = "A"
ListBox1.AddItem oitem.val

here class1 is an object with one property, val defined as string.
your method would work with a collection - such as the scripting dictionary





"Gustaf" wrote:

Hi,

I get an error on line 2 in this code:

Dim item As ListItem
item.Text = product.Name
ListBox1.AddItem item
products.Add product, product.Name

The error is

Object variable of With block variable not set

For some reason, the ListItem object won't let itself be instantiated:

Dim item As ListItem
Set tem = New ListItem ' Compile error

My idea is to first instantiate a ListItem, set some properties to it and THEN add it to the ListBox. Why doesn't that work?

Gustaf

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Dim item As ListItem

so instead of

item.Text = product.Name
ListBox1.AddItem item

what is wrong with

ListBox1.AddItem product.name

"Gustaf" wrote:

Hi,

Right, I had mistakenly added a reference to mscomctl.ocx, where ListItem is. Unfortunately, I can't add any dependencies to this project, since it will cause problems for the users. I assume there is no way to tie an object to a listbox item without using controls not available by default in VBA, so I'll have to find another way.

Gustaf

--
Patrick Molloy wrote:
afaik there is no listobject item. you can put text into a list , but not an
object unless its a string

Dim oitem As Object
Set oitem = New Class1
oitem.val = "A"
ListBox1.AddItem oitem.val

here class1 is an object with one property, val defined as string.
your method would work with a collection - such as the scripting dictionary





"Gustaf" wrote:

Hi,

I get an error on line 2 in this code:

Dim item As ListItem
item.Text = product.Name
ListBox1.AddItem item
products.Add product, product.Name

The error is

Object variable of With block variable not set

For some reason, the ListItem object won't let itself be instantiated:

Dim item As ListItem
Set tem = New ListItem ' Compile error

My idea is to first instantiate a ListItem, set some properties to it and THEN add it to the ListBox. Why doesn't that work?

Gustaf


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
To find rate of each item from item.xls and to copy price.xls pol Excel Discussion (Misc queries) 7 July 16th 09 12:49 AM
Return ListItem via HitTest Desi Excel Programming 0 July 22nd 08 12:09 AM
Item numbers result in item description in next field in Excel Cheryl MM Excel Worksheet Functions 1 February 20th 07 03:51 PM
Problem with ListItem Width allenj3 Excel Programming 1 June 29th 06 08:29 PM
disable listitem Roland Excel Programming 2 December 13th 04 08:49 PM


All times are GMT +1. The time now is 01:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"