Concatenating to perform an action

MatthewABlack

Member
Joined
Oct 3, 2008
Messages
7
Programming Experience
1-3
I'm teaching myself vb.net again after being out of school for a few years. My problem is probably simple although I don't know the correct terminology so it makes it hard to search for a solution. I am making a simple game with picture boxes. I created the variable YellowDrop which is a string. It concatenates a few things to create "Yellow6x1" for example. This is a picture box. I now need the command equivalent to yellow6x1.visible. I cannot just do yellowdrop.visible because visible is not a part of string. Can someone point me in the correct direction? Thank you.





If cbColor.Text = "Yellow" Then
For RowLoop = 6 To txtRow.Text Step -1
YellowDrop = ("Yellow" & (RowLoop) & "x" & (txtColumn.Text))
'****Here is where I need a command that would act like YellowDrop.visible****
Next
End If
 
I think i'm getting closer by making yellowdrop a picturebox... but not quite there.


Dim RowLoop As Integer
Dim YellowDrop As PictureBox


If cbColor.Text = "Yellow" Then
For RowLoop = 6 To txtRow.Text Step -1
YellowDrop.Name = ("Yellow" & (RowLoop) & "x" & (txtColumn.Text))
YellowDrop.Visible = True
Next
End If
 
I'm guessing that you have existing pictureboxes. If so you can do it this way.

If cbColor.Text = "Yellow" Then
For RowLoop As Integer = 6 To txtRow.Text Step -1
For Each ctrl As Control In Me.Controls
If ctrl.Name = "Yellow" & RowLoop & "x" & txtColumn.Text Then
ctrl.Visible = True
End If
Next
Next
End If
 
This is a step in the right direction I think but I don't know how to work around these if statements as I don't understand this line:

For Each ctrl As Control In Me.Controls

Each ctrl.name is showing in debug as "panel1" so it's skipping over the if statement for the concatenation.
 
Me is the form and you can't just iterate through picrtureboxes only (unfortunately) but must use controls instead. If they are in a container control such as a panel then you can change that to:
For Each ctrl As Control In Me.panel1.Controls

If you have multiple panels then you get to learn about recursive procedures :)
 
The picture boxes are not in the panel, rather the text boxes that are pulling the location of the picture boxes are. They are two text boxes inside a panel with an "x" separating them. They designate the picturebox on a grid that needs to be visible.
 
You need to be more explicit about what you have. Windows form or web page? DataGridView or what kind of grid? Your pictureboxes must be in a container control of some type - form or child container control.

If you want to create the pictureboxes at runtime, that is very different and you have a LOT more to do.
 
My mess right now looks like this :

VB.NET:
Public Class Form1
    Friend Count As Integer = 0
    Friend falltimerstopped As Boolean = True
    Friend rowloop As Integer = 6





    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If cbColor.Text = "Yellow" Then
            Count = 0
            fallTimer.Start()
            falltimerstopped = False
        End If

    End Sub
    Private Sub fallTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fallTimer.Tick

        Count += 1
        If Count = 1 Then
            For Each ctrl As Control In Me.Controls
                ctrl.Name = "Red" & rowloop & "x" & txtColumn.Text
                ctrl.Visible = False

                ctrl.Name = "Blue" & rowloop & "x" & txtColumn.Text
                ctrl.Visible = False

                ctrl.Name = "Yellow" & rowloop & "x" & txtColumn.Text
                ctrl.Visible = True

                Exit For
            Next
        End If
        If Count = 10 Then
            fallTimer.Stop()
            falltimerstopped = True

            For Each ctrl As Control In Me.Controls
                If ctrl.Name = "Red" & rowloop & "x" & txtColumn.Text Then
                    ctrl.Visible = False
                End If
                If ctrl.Name = "Blue" & rowloop & "x" & txtColumn.Text Then
                    ctrl.Visible = True
                End If
                If ctrl.Name = "Yellow" & rowloop & "x" & txtColumn.Text Then
                    ctrl.Visible = False
                End If
            Next

            rowloop -= 1

            If rowloop = 0 Then
                Exit Sub
            End If

        End If
    End Sub
End Class



I have a basic 6x7 grid with 3 picture boxes laying on top of each point in the grid. To the right of the grid I have a combo box with the choice of yellow or red. Under that I have a panel with two text boxes seperated with an x. This is so a user can input "yellow 1x1" for example. I'm trying to have the yellow spot on each part of the grid show fall from the top row of a specified column, show for 1 second, and then move down to the next spot until it hits the bottom. This is in replication of connect four.
 
My "grid" is a grid I made in paint as the background image and then 3 separate picture boxes on each point in the grid. They are each named according to their location (ie Red1x1 is in the bottom left with yellow1x1 and blue1x1 on top of it). The grid is blue that's why I have the blue points show up after the yellow piece is supposed to have fallen to the next point.
 
OK, PLEEEZE try to be more detailed when asking for help. IF it is the BackgroundImage of the form then the picture boxes are contained in the form and my first answer is correct.

That's all I can do for you.
 
I apologize. I've tried to be as detailed as possible, but being as novice as I am it is hard to distinguish importance. Thank you for dedicating some time to helping me today.
 
Back
Top