Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2003, 10:29 PM
VB_Oracle VB_Oracle is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 18 VB_Oracle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
VB ListBox error...please help

When I try to display the text selected from a ListBox onto the caption of a label, I get the "Compile error: Argument not optional". Below is the code I'm using, please help:


Private Sub ListBox2_Click()

Label17.Caption = ListBox2.Selected

End Sub

Reply With Quote
  #2  
Old November 26th, 2003, 11:38 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
small syntactical error... try this

Code:
Label17.Caption = ListBox2.Selected(ListBox2.ListIndex)


A ListBox's selected item is designated by a zero-based array index, that's the argument that is missing
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #3  
Old November 26th, 2003, 11:45 PM
VB_Oracle VB_Oracle is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 18 VB_Oracle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The above code displays "true" in the label caption NOT the actual text of what is selected in the listbox. How can I get it to display the actual text of what is selected...

for example, in my list box i have the following cities displayed:

chicago
new york
boston

when a person clicks on chicago, i would like the label caption to display chicago.

Thanks for all the help.

Reply With Quote
  #4  
Old November 27th, 2003, 02:05 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
My bad.. a few Tgiving beers and my mind doesn't work anymore... it should be this instead...

Code:
Label17.Caption = ListBox2.List(ListBox2.ListIndex)

Reply With Quote
  #5  
Old November 27th, 2003, 02:08 AM
VB_Oracle VB_Oracle is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 18 VB_Oracle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Another question related to that:

In my listbox, I'm displaying multiple rows of the following [it's the result of a query sent to Oracle]:

ListBox.AddItem rs("city") & (" ") & rs("phone")

When the user clicks on the ListBox, I would like to have just "city" (not "phone") of that particular selected entry displayed on Label1.Caption. How can I do that? Please help. Thanks.

P.S. Label1.Caption = ListBox.Text OR Label17.Caption = ListBox2.List(ListBox2.ListIndex) would display both "city" and "phone" in the caption...I would like to display just the "city".

Reply With Quote
  #6  
Old November 27th, 2003, 02:00 PM
matos240 matos240 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 5 matos240 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello VB_Oracle. The code I sent to you earlier had the MyString variable dimmed as a string. That was wrong. Try Dim MyString as variant. Since the split function returns an array. The only problem with that bit of Code is if the city was a two word city like "Fort Lauderdale" then only Fort will be in the label1.caption.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > VB ListBox error...please help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway