Welcome to Dream.In.Code
Become a VB Expert!

Join 149,911 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,188 people online right now. Registration is fast and FREE... Join Now!




randomize #1 to 4 in 4x4 grid

 
Reply to this topicStart new topic

randomize #1 to 4 in 4x4 grid

bmarthone
19 Dec, 2007 - 06:13 AM
Post #1

New D.I.C Head
*

Joined: 10 Dec, 2007
Posts: 5


My Contributions
Hey guys,

Im kind of lost because Im making a sudoku game. I want the # 1,2,3,4 to be the same values in rows,cols,and regions. But i could only do it for the rows. Help some help of how to get the cols and regions to how the same value of # 1 to 4 in the 4x4 grid. Below is the code I have.

thank

CODE

Dim ran(15) As Integer
        Dim i As Integer


        'array(ran) = Int(Int(Rnd(1) * 4 + 1))

        'i=1to4 is for loop.
button1:
        For i = 1 To 4
            Randomize()
            ran(0) = Int(Int(Rnd(1) * 4 + 1))
            If ran(0) = ran(1) Or ran(0) = ran(6) Or ran(0) = ran(4) Then
                GoTo button1
            End If
        Next i


button2:
        For i = 1 To 4
            Randomize()
            ran(1) = Int(Int(Rnd(1) * 4 + 1))
            If ran(1) = ran(0) Then

            End If
        Next i

button3:

        For i = 1 To 4
            Randomize()
            ran(2) = Int(Int(Rnd(1) * 4 + 1))
            If ran(2) = ran(0) Or ran(2) = ran(1) Then
                GoTo button3
            End If
        Next i


button4:
        For i = 1 To 4

            Randomize()
            ran(3) = Int(Int(Rnd(1) * 4 + 1))
            If ran(3) = ran(0) Or ran(3) = ran(1) Or ran(3) = ran(2) Then
                GoTo button4
            End If
        Next i


button5:
        For i = 1 To 4

            Randomize()
            ran(4) = Int(Int(Rnd(1) * 4 + 1))
            If ran(4) = ran(5) Or ran(4) = ran(6) Or ran(4) = ran(7) Then
                GoTo button5
            End If
        Next i

button6:
        For i = 1 To 4
            Randomize()
            ran(5) = Int(Int(Rnd(1) * 4 + 1))
            If ran(5) = ran(4) Or ran(5) = ran(6) Or ran(5) = ran(7) Then
                GoTo button6
            End If
        Next i

button7:

        For i = 1 To 4
            Randomize()
            ran(6) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(6) = ran(4) Or ran(6) = ran(5) Or ran(6) = ran(7) Then
                GoTo button7
            End If
        Next i


button8:
        For i = 1 To 4

            Randomize()
            ran(7) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(7) = ran(4) Or ran(7) = ran(5) Or ran(7) = ran(6) Then
                GoTo button8
            End If
        Next i


button9:

        For i = 1 To 4
            Randomize()
            ran(8) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(8) = ran(9) Or ran(8) = ran(10) Or ran(8) = ran(11)  Then
                GoTo button9
            End If
        Next i


button10:
        For i = 1 To 4

            Randomize()
            ran(9) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(9) = ran(8) Or ran(9) = ran(10) Or ran(9) = ran(11) Then
                GoTo button10
            End If
        Next i

button11:
        For i = 1 To 4

            Randomize()
            ran(10) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(10) = ran(8) Or ran(10) = ran(9) Or ran(9) = ran(11) Then
                GoTo button11
            End If
        Next i



button12:

        For i = 1 To 4
            Randomize()
            ran(11) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(11) = ran(8) Or ran(11) = ran(9) Or ran(11) = ran(10) Then

                GoTo button12
            End If
        Next i


button13:

        For i = 1 To 4
            Randomize()
            ran(12) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(12) = ran(13) Or ran(12) = ran(14) Or ran(12) = ran(15) Then


                GoTo button13
            End If
        Next i


button14:
        For i = 1 To 4

            Randomize()
            ran(13) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(13) = ran(12) Or ran(13) = ran(14) Or ran(13) = ran(15) Then

                GoTo button14
            End If
        Next i


button15:
        For i = 1 To 4

            Randomize()
            ran(14) = CInt(Int(Rnd(1) * 4 + 1))
            If ran(14) = ran(12) Or ran(14) = ran(13) Or ran(14) = ran(15) Then
                GoTo button15
            End If
        Next i


Button16:
        For i = 1 To 4

            Randomize()
            ran(15 ) = CInt(Int(Rnd(1) * 4 + 1))


            If ran(15) = ran(12) Or ran(15) = ran(13) Or ran(15) = ran(14) Then
                GoTo button16
            End If


        Next i

        Button1.Text = ran(0)
        Button2.Text = ran(1)
        Button3.Text = ran(2)
        Button4.Text = ran(3)
        Button5.Text = ran(4)
        Button6.Text = ran(5)
        Button7.Text = ran(6)
        Button8.Text = ran(7)
        Button9.Text = ran(8)
        Button10.Text = ran(9)
        Button11.Text = ran(10)
        Button12.Text = ran(11)
        Button13.Text = ran(12)
        Button14.Text = ran(13)
        Button15.Text = ran(14)
        Button16.Text = ran(15)
    End Sub
End Class


<ModEdit>Pease use code tags: => code.gif </ModEdit>

This post has been edited by PsychoCoder: 19 Dec, 2007 - 06:29 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 01:39PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month