...

View Full Version : VB6 Listbox Help



Geodesic_D
08-25-2007, 12:53 AM
NOT HOMEWORK - My friends don't know VB, so I am doing this for them.

I have written a program that will pick a random name out of a listbox, because I need it for an activity I am involved in.

However, I don't know how to actually display the name chosen from the list. All I get is the index number of that name.

Example: "The winner is 3". I want that to be: "The winner is Sam."

I have tried SelectedIndex, SelectedItem and so on. What am I doing wrong?

Geodesic_D
08-25-2007, 01:12 AM
I should also point out that the names are being added to said list box one at a time using a textbox and a command button.

So I think it would have something to do with the fact I am not assigning index numbers to each name.

Geodesic_D
08-25-2007, 03:40 AM
Ahhh! It was so simple!

I got it, never mind.

SpencerGraevn
12-23-2007, 10:57 PM
edited out

SpencerGraevn
12-23-2007, 11:04 PM
Hello!

I'm working on an RSS Maker for podcasts, and it's been a while since school, so I've forgotten most of my VB6 training.

I have two tables created in Access: "Channels," which contain ID, CTitle and ITitle; and "MasterList," which contains ID and MTitle.

On my form, I have two ListBoxes called lst_channels, which contains the data from MTitle; and lst_items, which I would like to fill with the information from ITitle.

MasterList/MTitle contains a list of Podcasts.
Channels/ITitle contains a list of episodes.
Channels/CTitle shows which Podcast an Episode belongs to.

The following code allows lst_channels to accept the info from MTitle.

Public Sub FillList()
Dim SQL As String
frm_MRPODCAST.lst_CHANNELS.Clear
frm_MRPODCAST.lst_ID.Clear
frm_MRPODCAST.lst_ITEMS.Clear
frm_MRPODCAST.lst_SORTID.Clear

SQL = "SELECT ID, MTitle FROM MasterList"
RS.Open SQL, CN, adOpenStatic, adLockReadOnly
If RS.RecordCount > 0 Then
RS.MoveFirst
End If
While Not RS.EOF
frm_MRPODCAST.lst_CHANNELS.AddItem RS.Fields("MTitle").Value
frm_MRPODCAST.lst_ID.AddItem RS.Fields("ID").Value
RS.MoveNext
Wend
RS.Close
Set RS = Nothing
End Sub


Here's a picture of the interface:
http://fc03.deviantart.com/fs22/i/2007/357/3/8/mrpodcast_by_Caelhath.jpg

Now, I would like to be able to click on a Channel, such as "The Bridge," and have it display a list of all the episodes associated with that file. I wrote up a sub to do that, but I'm having... difficulty. Here's the code.


Public Sub FillITEM()
Dim SQL As String

frm_MRPODCAST.lst_ITEMS.Clear
frm_MRPODCAST.lst_SORTID.Clear

SQL = "Select CTitle, ITitle FROM Channels where CTitle = " & lst_CHANNELS.List
RS.Open SQL, CN, adOpenStatic, adLockOptimistic
If RS.RecordCount > 0 Then
RS.MoveFirst
End If

While Not RS.EOF
frm_MRPODCAST.lst_ITEMS.AddItem RS.Fields("ITitle").Value
frm_MRPODCAST.lst_SORTID.AddItem RS.Fields("CTitle").Value
RS.MoveNext
Wend
RS.Close
Set RS = Nothing
End Sub

When I click on something in the Channels Listbox, I get an "Arguement not optional" popup. When I delete the part that reads where CTitle = " & lst_CHANNELS.List, it simply displays every episode from every podcast. This is logical, since there are no qualifiers in the query, so what do I need to do in order to just pull up the episodes I want?

Can anybody help? I remember this stuff being so much easier!!! A couple years of not working with a program will do that to ya, I suppose.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum