Archived

This topic is now archived and is closed to further replies.

Malachi

Delcaring a public function in VB

Recommended Posts

Im finally in my last stages of creating my Connect 4 game in viusal basic 6 but I have one more problem. I cant get my game to detect when the colors are in the right place for a connect 4. I did use this method: If b1.BackColor And b2.BackColor = QBColor(12) And b3.BackColor = QBColor(12) And b4.BackColor = QBColor(12) Then redl.visiable = True This kind of works but I have to paste this into every since button I have in the grid which makes the code unnecessarly long. I also get the box appearing earlier even if the connect 4 doesnt happen in a certain order. So is there a way I can declare a public function so I wont have to repeating the same code in every button?

Share this post


Link to post
Share on other sites
just a couple of things:

1)I hope that your code doesn''t look like what you''ve posted for one reason:

If b1.BackColor And b2.BackColor = QBColor(12) means if b1.BackColor exists and b2.BackColor = QBColor(12) then do something
what you mean is:
If b1.BackColor = QBColor(12) And b2.BackColor = QBColor(12) And...

2)it looks like you are making a bunch of controls and calling them b1, b2, b3, b4,... so on. In a case like this when you are using many of the same control, it''s usually better to use a control array. So your controls would be b(0), b(1), b(2), b(3)... I think this would help you because control arrays share code so you would only have to make one generic click event and you wouldn''t need to copy and paste

Share this post


Link to post
Share on other sites
Hello,
This is an easy one. How I do it is make a timer function and have that enabled and constantly checking. also declair a variable for each hole. then set each channel (witch im asuming is made up of picture boxes on top of each other) as an array. then have another variable like, dim clm1 as interger. then under each picturebox have two other pictureboxes with the visible setting as off. after that set two bolean varibles like, dim ply1 as boolean, and dim ply2 as boolean. then when the colomb is clicked then do an if ply1 = true then
picture1(clm1).visible = true. the ply1 sets what picture should be loaded, the white or the red one. then the clm1 is set as clm1 = clm1 + 1 at the beggining of the code for changeing the picture. then the timer looks to see what the value is for each of the intergers (clm1, clm2, clm3, etc. etc. etc.) and sees wether the numbers line up correctly. you also have to add some boolean variables for each spot saying wther it is red or white. The timer does a code like

if clm1 > 1 and c1s1w = true then
p1w = p1w + 1
end if

if clm1 > 1 and c1s1r = true then
p1r = p1r + 1
end if
''yadda yadda yadda
''if there is six colombs then
if p1w = 6 then
msgbox "white player wins"

end if
if p1r = 6 then
msgbox "redplayer wins
end if

do this for each row, this might be tedious but it only has to be written once since it checks ever so often instead of each time a piece is set. then for diagonals just do the same thing but only a few places can have diagonals on the board so do a different timer and it will take less code than the horosantals take. the end
-VBdestroyer

Share this post


Link to post
Share on other sites