Simple Sudoku Game vb 2008

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 12555 Views - Last Post: 08 June 2011 - 06:17 AM Rate Topic: -----

#1 javmiller  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-May 11

Simple Sudoku Game vb 2008

Posted 31 May 2011 - 06:51 AM

Hi everyone I am new here. I am trying to make a sudoku game and I have the basic concepts, and now I'm trying to get the test button to work. I am not sure where to go next, I do not know how to get it to work without having to have to put in all of the combinations for sudoku. Is there an easier way to do this?
Here is my code:
Public Class Form1
    Dim SQ1(9, 9) As Integer
    Dim Buttonvalue As Integer
    Dim butnum(9, 9) As Integer
    Dim temp As Integer
    Dim T As Integer

    Private Sub testbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles testbut.Click

        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "9" Then
            MsgBox("You Won!")
        Else
            MsgBox("Something's not right.")
        End If
    End Sub

    Private Sub resetbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetbut.Click
        T = 0
        Label1.Text = "Time: " & T
        butnum(1, 1) = 0
        Button1.Text = ""
        butnum(1, 2) = 0
        Button2.Text = ""
        butnum(1, 3) = 0
        Button3.Text = ""
        butnum(2, 1) = 0
        Button4.Text = ""
        butnum(2, 2) = 0
        Button5.Text = ""
        butnum(2, 3) = 0
        Button6.Text = ""
        butnum(3, 1) = 0
        Button7.Text = ""
        butnum(3, 2) = 0
        Button8.Text = ""
        butnum(3, 3) = 0
        Button9.Text = ""
        butnum(4, 1) = 0
        Button10.Text = ""
        butnum(4, 2) = 0
        Button11.Text = ""
        butnum(4, 3) = 0
        Button12.Text = ""
        butnum(5, 1) = 0
        Button13.Text = ""
        butnum(5, 2) = 0
        Button14.Text = ""
        butnum(5, 3) = 0
        Button15.Text = ""
        butnum(6, 1) = 0
        Button16.Text = ""
        butnum(6, 2) = 0
        Button17.Text = ""
        butnum(6, 3) = 0
        Button18.Text = ""
        butnum(7, 1) = 0
        Button19.Text = ""
        butnum(7, 2) = 0
        Button20.Text = ""
        butnum(7, 3) = 0
        Button21.Text = ""
        butnum(8, 1) = 0
        Button22.Text = ""
        butnum(8, 2) = 0
        Button23.Text = ""
        butnum(8, 3) = 0
        Button24.Text = ""
        butnum(9, 1) = 0
        Button25.Text = ""
        butnum(9, 2) = 0
        Button26.Text = ""
        butnum(9, 3) = 0
        Button27.Text = ""
        butnum(1, 4) = 0
        Button28.Text = ""
        butnum(1, 5) = 0
        Button29.Text = ""
        butnum(1, 6) = 0
        Button30.Text = ""
        butnum(2, 4) = 0
        Button31.Text = ""
        butnum(2, 5) = 0
        Button32.Text = ""
        butnum(2, 6) = 0
        Button33.Text = ""
        butnum(3, 4) = 0
        Button34.Text = ""
        butnum(3, 5) = 0
        Button35.Text = ""
        butnum(3, 6) = 0
        Button36.Text = ""
        butnum(4, 4) = 0
        Button37.Text = ""
        butnum(4, 5) = 0
        Button38.Text = ""
        butnum(4, 6) = 0
        Button39.Text = ""
        butnum(5, 4) = 0
        Button40.Text = ""
        butnum(5, 5) = 0
        Button41.Text = ""
        butnum(5, 6) = 0
        Button42.Text = ""
        butnum(6, 4) = 0
        Button43.Text = ""
        butnum(6, 5) = 0
        Button44.Text = ""
        butnum(6, 6) = 0
        Button45.Text = ""
        butnum(7, 4) = 0
        Button46.Text = ""
        butnum(7, 5) = 0
        Button47.Text = ""
        butnum(7, 6) = 0
        Button48.Text = ""
        butnum(8, 4) = 0
        Button49.Text = ""
        butnum(8, 5) = 0
        Button50.Text = ""
        butnum(8, 6) = 0
        Button51.Text = ""
        butnum(9, 4) = 0
        Button52.Text = ""
        butnum(9, 5) = 0
        Button53.Text = ""
        butnum(9, 6) = 0
        Button54.Text = ""
        butnum(1, 7) = 0
        Button55.Text = ""
        butnum(1, 8) = 0
        Button56.Text = ""
        butnum(1, 9) = 0
        Button57.Text = ""
        butnum(2, 7) = 0
        Button58.Text = ""
        butnum(2, 8) = 0
        Button59.Text = ""
        butnum(2, 9) = 0
        Button60.Text = ""
        butnum(3, 7) = 0
        Button61.Text = ""
        butnum(3, 8) = 0
        Button62.Text = ""
        butnum(3, 9) = 0
        Button63.Text = ""
        butnum(4, 7) = 0
        Button64.Text = ""
        butnum(4, 8) = 0
        Button65.Text = ""
        butnum(4, 9) = 0
        Button66.Text = ""
        butnum(5, 7) = 0
        Button67.Text = ""
        butnum(5, 8) = 0
        Button68.Text = ""
        butnum(5, 9) = 0
        Button69.Text = ""
        butnum(6, 7) = 0
        Button70.Text = ""
        butnum(6, 8) = 0
        Button71.Text = ""
        butnum(6, 9) = 0
        Button72.Text = ""
        butnum(7, 7) = 0
        Button73.Text = ""
        butnum(7, 8) = 0
        Button74.Text = ""
        butnum(7, 9) = 0
        Button75.Text = ""
        butnum(8, 7) = 0
        Button76.Text = ""
        butnum(8, 8) = 0
        Button77.Text = ""
        butnum(8, 9) = 0
        Button78.Text = ""
        butnum(9, 7) = 0
        Button79.Text = ""
        butnum(9, 8) = 0
        Button80.Text = ""
        butnum(9, 9) = 0
    End Sub


    'Below is the Time Label: It shows the time
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        T = T + 1
        Label1.Text = "Time: " & T
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Label1.Text = "Time: 0"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        temp = butnum(1, 1) + 1
        butnum(1, 1) = temp
        Button1.Text = butnum(1, 1)
        If butnum(1, 1) > 9 Then butnum(1, 1) = 0
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        temp = butnum(1, 2) + 1
        butnum(1, 2) = temp
        Button2.Text = butnum(1, 2)
        If butnum(1, 2) > 9 Then butnum(1, 2) = 0
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        temp = butnum(1, 3) + 1
        butnum(1, 3) = temp
        Button3.Text = butnum(1, 3)
        If butnum(1, 3) > 9 Then butnum(1, 3) = 0
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        temp = butnum(2, 1) + 1
        butnum(2, 1) = temp
        Button4.Text = butnum(2, 1)
        If butnum(2, 1) > 9 Then butnum(2, 1) = 0
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        temp = butnum(2, 2) + 1
        butnum(2, 2) = temp
        Button5.Text = butnum(2, 2)
        If butnum(2, 2) > 9 Then butnum(2, 2) = 0
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        temp = butnum(2, 3) + 1
        butnum(2, 3) = temp
        Button6.Text = butnum(2, 3)
        If butnum(2, 3) > 9 Then butnum(2, 3) = 0
    End Sub
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        temp = butnum(3, 1) + 1
        butnum(3, 1) = temp
        Button7.Text = butnum(3, 1)
        If butnum(3, 1) > 9 Then butnum(3, 1) = 0
    End Sub
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        temp = butnum(3, 2) + 1
        butnum(3, 2) = temp
        Button8.Text = butnum(3, 2)
        If butnum(3, 2) > 9 Then butnum(3, 2) = 0
    End Sub
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        temp = butnum(3, 3) + 1
        butnum(3, 3) = temp
        Button9.Text = butnum(3, 3)
        If butnum(3, 3) > 9 Then butnum(3, 3) = 0
    End Sub
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        temp = butnum(4, 1) + 1
        butnum(4, 1) = temp
        Button10.Text = butnum(4, 1)
        If butnum(4, 1) > 9 Then butnum(4, 1) = 0
    End Sub
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        temp = butnum(4, 2) + 1
        butnum(4, 2) = temp
        Button11.Text = butnum(4, 2)
        If butnum(4, 2) > 9 Then butnum(4, 2) = 0
    End Sub
    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        temp = butnum(4, 3) + 1
        butnum(4, 3) = temp
        Button12.Text = butnum(4, 3)
        If butnum(4, 3) > 9 Then butnum(4, 3) = 0
    End Sub
    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        temp = butnum(5, 1) + 1
        butnum(5, 1) = temp
        Button13.Text = butnum(5, 1)
        If butnum(5, 1) > 9 Then butnum(5, 1) = 0
    End Sub
    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        temp = butnum(5, 2) + 1
        butnum(5, 2) = temp
        Button14.Text = butnum(5, 2)
        If butnum(5, 2) > 9 Then butnum(5, 2) = 0
    End Sub
    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        temp = butnum(5, 3) + 1
        butnum(5, 3) = temp
        Button15.Text = butnum(5, 3)
        If butnum(5, 3) > 9 Then butnum(5, 3) = 0
    End Sub
    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        temp = butnum(6, 1) + 1
        butnum(6, 1) = temp
        Button16.Text = butnum(3, 1)
        If butnum(6, 1) > 9 Then butnum(6, 1) = 0
    End Sub
    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        temp = butnum(6, 2) + 1
        butnum(6, 2) = temp
        Button17.Text = butnum(6, 2)
        If butnum(6, 2) > 9 Then butnum(6, 2) = 0
    End Sub
    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        temp = butnum(6, 3) + 1
        butnum(6, 3) = temp
        Button18.Text = butnum(6, 3)
        If butnum(6, 3) > 9 Then butnum(6, 3) = 0
    End Sub
    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        temp = butnum(7, 1) + 1
        butnum(7, 1) = temp
        Button19.Text = butnum(7, 1)
        If butnum(7, 1) > 9 Then butnum(7, 1) = 0
    End Sub
    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        temp = butnum(7, 2) + 1
        butnum(7, 2) = temp
        Button20.Text = butnum(7, 2)
        If butnum(7, 2) > 9 Then butnum(7, 2) = 0
    End Sub
    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        temp = butnum(7, 3) + 1
        butnum(7, 3) = temp
        Button21.Text = butnum(7, 3)
        If butnum(7, 3) > 9 Then butnum(7, 3) = 0
    End Sub
    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        temp = butnum(8, 1) + 1
        butnum(8, 1) = temp
        Button22.Text = butnum(8, 1)
        If butnum(8, 1) > 9 Then butnum(8, 1) = 0
    End Sub
    Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
        temp = butnum(8, 2) + 1
        butnum(8, 2) = temp
        Button23.Text = butnum(8, 2)
        If butnum(8, 2) > 9 Then butnum(8, 2) = 0
    End Sub
    Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
        temp = butnum(8, 3) + 1
        butnum(8, 3) = temp
        Button24.Text = butnum(8, 3)
        If butnum(8, 3) > 9 Then butnum(8, 3) = 0
    End Sub
    Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
        temp = butnum(9, 1) + 1
        butnum(9, 1) = temp
        Button25.Text = butnum(9, 1)
        If butnum(9, 1) > 9 Then butnum(9, 1) = 0
    End Sub
    Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
        temp = butnum(9, 2) + 1
        butnum(9, 2) = temp
        Button26.Text = butnum(9, 2)
        If butnum(9, 2) > 9 Then butnum(9, 2) = 0
    End Sub
    Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click
        temp = butnum(9, 3) + 1
        butnum(9, 3) = temp
        Button27.Text = butnum(9, 3)
        If butnum(9, 3) > 9 Then butnum(9, 3) = 0
    End Sub
    Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click
        temp = butnum(1, 4) + 1
        butnum(1, 4) = temp
        Button28.Text = butnum(1, 4)
        If butnum(1, 4) > 9 Then butnum(1, 4) = 0
    End Sub
    Private Sub Button29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button29.Click
        temp = butnum(1, 5) + 1
        butnum(1, 5) = temp
        Button29.Text = butnum(1, 5)
        If butnum(1, 5) > 9 Then butnum(1, 5) = 0
    End Sub
    Private Sub Button30_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button30.Click
        temp = butnum(1, 6) + 1
        butnum(1, 6) = temp
        Button30.Text = butnum(1, 6)
        If butnum(1, 6) > 9 Then butnum(1, 6) = 0
    End Sub
    Private Sub Button31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button31.Click
        temp = butnum(2, 4) + 1
        butnum(2, 4) = temp
        Button31.Text = butnum(3, 3)
        If butnum(2, 4) > 9 Then butnum(2, 4) = 0
    End Sub
    Private Sub Button32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button32.Click
        temp = butnum(2, 5) + 1
        butnum(2, 5) = temp
        Button32.Text = butnum(2, 5)
        If butnum(2, 5) > 9 Then butnum(2, 5) = 0
    End Sub
    Private Sub Button33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button33.Click
        temp = butnum(2, 6) + 1
        butnum(2, 6) = temp
        Button33.Text = butnum(2, 6)
        If butnum(2, 6) > 9 Then butnum(2, 6) = 0
    End Sub
    Private Sub Button34_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button34.Click
        temp = butnum(3, 4) + 1
        butnum(3, 4) = temp
        Button34.Text = butnum(3, 4)
        If butnum(3, 4) > 9 Then butnum(3, 4) = 0
    End Sub
    Private Sub Button35_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button35.Click
        temp = butnum(3, 5) + 1
        butnum(3, 5) = temp
        Button35.Text = butnum(3, 5)
        If butnum(3, 5) > 9 Then butnum(3, 5) = 0
    End Sub
    Private Sub Button36_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button36.Click
        temp = butnum(3, 6) + 1
        butnum(3, 6) = temp
        Button36.Text = butnum(3, 6)
        If butnum(3, 6) > 9 Then butnum(3, 6) = 0
    End Sub
    Private Sub Button37_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button37.Click
        temp = butnum(4, 4) + 1
        butnum(4, 4) = temp
        Button37.Text = butnum(4, 4)
        If butnum(4, 4) > 9 Then butnum(4, 4) = 0
    End Sub
    Private Sub Button38_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button38.Click
        temp = butnum(4, 5) + 1
        butnum(4, 5) = temp
        Button38.Text = butnum(4, 5)
        If butnum(4, 5) > 9 Then butnum(4, 5) = 0
    End Sub
    Private Sub Button39_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button39.Click
        temp = butnum(4, 6) + 1
        butnum(4, 6) = temp
        Button39.Text = butnum(4, 6)
        If butnum(4, 6) > 9 Then butnum(4, 6) = 0
    End Sub
    Private Sub Button40_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button40.Click
        temp = butnum(5, 4) + 1
        butnum(5, 4) = temp
        Button40.Text = butnum(5, 4)
        If butnum(5, 4) > 9 Then butnum(5, 4) = 0
    End Sub
    Private Sub Button41_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button41.Click
        temp = butnum(5, 5) + 1
        butnum(5, 5) = temp
        Button41.Text = butnum(5, 5)
        If butnum(5, 5) > 9 Then butnum(5, 5) = 0
    End Sub
    Private Sub Button42_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button42.Click
        temp = butnum(5, 6) + 1
        butnum(5, 6) = temp
        Button42.Text = butnum(5, 6)
        If butnum(5, 6) > 9 Then butnum(5, 6) = 0
    End Sub
    Private Sub Button43_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button43.Click
        temp = butnum(6, 4) + 1
        butnum(6, 4) = temp
        Button43.Text = butnum(6, 4)
        If butnum(6, 4) > 9 Then butnum(6, 4) = 0
    End Sub
    Private Sub Button44_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button44.Click
        temp = butnum(6, 5) + 1
        butnum(6, 5) = temp
        Button44.Text = butnum(6, 5)
        If butnum(6, 5) > 9 Then butnum(6, 5) = 0
    End Sub
    Private Sub Button45_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button45.Click
        temp = butnum(6, 6) + 1
        butnum(6, 6) = temp
        Button45.Text = butnum(6, 6)
        If butnum(6, 6) > 9 Then butnum(6, 6) = 0
    End Sub
    Private Sub Button46_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button46.Click
        temp = butnum(7, 4) + 1
        butnum(7, 4) = temp
        Button46.Text = butnum(7, 4)
        If butnum(7, 4) > 9 Then butnum(7, 4) = 0
    End Sub
    Private Sub Button47_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button47.Click
        temp = butnum(7, 5) + 1
        butnum(7, 5) = temp
        Button47.Text = butnum(7, 5)
        If butnum(7, 5) > 9 Then butnum(7, 5) = 0
    End Sub
    Private Sub Button48_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button48.Click
        temp = butnum(7, 6) + 1
        butnum(7, 6) = temp
        Button48.Text = butnum(7, 6)
        If butnum(7, 6) > 9 Then butnum(7, 6) = 0
    End Sub
    Private Sub Button49_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button49.Click
        temp = butnum(8, 4) + 1
        butnum(8, 4) = temp
        Button49.Text = butnum(8, 4)
        If butnum(8, 4) > 9 Then butnum(8, 4) = 0
    End Sub
    Private Sub Button50_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button50.Click
        temp = butnum(8, 5) + 1
        butnum(8, 5) = temp
        Button50.Text = butnum(8, 5)
        If butnum(8, 5) > 9 Then butnum(8, 5) = 0
    End Sub
    Private Sub Button51_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button51.Click
        temp = butnum(8, 6) + 1
        butnum(8, 6) = temp
        Button51.Text = butnum(8, 6)
        If butnum(8, 6) > 9 Then butnum(8, 6) = 0
    End Sub
    Private Sub Button52_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button52.Click
        temp = butnum(9, 4) + 1
        butnum(9, 4) = temp
        Button52.Text = butnum(9, 4)
        If butnum(9, 4) > 9 Then butnum(9, 4) = 0
    End Sub
    Private Sub Button53_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button53.Click
        temp = butnum(9, 5) + 1
        butnum(9, 5) = temp
        Button53.Text = butnum(9, 5)
        If butnum(9, 5) > 9 Then butnum(9, 5) = 0
    End Sub
    Private Sub Button54_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button54.Click
        temp = butnum(9, 6) + 1
        butnum(9, 6) = temp
        Button54.Text = butnum(9, 6)
        If butnum(9, 6) > 9 Then butnum(9, 6) = 0
    End Sub
    Private Sub Button55_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button55.Click
        temp = butnum(1, 7) + 1
        butnum(1, 7) = temp
        Button55.Text = butnum(1, 7)
        If butnum(1, 7) > 9 Then butnum(1, 7) = 0
    End Sub
    Private Sub Button56_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button56.Click
        temp = butnum(1, 8) + 1
        butnum(1, 8) = temp
        Button56.Text = butnum(1, 8)
        If butnum(1, 8) > 9 Then butnum(1, 8) = 0
    End Sub
    Private Sub Button57_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button57.Click
        temp = butnum(1, 9) + 1
        butnum(1, 9) = temp
        Button57.Text = butnum(1, 9)
        If butnum(1, 9) > 9 Then butnum(1, 9) = 0
    End Sub
    Private Sub Button58_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button58.Click
        temp = butnum(2, 7) + 1
        butnum(2, 7) = temp
        Button58.Text = butnum(2, 7)
        If butnum(2, 7) > 9 Then butnum(2, 7) = 0
    End Sub
    Private Sub Button59_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button59.Click
        temp = butnum(2, 8) + 1
        butnum(2, 8) = temp
        Button59.Text = butnum(2, 8)
        If butnum(2, 8) > 9 Then butnum(2, 8) = 0
    End Sub
    Private Sub Button60_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button60.Click
        temp = butnum(2, 9) + 1
        butnum(2, 9) = temp
        Button60.Text = butnum(2, 9)
        If butnum(2, 9) > 9 Then butnum(2, 9) = 0
    End Sub
    Private Sub Button61_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button61.Click
        temp = butnum(3, 7) + 1
        butnum(3, 7) = temp
        Button61.Text = butnum(3, 7)
        If butnum(3, 7) > 9 Then butnum(3, 7) = 0
    End Sub
    Private Sub Button62_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button62.Click
        temp = butnum(3, 8) + 1
        butnum(3, 8) = temp
        Button62.Text = butnum(3, 8)
        If butnum(3, 8) > 9 Then butnum(3, 8) = 0
    End Sub
    Private Sub Button63_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button63.Click
        temp = butnum(3, 9) + 1
        butnum(3, 9) = temp
        Button63.Text = butnum(3, 9)
        If butnum(3, 9) > 9 Then butnum(3, 9) = 0
    End Sub
    Private Sub Button64_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button64.Click
        temp = butnum(4, 7) + 1
        butnum(4, 7) = temp
        Button64.Text = butnum(4, 7)
        If butnum(4, 7) > 9 Then butnum(4, 7) = 0
    End Sub
    Private Sub Button65_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button65.Click
        temp = butnum(4, 8) + 1
        butnum(4, 8) = temp
        Button65.Text = butnum(4, 8)
        If butnum(4, 8) > 9 Then butnum(4, 8) = 0
    End Sub
    Private Sub Button66_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button66.Click
        temp = butnum(4, 9) + 1
        butnum(4, 9) = temp
        Button66.Text = butnum(4, 9)
        If butnum(4, 9) > 9 Then butnum(4, 9) = 0
    End Sub
    Private Sub Button67_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button67.Click
        temp = butnum(5, 7) + 1
        butnum(5, 7) = temp
        Button67.Text = butnum(5, 7)
        If butnum(5, 7) > 9 Then butnum(5, 7) = 0
    End Sub
    Private Sub Button68_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button68.Click
        temp = butnum(5, 8) + 1
        butnum(5, 8) = temp
        Button68.Text = butnum(5, 8)
        If butnum(5, 8) > 9 Then butnum(5, 8) = 0
    End Sub
    Private Sub Button69_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button69.Click
        temp = butnum(5, 9) + 1
        butnum(5, 9) = temp
        Button69.Text = butnum(5, 9)
        If butnum(5, 9) > 9 Then butnum(5, 9) = 0
    End Sub
    Private Sub Button70_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button70.Click
        temp = butnum(6, 7) + 1
        butnum(6, 7) = temp
        Button70.Text = butnum(6, 7)
        If butnum(6, 7) > 9 Then butnum(6, 7) = 0
    End Sub
    Private Sub Button71_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button71.Click
        temp = butnum(6, 8) + 1
        butnum(6, 8) = temp
        Button71.Text = butnum(6, 8)
        If butnum(6, 8) > 9 Then butnum(6, 8) = 0
    End Sub
    Private Sub Button72_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button72.Click
        temp = butnum(6, 9) + 1
        butnum(6, 9) = temp
        Button72.Text = butnum(6, 9)
        If butnum(6, 9) > 9 Then butnum(6, 9) = 0
    End Sub
    Private Sub Button73_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button73.Click
        temp = butnum(7, 7) + 1
        butnum(7, 7) = temp
        Button73.Text = butnum(7, 7)
        If butnum(7, 7) > 9 Then butnum(7, 7) = 0
    End Sub
    Private Sub Button74_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button74.Click
        temp = butnum(7, 8) + 1
        butnum(7, 8) = temp
        Button74.Text = butnum(7, 8)
        If butnum(7, 8) > 9 Then butnum(7, 8) = 0
    End Sub
    Private Sub Button75_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button75.Click
        temp = butnum(7, 9) + 1
        butnum(7, 9) = temp
        Button75.Text = butnum(7, 9)
        If butnum(7, 9) > 9 Then butnum(7, 9) = 0
    End Sub
    Private Sub Button76_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button76.Click
        temp = butnum(8, 7) + 1
        butnum(8, 7) = temp
        Button76.Text = butnum(8, 7)
        If butnum(8, 7) > 9 Then butnum(8, 7) = 0
    End Sub
    Private Sub Button77_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button77.Click
        temp = butnum(8, 8) + 1
        butnum(8, 8) = temp
        Button77.Text = butnum(8, 8)
        If butnum(8, 8) > 9 Then butnum(8, 8) = 0
    End Sub
    Private Sub Button78_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button78.Click
        temp = butnum(8, 9) + 1
        butnum(8, 9) = temp
        Button78.Text = butnum(8, 9)
        If butnum(8, 9) > 9 Then butnum(8, 9) = 0
    End Sub
    Private Sub Button79_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button79.Click
        temp = butnum(9, 7) + 1
        butnum(9, 7) = temp
        Button79.Text = butnum(9, 7)
        If butnum(9, 7) > 9 Then butnum(9, 7) = 0
    End Sub
    Private Sub Button80_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button80.Click
        temp = butnum(9, 8) + 1
        butnum(9, 8) = temp
        Button80.Text = butnum(9, 8)
        If butnum(9, 8) > 9 Then butnum(9, 8) = 0
    End Sub
    Private Sub Button81_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button81.Click
        temp = butnum(9, 9) + 1
        butnum(9, 9) = temp
        Button81.Text = butnum(9, 9)
        If butnum(9, 9) > 9 Then butnum(9, 9) = 0
    End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Simple Sudoku Game vb 2008

