Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,471 VB.NET Programmers. There are 1,200 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Visual Basic Programming

 
Reply to this topicStart new topic

Visual Basic Programming

victorB
post 6 May, 2008 - 08:11 PM
Post #1


New D.I.C Head

*
Joined: 22 Mar, 2008
Posts: 11




I am painting a 2-dimensional array of labels on the form. The user can input the size of the array from 1x1 to 8x8. I am alternating the color of the rows or columns between red and blue. After the labels are painted on the form, i want to toggle the color of rows or columns. Now, if the program, alternates the color of the rows, after pushing the toggle button then the next time the toggle button is pushed i would like the columns to alternate in color. I am able to get the rows or columns to aternate in color; however,, i can not get the program to alternate between rows and columns. I used a Boolean; however, not effectively. Any help would be appreciated.


CODE
Public Class finalPartBForm

    Private gridLabelArray(,) As Label
    'Private rowInteger, columnInteger As Integer
    Private rowsInteger, columnsInteger As Integer
    Dim toggleBoolean As Boolean = True
    Private Sub startButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click
        
        Try

            rowsInteger = Integer.Parse(rowTextBox.Text) - 1
            columnsInteger = Integer.Parse(columnTextBox.Text) - 1

            If rowsInteger < 0 Or rowsInteger > 7 Then
                MessageBox.Show("Please enter an integer between 1 & 8", "Data entry error", MessageBoxButtons.OK)
                rowTextBox.Text = ""
                rowTextBox.Focus()
            ElseIf columnsInteger < 0 Or columnsInteger > 7 Then
                MessageBox.Show("Please enter an integer between 1 & 8", "Data entry error", MessageBoxButtons.OK)
                columnTextBox.Text = ""
                columnTextBox.Focus()
            Else
                ReDim gridLabelArray(rowsInteger, columnsInteger)
                Dim rowIndex, columnIndex As Integer
                For rowIndex = 0 To rowsInteger
                    For columnIndex = 0 To columnsInteger
                        Dim theLabel As New Label
                        With theLabel
                            '.SetBounds(60 + 46 * columnIndex, 120 + 46 * rowIndex, 45, 45)
                            If toggleBoolean Then
                                If columnIndex Mod 2 = 0 Then
                                    .BackColor = Color.Red
                                Else
                                    .BackColor = Color.Blue
                                End If
                                .SetBounds(60 + 46 * columnIndex, 100 + 46 * rowIndex, 45, 45)
                                Controls.Add(theLabel)
                                gridLabelArray(rowIndex, columnIndex) = theLabel
                            End If
                        End With
                    Next
                Next



                If toggleBoolean = False Then
                    ReDim gridLabelArray(rowsInteger, columnsInteger)
                    'Dim rowIndex, columnIndex As Integer
                    For rowIndex = 0 To rowsInteger
                        For columnIndex = 0 To columnsInteger
                            Dim theLabel As New Label
                            With theLabel
                                '.SetBounds(60 + 46 * columnIndex, 120 + 46 * rowIndex, 45, 45)
                                If rowIndex Mod 2 = 0 Then
                                    .BackColor = Color.Red
                                Else
                                    .BackColor = Color.Blue
                                End If
                                .SetBounds(60 + 46 * columnIndex, 100 + 46 * rowIndex, 45, 45)
                                Controls.Add(theLabel)
                                gridLabelArray(rowIndex, columnIndex) = theLabel

                            End With
                        Next
                    Next
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("Input must be an integer between 1 & 8", _
            "Data entry error", MessageBoxButtons.OK)

        End Try
        Me.Width = 35 * columnsInteger + 225
        Me.Height = 40 * rowsInteger + 225
    End Sub

    Private Sub toggleButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toggleButton.Click

        Dim rowIndex, columnIndex As Integer
        For rowIndex = 0 To rowsInteger
            For columnIndex = 0 To columnsInteger
                If toggleBoolean = True Then


                    If gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red Then
                        gridLabelArray(rowIndex, columnIndex).BackColor = Color.Blue
                    Else
                        gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red
                    End If

                ElseIf toggleBoolean = False Then
                    If gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red Then
                        gridLabelArray(rowIndex, columnIndex).BackColor = Color.Blue
                    Else
                        gridLabelArray(rowIndex, columnIndex).BackColor = Color.Red
                    End If

                End If
            Next
        Next
        toggleBoolean = True


        'If toggleBoolean = False Then
        '    ReDim gridLabelArray(rowsInteger, columnsInteger)
        '    'Dim rowIndex, columnIndex As Integer
        '    For rowIndex = 0 To rowsInteger
        '        For columnIndex = 0 To columnsInteger
        '            Dim theLabel As New Label
        '            With theLabel
        '                '.SetBounds(60 + 46 * columnIndex, 120 + 46 * rowIndex, 45, 45)
        '                If rowIndex Mod 2 = 1 Then
        '                    .BackColor = Color.Red
        '                Else
        '                    .BackColor = Color.Blue
        '                End If
        '                .SetBounds(60 + 46 * columnIndex, 100 + 46 * rowIndex, 45, 45)
        '                Controls.Add(theLabel)
        '                gridLabelArray(rowIndex, columnIndex) = theLabel

        '            End With
        '        Next
        '    Next
        'End If
    End Sub
