mike2
01-31-2004, 03:14 AM
Hi.I have a list box and 16 labels.The listbox.listcount should be 16 like the labels.Now when I click a button I would like label1.caption to be list1.listindex 0 , label2.caption to be list1.listindex 1 etc...
Private Sub Form_Load()
Dim i As Integer
For i = 0 To frmEnter.lstSeeds.ListCount - 1
lblSeed1.Caption = frmEnter.lstSeeds.List(i)
Next
End Sub
That works only for one label.How can I do this for many labels?
Thanks :chuckle:
martrinex
01-31-2004, 03:33 AM
ah, don't do like that!
use an array of labels
lblSeed(1), lblSeed(2), lblSeed(3) '< to 16
now:
Private Sub Form_Load()
Dim i As Integer
For i = 0 To frmEnter.lstSeeds.ListCount - 1
if i+1 > ubound lblSeed then
msgbox "out of range add more labels"
'you could also dynamicly create labels here
else
lblSeed(i+1).Caption = frmEnter.lstSeeds.List(i)
end if
Next
End Sub
mike2
01-31-2004, 03:39 AM
ah, don't do like that!
Private Sub Form_Load()
Dim i As Integer
For i = 0 To frmEnter.lstSeeds.ListCount - 1
if i+1 > ubound lblSeed then
msgbox "out of range add more labels"
'you could also dynamicly create labels here
else
lblSeed(i+1).Caption = frmEnter.lstSeeds.List(i)
end if
Next
End Sub
Hmmm...I get a "Syntax Error" on the bolded code...
Whats wrong...?
martrinex
01-31-2004, 03:55 AM
sorry i fogot to place in ()
Private Sub Form_Load()
Dim i As Integer
For i = 0 To frmEnter.lstSeeds.ListCount - 1
if i+1 > UBound(lblSeed) then
msgbox "out of range add more labels"
'you could also dynamicly create labels here
Else
lblSeed(i+1).Caption = frmEnter.lstSeeds.List(i)
End If
Next
End Sub
mike2
01-31-2004, 03:58 AM
Now getting Type mismatch... :-\
martrinex
01-31-2004, 04:02 AM
maybe i should test theis things before sending, this 1 is right i tested it :D
Private Sub Form_Load()
Dim i As Integer
For i = 0 To frmenter.lstseeds.ListCount - 1
If i + 1 > lvlseed.UBound Then
MsgBox "out of range add more labels"
'you could also dynamicly create labels here
Else
lblseed(i + 1).Caption = frmenter.lstseeds.List(i)
End If
Next
End Sub
mike2
01-31-2004, 04:16 AM
maybe i should test theis things before sending, this 1 is right i tested it :D
Private Sub Form_Load()
Dim i As Integer
For i = 0 To frmenter.lstseeds.ListCount - 1
If i + 1 > lvlseed.UBound Then
MsgBox "out of range add more labels"
'you could also dynamicly create labels here
Else
lblseed(i + 1).Caption = frmenter.lstseeds.List(i)
End If
Next
End Sub
Doesnt work on me :(
Fixed a typo(If i + 1 > lvlseed.UBound Then)Tried doing : If i + 1 > lblseed but it still doesnt work...
Whats wrong?
thingimijig
01-31-2004, 04:50 AM
if your labels are in an array do this
Dim i As Integer
For i = 0 To frmEnter.lstSeeds.ListCount - 1
lblSeed1(i).Caption = frmEnter.lstSeeds.List(i)
Next i
thingimijig.
mike2
01-31-2004, 05:00 AM
if your labels are in an array do this
Dim i As Integer
For i = 0 To frmEnter.lstSeeds.ListCount - 1
lblSeed1(i).Caption = frmEnter.lstSeeds.List(i)
Next i
thingimijig.
Doesnt work :(
thingimijig
01-31-2004, 05:06 AM
what doesnt work ?
is your labels in an array ?
thingimijig.
HarvestR
01-31-2004, 05:28 AM
what doesnt work ?
is your labels in an array ?
thingimijig.
Hint: To have an array of controls (ie Labels), they must all have the same name, with a different Index propertie value.
You can select the lblSeed label on your form, then copy/paste it to this same form. VB will ask you if you want to create a controls array, answer Yes.
Then paste until your 16 labels are on the form. VB will assign them an Index value automatically.
Now you have lblSeed(0), lblSeed(1)... lblSeed(15) (yes first Index value is 0, not 1... VB mystery) ;)
Now you can use the code thingimijig gave you (with a little change in the label name to fit my exemple) :
For i = 0 To frmEnter.lstSeeds.ListCount - 1
lblSeed(i).Caption = frmEnter.lstSeeds.List(i)
Next i
Hope you're OK with it now.