#2 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Simple Sudoku Game vb 2008

Posted 31 May 2011 - 07:49 AM

Okay, one thing I would suggest is to generate the controls you use dynamically...cause to be honest, scrolling through 81 of those statements made me feel sorry for your hands.

Now, I did a sudoku game for my VB II final, so I'm more or less gonna be just pulling things from that.

Firstly, the method to generate the buttons dynamically (I used labels for my final, but buttons work fine) First you need to declare some constant variables to make the buttons with:

    Const cellWidth As Integer = 32
    Const cellHeight As Integer = 32

    Const offsetX As Integer = -20
    Const offsetY As Integer = 32


That's what I used, and it resulted in "buttons" that looked like this, change to your own taste:
Posted Image

Then I did this to draw the labels dynamically rather than 81 times:

 Public Sub DrawBoard()
        'set defaults
        ToolStripButton1.Checked = True
        selectedNumber = 1

        'stores the cell
        Dim location As New Point
        'nested loops to draw the 81 labels (9 * 9) because I am lazy
        For row As Integer = 1 To 9
            For col As Integer = 1 To 9
                location.X = col * (cellWidth + 1) + offsetX
                location.Y = row * (cellHeight + 1) + offsetY

                'create labels and set them to grind value between 1,1 (11) and 9,9(99)
                Dim lbl As New Label

                With lbl
                    .Name = col.ToString() & row.ToString()
                    .BorderStyle = BorderStyle.Fixed3D
                    .Location = location
                    .Width = cellWidth
                    .Height = cellHeight
                    .TextAlign = ContentAlignment.MiddleCenter
                    .BackColor = program_BackColor
                    .Font = New Font(.Font, .Font.Style Or FontStyle.Bold)
                    '.tag tells if the "cell" is erasable or not. 1 = erasable, 0 = not
                    .Tag = 1
                    AddHandler lbl.Click, AddressOf clickCell
                End With
                Me.Controls.Add(lbl)
            Next
        Next
    End Sub



