|
-
May 23rd, 2013, 05:05 PM
#1
Thread Starter
Junior Member
Visual Studio 2012 Question/Help
Hi, so im making a Connect Four game, but im having trouble with the declaring the winner part. I have the pieces as back colors in picture boxes, but i cant figure out how to write the if statement saying if four picture boxes have the same back color.
for example i currently have:
Function Winner()
For rows = 0 To 5
For columns = 0 To 2
If picboxarray(rows, columns).BackColor = picboxarray(rows, columns + 1).BackColor And picboxarray(rows, columns + 1).BackColor = picboxarray(rows, columns + 2).BackColor And picboxarray(rows, columns + 2).BackColor And picboxarray(rows, columns + 3).BackColor And picboxarray(rows, columns).BackColor <> Nothing Then
Return True
End If
Next
Next
End Function
i get the error: Operator 'And' is not defined for types 'Boolean' and 'System.Drawing.Color'.
Any ideas on an alternative way? Thanks
-
May 24th, 2013, 07:58 AM
#2
Re: Visual Studio 2012 Question/Help
is this what you intended?:
Code:
If picboxarray(rows, columns).BackColor = picboxarray(rows, columns + 1).BackColor And picboxarray(rows, columns + 1).BackColor = picboxarray(rows, columns + 2).BackColor And picboxarray(rows, columns + 2).BackColor <> Nothing And picboxarray(rows, columns + 3).BackColor <> Nothing And picboxarray(rows, columns).BackColor <> Nothing Then
Return True
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 24th, 2013, 02:16 PM
#3
Re: Visual Studio 2012 Question/Help
This line is an interesting one:
And picboxarray(rows, columns).BackColor <> Nothing Then
If .Backcolor is actually nothing, then ALL of the previous conditions will throw exceptions, so this particular part of the If statement had better be true. The better way to write that would be to put that part first, and use AndAlso rather than And. If you use And, then all parts of the expression will be evaluated. By using AndAlso, if the first part is False, then the rest aren't evaluated because the total result is already known.
As for the actual problem, you started out ok on that If statement, but then there is this part in the middle:
And picboxarray(rows, columns + 2).BackColor And
Note that it starts and ends with And, with no = sign in the middle. That is not what you meant to write, as you did it correctly for the first two by comparing the BackColor to some other color.
My usual boring signature: Nothing
 
-
May 24th, 2013, 04:38 PM
#4
Re: Visual Studio 2012 Question/Help
Actually a picturebox BackColor can never be nothing. If you set it to Nothing it will revert to default (usually Color[Control]) so that part of the condition is useless as it stands.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 24th, 2013, 05:00 PM
#5
Re: Visual Studio 2012 Question/Help
It will revert to the default value for the Color structure, which should be Black, but now that I think about it, you can't compare anything to Nothing using <> anyways. You'd have to use Is Not. Of course, compilation never got that far because of the missing part of the statement from earlier.
My usual boring signature: Nothing
 
-
May 24th, 2013, 06:43 PM
#6
Re: Visual Studio 2012 Question/Help
using a picturebox straight from the toolbox with no modifications:
Code:
MsgBox(PictureBox1.BackColor <> Nothing) '=true
MsgBox(PictureBox1.BackColor <> SystemColors.Control) '=false
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 24th, 2013, 10:33 PM
#7
Thread Starter
Junior Member
Re: Visual Studio 2012 Question/Help
thanks everyone i found out my problem. feel free to check out my new thread once it gets accepted to be put up
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|