Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 10th, 2006, 01:01 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default ListBox

good morning everybody
i'm facing a little bit problem

in the declaration section i declared a listbox like this

Dim lst As ListBox

and on the click event of a button i performed this action

Private Sub btn_Click()
lst.AddItem "Item-1"
lst.AddItem "Item-2"
End Sub

but when i click on the button, an unexpected error occurs :-(

iz there any one who can solve my problem (but plz keep in mind, i dont want to place ListBox on the form even its Visible property is set to False)

Reply With Quote
  #2 (permalink)  
Old September 11th, 2006, 08:02 AM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
what is the error message u get

Reply With Quote
  #3 (permalink)  
Old September 11th, 2006, 12:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you cannot "declare" a list box (as well as any other controls)
you must add it at design time, or add it at run time using Controls.Add
Reply With Quote
  #4 (permalink)  
Old September 12th, 2006, 12:32 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default

goog morning

@SriRamaKrishna
yaar, the error message is some thing like "WITH OBJECT VARIABLE NOT SET..."

@marcostraf
friend, if we can't declare any control (according 2 u), then why it is allowed in VB, i mean, when i type Dim lst As ... just after typing the word "As", all the datatypes are listed including all controls ... if declaring controls is not allowed then why all the controls are displayed in the list???

i hope i'll get a good reply

Reply With Quote
  #5 (permalink)  
Old September 12th, 2006, 12:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is not that you cannot "declare" controls (I put the word in quotes in my previous msg), but then you have to initialize the variable.

Dim lst as ListBox

is a perfectly legittimate statement, but unless you initialize the variable lst, you get a "object variable not set" error. To initialize it, or you have to assign to it a already created listBox control

set lst = myList

or you can set to it a controls that you are adding at run time like

set lst = me.Controls.Add(....

or just use the name of a ListBox already created, and skip the declaration of lst

Hope this time I was more clear!

Marco
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ListBox obrienkev C# 2005 4 November 6th, 2007 03:15 AM
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Listbox vanjamier Pro JSP 0 January 6th, 2005 09:44 PM
About listbox csc820203 C# 1 April 29th, 2004 06:17 AM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM



All times are GMT -4. The time now is 07:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.