Now, ignore the first two lines, as they're involved with something in the GUI. I use two loops to iterate between all 81 entries in the (9,9) array (I ignore the 0 rows and cols to make the calculations easier) I create a new point so I can get a pair of X, Y coords, then increment the location of the X and Y corrds to place the buttons(labels) in different places every iteration of the loop. I then create a label object and then set a bunch of it's properties, setting the name of the label to the concatenation of the outer loop counter and the inner loop counter, making labels with the names "11" to "99" in order, now focus on one line, as it's VERY important, this one:

AddHandler lbl.Click, AddressOf clickCell

This line adds a handler to the newly created labels to the sub called clickCell, which means that that ONE sub-routine handles the .Click event for EVERY one of the labels. If you adapt that code to use buttons instead of labels, you'll reduce the code length by a large amount. What you did up there in ~700 lines of code I did in my final project in about 55 lines of code.

Hope that helps.
Was This Post Helpful? 3
  • +
  • -

#3 javmiller  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-May 11

Re: Simple Sudoku Game vb 2008

Posted 01 June 2011 - 06:26 AM

Thanks Tarkenfire for trying to help. I'm still trying to understand your code. Some of it is not declared and I'm not sure what the case is, weather they are other privates subs in the code or they are dim "..." as something. I have three of them: selectedNumber, program_BackColor, clickCell.
And I'm not sure, but this code that you gave me, is it supposed to work along with my code? Thanks in advanced.
Was This Post Helpful? 0
  • +
  • -

