Results 1 to 2 of 2

Thread: How would I do this?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    6

    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

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Why not pass in the labels instead?
    VB Code:
    1. Private Sub DisplayNext(ByVal lbl1 As Label, ByVal lbl2 As Label, Optional ByVal lbl3 As Label = Nothing, ...)
    2.    lbl1.Visible = False
    3.    lbl2.Visible = False
    4.    If Not (lbl3 Is Nothing) Then
    5.       lbl3.Visible = False
    6.    End If
    7.    'etc...
    8. End Sub
    9.  
    10. Private Sub Test()
    11.    DisplayNext(lblCon1, lblCon2, lblCon3,....)
    12. 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
  •  



Click Here to Expand Forum to Full Width