Wednesday, January 6, 2010

How to make a labelbox's caption to change when an item in a listbox is selected in Visual Basic 6.0?

I made a program that when an item in a listbox was selected then the labelbox's caption would change. below is the code of program





************code***********





Private Sub Form_Load()


'init listbox


With Me.List1


.AddItem ';A';


.AddItem ';B';


.AddItem ';C';


End With


End Sub








Private Sub List1_Click()


'if listbox item selected, set label caption


If List1.ListIndex %26gt; -1 Then


Label1.Caption = ';hello!';


End If





End Sub





**********************************





these codes work but my problem is that all the items on listbox can only make the label's caption = ';helllo!'; but what I want to happen is that each item on the listbox can make different captions on the labelbox. for example if I clicked an item the listbox the label's caption would be ';hello!'; and when I clicked anpther item the label's caption would change to a different one....





please help in this one....


thanks to the one that will answer my question....How to make a labelbox's caption to change when an item in a listbox is selected in Visual Basic 6.0?
I don't know how many items in your list box, but you could use something like:





Select Case lstBox.listindex


Case 1


lblBox.Caption = ';Hello';


Case 2


lblBox.Caption = ';Goodbye';





.....etc, etc, etc





Case Else





End Select
  • myspace code
  • No comments:

    Post a Comment