#4 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Simple Sudoku Game vb 2008

Posted 01 June 2011 - 01:08 PM

Okay, the gist of it is this:

Dim location As New Point

I use a point for the sake of being able to store two integers (and X and a Y) value at the same time. This point will determine where the new label that is being made is placed on the form.

For the next few lines:
For row As Integer = 1 To 9
           For col As Integer = 1 To 9
               location.X = col * (cellWidth + 1) + offsetX
               location.Y = row * (cellHeight + 1) + offsetY


This starts the two loops that represent the 9 rows and cols of the sudoku board.

The two next lines set the X and Y coordinates for the new label to locations based upon the constants you declare. I used 32 for the sizes and -20 and 32 for the offsets, changing them will make the spacing and size of the labels look different, if you so desire.

Next:
Dim lbl As New Label

I create a label with code. You can create controls outside of the designer.

After that, I use the With...End With construct. The way that works is by taking whatever is next to the With, it makes it so that all lines before the End With are executed on the word next to the With. So, in this instance, if I didn't use the with, I would have to type out lbl.Name, lbl.Location, etc.

With lbl
                   .Name = col.ToString() & row.ToString()
                   .BorderStyle = BorderStyle.Fixed3D
                   .Location = location
                   .Width = cellWidth
                   .Height = cellHeight
                   .TextAlign = ContentAlignment.MiddleCenter
                   .BackColor = program_BackColor
                   .Font = New Font(.Font, .Font.Style Or FontStyle.Bold)
                   '.tag tells if the "cell" is erasable or not. 1 = erasable, 0 = not
                   .Tag = 1



