Results 1 to 9 of 9

Thread: [RESOLVED] [2005] component array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Resolved [RESOLVED] [2005] component array

    how do i set up an object array in VS 2005? i have tried naming two objects the same thing but it gives me an error saying that the namespace is already being used. i need to set up an array of picture boxes if that helps any. they all need to have the same name (imgSnake+array #(like imgSnake0))

    anyone know what to do?
    Last edited by bagstoper; Apr 26th, 2008 at 06:41 PM.

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2005] component array

    Dang. now i am sad. is there any way to work around that?

  4. #4
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] component array

    yes, but each control has to have its own name. lets say you wanted to make an array of groupboxes and then wanted to cycle through them, you would do the following:
    vb Code:
    1. 'make the array
    2. Private arrGroupBoxes() As GroupBox
    3. 'initial index start for the array
    4. Private intIndex As Index = 0
    then in the form load (as an example), you would add the relevant group boxes by name to the array
    vb Code:
    1. 'add the elements to the array by name
    2. arrGroupBoxes = New GroupBox() {groupbox1, groupbox2, groupbox3}
    then if you wanted to use a button to go forward and nother to go back, you do this:
    vb Code:
    1. Private Sub cmdBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBack.Click
    2. 'make the group boxes invisible
    3. arrGroupBoxes(intIndex).Visible = False
    4.  
    5. 'decrease
    6. intIndex -= 1
    7.  
    8. With arrGroupBoxes(intIndex)
    9. 'do something
    10. End With
    11. End Sub
    vb Code:
    1. Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
    2. 'make the group boxes invisible
    3. arrGroupBoxes(intIndex).Visible = False
    4.  
    5. 'increase
    6. intIndex += 1
    7.  
    8. With arrGroupBoxes(intIndex)
    9. 'do something
    10. End With
    11. End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2005] component array

    Ok, that will work for what i am wanting to do thanks so much for your help. (rated you)

  6. #6

  7. #7
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: [RESOLVED] [2005] component array

    I'm trying to do the same thing but with check boxes. I followed the script, and I'm having trouble trying to get the check boxes to become visible. What am I missing here?



    Code:
    Imports Toub.Sound.Midi
    Public Class Form1
        Private chekbox(10) As CheckBox
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            For i = 1 To 10
                chekbox(i) = New CheckBox()
                chekbox(i).Visible = True
                chekbox(i).Left = i
                chekbox(i).Top = i
            Next
        End Sub
    End Class

  8. #8
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [RESOLVED] [2005] component array

    if you already have the checkboxes on the form and you want to make them all visible with a mouse click of a button, you could do something like:
    vb Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.  
    3. For Each ctrl As Control In Me.Controls
    4. If TypeOf ctrl is CheckBox Then
    5. me.ctrl.visible=True
    6. End If
    7. Next ctrl
    8.  
    9. End Sub

  9. #9
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [RESOLVED] [2005] component array

    youre trying to do a control array and they dont exist in .NET

    Quote Originally Posted by MotoMan_Yz400
    I'm trying to do the same thing but with check boxes. I followed the script, and I'm having trouble trying to get the check boxes to become visible. What am I missing here?



    Code:
    Imports Toub.Sound.Midi
    Public Class Form1
        Private chekbox(10) As CheckBox
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            For i = 1 To 10
                chekbox(i) = New CheckBox()
                chekbox(i).Visible = True
                chekbox(i).Left = i
                chekbox(i).Top = i
            Next
        End Sub
    End Class

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