|
-
May 14th, 2004, 07:26 PM
#1
Thread Starter
New Member
How would I do this?
I made a sub to hide a selection of labels and display a new section, but I don't know how to include a variable into a function like lblCon.Visible. Here's what I mean, examine my current code:
Code:
Public Sub DisplayNext(ByVal HideObject1 As Integer, ByVal HideObject2 As Integer, ByVal HideObject3 As Integer, ByVal HideObject4 As Integer, ByVal HideObject5 As Integer, ByVal HideObject6 As Integer)
lblCon1.Visible = False
lblCon2.Visible
End Sub
Now what I want to do is something like "lblCon(HideObject1).Visible = False" so say, I call the function like this:
"DisplayNext(1,2,3)" so the function would do this: "lblCon1.Visible = False lblCon2.Visible = False lblCon3.Visible = False"
how would I do that? I think the main question is, how do I include a variable in a function like that? lblCon#.Parameter
-
May 14th, 2004, 07:49 PM
#2
Frenzied Member
Why not pass in the labels instead?
VB Code:
Private Sub DisplayNext(ByVal lbl1 As Label, ByVal lbl2 As Label, Optional ByVal lbl3 As Label = Nothing, ...)
lbl1.Visible = False
lbl2.Visible = False
If Not (lbl3 Is Nothing) Then
lbl3.Visible = False
End If
'etc...
End Sub
Private Sub Test()
DisplayNext(lblCon1, lblCon2, lblCon3,....)
End Sub
You could probably iterate through the labels in DisplayNext in a loop if you had a lot of them, or pass them in as an array. But I don't think you can take your integer parameters and append them to the rest of the label name, even if you passed them as a string instead of an integer, which is what I think you're looking for. A control's name isn't a string, so that doesn't work.
Other options would be to use the Tag property of the labels and check for that, or maybe use a control array (that'd be a VB6 way, don't know if it's the same in .Net).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|