So these are just properties of the newly made label, most are astetic, the .Name will make the control have names like 11 for 1,1 and 88 for 8,8 on the grid. Location is set to the point made before, height and width are set to the height and width, text aliment makes the text appear in the center of the control backcolor and font are just aesthetic things, and I used the tag property for some of the logic of the program.

Here's the important line:
AddHandler lbl.Click, AddressOf clickCell

This adds a handler to the event of someone clicking on the label, and when someone clicks it, the clickCell subroutine further down in the program handles it. Here's the important part of that sub:

Private Sub clickCell(ByVal sender As System.Object, ByVal e As System.EventArgs)


Notice how it has no "Handles control.click" after it like most other subs:?
Private Sub MainForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint


That's because with that AddHandler line, we had the "Handles...", if we didn't to that, you'd have to add "Handles 11.click, 12.click 13.click..." and so on, so I did it in the code.

Finally this line:
Me.Controls.Add(lbl)

Adds the new control to the form.

Hopefully that helps you understand.

I wouldn't just plop my code into your project, not that I care, but it's probably not gonna mesh well with your code, I was just trying to get the concept of generating controls without using the form editor.
Was This Post Helpful? 2
  • +
  • -

#5 javmiller  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-May 11

Re: Simple Sudoku Game vb 2008