End Class

User is offlineProfile CardPM
Go to the top of the page
+Quote Post


anand_the_great
post 7 May, 2008 - 01:58 AM
Post #2


New D.I.C Head

*
Joined: 15 Apr, 2008
Posts: 27

Hello.

Dude, i would suggest to concentrate on the row,column thing.
Remember the basic for grids is the columnindex is to 0.
Use a for loop to test for assigning valus in it first.

CODE

For xi = 0 To rs.RecordCount     'Loop in row (in this you will use the total number of 1X1 as the length)
    For xj = 0 To rs.Fields.Count  'Loop within each row the columns
        If a(an Integer) = even number use the %(mod), so if it even then display as red
        Else the odd column is blue
        End If
    Next xj
Next xi


This post has been edited by anand_the_great: 7 May, 2008 - 02:17 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

victorB
post 7 May, 2008 - 05:14 AM
Post #3


New D.I.C Head

*
Joined: 22 Mar, 2008
Posts: 11

QUOTE(anand_the_great @ 7 May, 2008 - 01:58 AM) *

Hello.

Dude, i would suggest to concentrate on the row,column thing.
Remember the basic for grids is the columnindex is to 0.
Use a for loop to test for assigning valus in it first.

CODE

For xi = 0 To rs.RecordCount     'Loop in row (in this you will use the total number of 1X1 as the length)
    For xj = 0 To rs.Fields.Count  'Loop within each row the columns
        If a(an Integer) = even number use the %(mod), so if it even then display as red
        Else the odd column is blue
        End If
    Next xj
Next xi


[reply]
Hello anand_the_great,
I'm not certain what you are saying here. I have alredy used this construction. As a matter of fact, i can toggle between red and blue for rows or i can toggle between red and blue for columns; however, i can not toggle between rows and columns and then columns to rows. which is the final part of the code that i am having trouble with. In other words, after i paint the grid on the form i am able to toggle between colors for either rows or columns so the next step is, if i toggled colors between rows then the next time i hit the toggle button i want the colors to toggle between columns.
[/reply]
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

victorB
post 9 May, 2008 - 07:04 AM
Post #4


New D.I.C Head

*
Joined: 22 Mar, 2008
Posts: 11

QUOTE(victorB @ 7 May, 2008 - 05:14 AM) *

QUOTE(anand_the_great @ 7 May, 2008 - 01:58 AM) *

Hello.

Dude, i would suggest to concentrate on the row,column thing.
Remember the basic for grids is the columnindex is to 0.
Use a for loop to test for assigning valus in it first.

CODE

For xi = 0 To rs.RecordCount     'Loop in row (in this you will use the total number of 1X1 as the length)
    For xj = 0 To rs.Fields.Count  'Loop within each row the columns
        If a(an Integer) = even number use the %(mod), so if it even then display as red
        Else the odd column is blue
        End If
    Next xj
Next xi


[reply]
Hello anand_the_great,
I'm not certain what you are saying here. I have alredy used this construction. As a matter of fact, i can toggle between red and blue for rows or i can toggle between red and blue for columns; however, i can not toggle between rows and columns and then columns to rows. which is the final part of the code that i am having trouble with. In other words, after i paint the grid on the form i am able to toggle between colors for either rows or columns so the next step is, if i toggled colors between rows then the next time i hit the toggle button i want the colors to toggle between columns.
[/reply]
Well, i am still uncertain how i am to apply the given help; nonetheless, i have written a solution. I did so in the toggle click_method. Thanks for the help.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

PsychoCoder
post 9 May, 2008 - 07:07 AM
Post #5


ToCode || !ToCode

Group Icon
Joined: 26 Jul, 2007
Posts: 5,860

Moved to VB.NET
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 06:45PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month