Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 10th, 2006, 01:01 AM
Authorized User
 
Join Date: Aug 2005
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)

 
Old September 11th, 2006, 08:02 AM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
what is the error message u get

 
Old September 11th, 2006, 12:49 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old September 12th, 2006, 12:32 AM
Authorized User
 
Join Date: Aug 2005
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

 
Old September 12th, 2006, 12:28 PM
Friend of Wrox
 
Join Date: Jun 2003
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.