Posted 02 June 2011 - 06:38 AM

I still am having a little trouble understanding this. Do i have a datagridview, and does that have the labels in it?
Was This Post Helpful? 0
  • +
  • -

#6 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Simple Sudoku Game vb 2008

Posted 02 June 2011 - 06:49 AM

The labels are just on the form, you add them to the form via code in this method rather than dragging and dropping them on the form editor.
Was This Post Helpful? 0
  • +
  • -

#7 javmiller  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-May 11

Re: Simple Sudoku Game vb 2008

Posted 03 June 2011 - 06:34 AM

How about selectednumber = 1
its not declared in the code. Is this supposed to be a dim value or something?
Was This Post Helpful? 0
  • +
  • -

#8 nunzio01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-June 11

Re: Simple Sudoku Game vb 2008

Posted 03 June 2011 - 06:47 AM

how do you get the 1-9 to regester in your labels
Was This Post Helpful? 0
  • +
  • -

#9 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Simple Sudoku Game vb 2008

Posted 03 June 2011 - 07:06 AM

View Postjavmiller, on 03 June 2011 - 06:34 AM, said:

How about selectednumber = 1
its not declared in the code. Is this supposed to be a dim value or something?


That's because that's in a different sub, if you care to see the code(as a note, ont he top of my forms, I have a toolbar with 10 buttons (1-9 and clear(0)):

    'selected number in toolstrip
    Private selectedNumber As Integer = 0


selectedNumber is declared in the place for the class variables.

And in this sub is where the selectedButton gets it value:
 Private Sub ToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click, ToolStripButton2.Click, ToolStripButton3.Click, ToolStripButton4.Click, ToolStripButton5.Click, ToolStripButton6.Click, ToolStripButton7.Click, ToolStripButton8.Click, ToolStripButton9.Click, ToolStripButton10.Click

        'gets the object of the selected button.
        Dim selectedButton As ToolStripButton = CType(sender, ToolStripButton)

        'unchecks all buttons.
        For i As Integer = 1 To 10
            CType(ToolStrip1.Items.Item(i), ToolStripButton).Checked = False
        Next

        selectedButton.Checked = True

        If selectedButton.Text = "Clear" Then
            selectedNumber = 0
        Else
            selectedNumber = Integer.Parse(selectedButton.Text)
        End If
    End Sub


I have multiple handlers for all 10 buttons, so this sub get's executed whenever any of those buttons are clicked. It first get's which control called the sub (the sender variable in the arguments contains this data), and uses CType...which is more or less a general purpose conversion phrase, you can convert something into ANYTHING you can declare with a Dim statement (ie Integer, Double, Label, TextBox). I use this twice, once to get the name of the clicked buttons, and again to cycle through all of the other buttons, unchecking them.

After that it's pretty self explanatory. I check the button the user clicked, then determine what number it is (or if it's clear) with an if statement.

