Jump to content

Beginner. Help with a loop.

- - - - -

  • Please log in to reply
1 reply to this topic

#1
stevefox

stevefox

    Newbie

  • Members
  • Pip
  • 2 posts
Hi im 250 pages deep in a VB "get-started" book. Trying to create a program for fun.
I have a lot of checkboxes that I want to check if there Checked. I came up with this loop:


        Dim blnArrayChecks(8) As Boolean


        For intNumber As Integer = 0 To 8


            If chkGame1Box(intNumber).Checked Then blnArrayChecks(intNumber) = True


        Next


The problem is: chkGame1Box(intNumber). Is it anyway I can make this work?

#2
stevefox

stevefox

    Newbie

  • Members
  • Pip
  • 2 posts
Created 3 Panels and got it to work with theese loops:


           Dim c As CheckBox

           Dim intGamesArray(2) As Integer


           For Each c In Panel0.Controls()

            If c.Checked = True Then

                intGamesArray(0) += 1

            End If

        Next


        For Each c In Panel1.Controls()

            If c.Checked = True Then

                intGamesArray(1) += 1

            End If

        Next


        For Each c In Panel2.Controls()

            If c.Checked = True Then

                intGamesArray(2) += 1

            End If

        Next


But it would be nice to do something like this:
(Create one panel and add all 3 panels to that one):

The thing that messes it up is Panel(intNumber).Controls
Is it not possible to define a Class with an variable?

        Dim intNumber As Integer

        Dim c As CheckBox


        For Each Panel In Panel4.Controls()


            intNumber = 0


            For Each c In Panel(intNumber).Controls

                If c.Checked = True Then

                    intGamesArray(intNumber) += 1

                End If

                intNumber += 1

            Next


            intNumber += 1


        Next


Edited by stevefox, 02 January 2012 - 07:41 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users