This post has been edited by Tarkenfire: 03 June 2011 - 07:07 AM

Was This Post Helpful? 0
  • +
  • -

#10 Jeff H  Icon User is offline

  • D.I.C Regular

Reputation: 112
  • View blog
  • Posts: 308
  • Joined: 30-January 11

Re: Simple Sudoku Game vb 2008

Posted 03 June 2011 - 07:52 AM

Hey Tarkenfire,
Gave you couple points for patience's and lengthy explanations

no need for lengthy explanation or no more than a couple of sentences, but was curios if not a problem and would only take a second.

I guess I could google it and can think of a couple of ways but what logic did you use for assigning numbers to cells, and I do not mean showing them on the form.

This post has been edited by Jeff H: 03 June 2011 - 07:53 AM

Was This Post Helpful? 0
  • +
  • -

#11 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Simple Sudoku Game vb 2008

Posted 03 June 2011 - 09:48 AM

I named the labels with grid specific names, ie 11, 22, 34 to represent (1,1), (2,2), (3,4), and so forth on the grid, so when someone clicked on a cell, I would just use the name of the label to assign the number to a 2-dimensional array.

This post has been edited by Tarkenfire: 03 June 2011 - 09:49 AM

Was This Post Helpful? 0
  • +
  • -

#12 nunzio01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-June 11

Re: Simple Sudoku Game vb 2008

Posted 06 June 2011 - 06:44 AM

How do you name the labels with the specific grid names like 11 (1,1) 34 (3,4)?
Was This Post Helpful? 0
  • +
  • -

#13 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Simple Sudoku Game vb 2008

Posted 06 June 2011 - 09:22 AM

This line:
.Name = col.ToString() & row.ToString()


You set the .Name property of the newly created label to a concatenation of the counters in the two for loops that run through the 81 numbers.
Was This Post Helpful? 0
  • +
  • -

#14 nunzio01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-June 11

Re: Simple Sudoku Game vb 2008

Posted 07 June 2011 - 06:08 AM

my tool bar doesnt regester numbers to the board, so how do you get the toolstripbuttons to work?
Was This Post Helpful? 0
  • +
  • -

#15 javmiller  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-May 11

Re: Simple Sudoku Game vb 2008

Posted 07 June 2011 - 06:33 AM

hey nunuzio01, i think i solved your problem. Use this:
        Dim lbl As Label = CType(sender, Label)
        If selectedNumber = 1 Then
            With lbl
                .Text = 1
            End With
        End If
        If selectedNumber = 2 Then
            With lbl
                .Text = 2
            End With
        End If
        If selectedNumber = 3 Then
            With lbl
                .Text = 3
            End With
        End If
        If selectedNumber = 4 Then
            With lbl
                .Text = 4
            End With
        End If
        If selectedNumber = 5 Then
            With lbl
                .Text = 5
            End With
        End If
        If selectedNumber = 6 Then
            With lbl
                .Text = 6
            End With
        End If
        If selectedNumber = 7 Then
            With lbl
                .Text = 7
            End With
        End If
        If selectedNumber = 8 Then
            With lbl
                .Text = 8
            End With
        End If
        If selectedNumber = 9 Then
            With lbl
                .Text = 9
            End With
        End If
        If selectedNumber = 0 Then
            With lbl
                .Text = 0
            End With
        End If

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2