none
I Need Some Help on Problem Solving My VB Assignment

    Question

  • I am new to programming and am having some issues.  Here is my situation.  I am working on a Small Group project but do to unknown reasons the majority of my fellow students have been unavailable to assist me.  I am on Active Duty in the Army and have the assignment due tomorrow but I have duty for 24hrs tomorrow so completing the project in a timely manner will be difficult for me.  I have been spending three frustrating days to make it work but with no luck even after interacting with other students outside my group.  Here is what needs to happen:

    I need to create a dynamic Sudoku game board using my existing Visual Basic code that uses random number generation when you click on the random button.

    I have created some of the code but have gotten stuck on this part.  I have to modify the existing 16 grid square to do the random number generation in accordance with the Soduku rules.

    I have been able to understand how to do the random number generation but it is only partially correct in accordance with the assignment instructions.  I ask that if someone could assist me in trying to troubleshoot this.  I know that somewhere I might have to add cases

    Here is my code but if anyone would like I can email them my code in a zip folder so it will be easier to review.  Any assistance would be greatly appreciated.

    Jeff Anderson

    Imports System

    Imports System.IO

    Imports System.Text

    Public Class Form1

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

    Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, _

    Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, Button11.Click, _

    Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click

    If sender.Text = "" Then

    sender.Text = "1"

    ElseIf sender.Text = "1" Then

    sender.Text = "2"

    ElseIf sender.Text = "2" Then

    sender.Text = "3"

    ElseIf sender.Text = "3" Then

    sender.Text = "4"

    ElseIf sender.Text = "4" Then

    sender.Text = ""

    End If

    End Sub

    Private Sub Button17_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click

    If Button1.Text <> "" Then

    If Button1.Text = Button2.Text Or Button1.Text = Button5.Text Or Button1.Text = Button6.Text Then

    MessageBox.Show("There is a Horizontal Error with Button1")

    Exit Sub

    End If

    If Button1.Text = Button3.Text Or Button1.Text = Button9.Text Or Button1.Text = Button11.Text Then

    MessageBox.Show("There is a Vertical Error with Button1")

    Exit Sub

    End If

    If Button1.Text = Button2.Text Or Button1.Text = Button3.Text Or Button1.Text = Button4.Text Then

    MessageBox.Show("There is a Regional Error with Button1")

    Exit Sub

    End If

    End If

    If Button2.Text <> "" Then

    If Button2.Text = Button1.Text Or Button2.Text = Button5.Text Or Button2.Text = Button6.Text Then

    MessageBox.Show("There is a Horizontal Error with Button2")

    Exit Sub

    End If

    If Button2.Text = Button4.Text Or Button2.Text = Button10.Text Or Button2.Text = Button12.Text Then

    MessageBox.Show("There is a Vertical Error with Button2")

    Exit Sub

    End If

    If Button2.Text = Button1.Text Or Button2.Text = Button3.Text Or Button2.Text = Button4.Text Then

    MessageBox.Show("There is a Regional Error with Button2")

    Exit Sub

    End If

    End If

    If Button3.Text <> "" Then

    If Button3.Text = Button4.Text Or Button3.Text = Button7.Text Or Button3.Text = Button8.Text Then

    MessageBox.Show("There is a Horizontal Error with Button3")

    Exit Sub

    End If

    If Button3.Text = Button1.Text Or Button3.Text = Button9.Text Or Button3.Text = Button11.Text Then

    MessageBox.Show("There is a Vertical Error with Button3")

    Exit Sub

    End If

    If Button3.Text = Button4.Text Or Button3.Text = Button1.Text Or Button3.Text = Button2.Text Then

    MessageBox.Show("There is a Regional Error with Button3")

    Exit Sub

    End If

    End If

    If Button4.Text <> "" Then

    If Button4.Text = Button3.Text Or Button4.Text = Button7.Text Or Button4.Text = Button8.Text Then

    MessageBox.Show("There is a Horizontal Error with Button4")

    Exit Sub

    End If

    If Button4.Text = Button2.Text Or Button4.Text = Button10.Text Or Button4.Text = Button12.Text Then

    MessageBox.Show("There is a Vertical Error with Button4")

    Exit Sub

    End If

    If Button4.Text = Button1.Text Or Button4.Text = Button2.Text Or Button4.Text = Button3.Text Then

    MessageBox.Show("There is a Regional Error with Button4")

    Exit Sub

    End If

    End If

    If Button5.Text <> "" Then

    If Button5.Text = Button1.Text Or Button5.Text = Button2.Text Or Button5.Text = Button6.Text Then

    MessageBox.Show("There is a Horizontal Error with Button5")

    Exit Sub

    End If

    If Button5.Text = Button7.Text Or Button5.Text = Button13.Text Or Button5.Text = Button15.Text Then

    MessageBox.Show("There is a Vertical Error with Button5")

    Exit Sub

    End If

    If Button5.Text = Button6.Text Or Button5.Text = Button7.Text Or Button5.Text = Button8.Text Then

    MessageBox.Show("There is a Regional Error with Button5")

    Exit Sub

    End If

    End If

    If Button6.Text <> "" Then

    If Button6.Text = Button5.Text Or Button6.Text = Button2.Text Or Button6.Text = Button1.Text Then

    MessageBox.Show("There is a Horizontal Error with Button6")

    Exit Sub

    End If

    If Button6.Text = Button8.Text Or Button6.Text = Button14.Text Or Button6.Text = Button16.Text Then

    MessageBox.Show("There is a Vertical Error with Button6")

    Exit Sub

    End If

    If Button6.Text = Button5.Text Or Button6.Text = Button7.Text Or Button6.Text = Button8.Text Then

    MessageBox.Show("There is a Regional Error with Button6")

    Exit Sub

    End If

    End If

    If Button7.Text <> "" Then

    If Button7.Text = Button3.Text Or Button7.Text = Button4.Text Or Button7.Text = Button8.Text Then

    MessageBox.Show("There is a Horizontal Error with Button7")

    Exit Sub

    End If

    If Button7.Text = Button5.Text Or Button7.Text = Button13.Text Or Button7.Text = Button15.Text Then

    MessageBox.Show("There is a Vertical Error with Button7")

    Exit Sub

    End If

    If Button7.Text = Button5.Text Or Button7.Text = Button6.Text Or Button7.Text = Button8.Text Then

    MessageBox.Show("There is a Regional Error with Button7")

    Exit Sub

    End If

    End If

    If Button8.Text <> "" Then

    If Button8.Text = Button3.Text Or Button8.Text = Button4.Text Or Button8.Text = Button7.Text Then

    MessageBox.Show("There is a Horizontal Error with Button8")

    Exit Sub

    End If

    If Button8.Text = Button6.Text Or Button8.Text = Button14.Text Or Button8.Text = Button16.Text Then

    MessageBox.Show("There is a Vertical Error with Button8")

    Exit Sub

    End If

    If Button8.Text = Button5.Text Or Button8.Text = Button6.Text Or Button8.Text = Button7.Text Then

    MessageBox.Show("There is a Regional Error with Button8")

    Exit Sub

    End If

    End If

    If Button9.Text <> "" Then

    If Button9.Text = Button10.Text Or Button9.Text = Button13.Text Or Button9.Text = Button14.Text Then

    MessageBox.Show("There is a Horizontal Error with Button9")

    Exit Sub

    End If

    If Button9.Text = Button11.Text Or Button9.Text = Button3.Text Or Button9.Text = Button1.Text Then

    MessageBox.Show("There is a Vertical Error with Button9")

    Exit Sub

    End If

    If Button9.Text = Button10.Text Or Button9.Text = Button11.Text Or Button9.Text = Button12.Text Then

    MessageBox.Show("There is a Regional Error with Button9")

    Exit Sub

    End If

    End If

    If Button10.Text <> "" Then

    If Button10.Text = Button9.Text Or Button10.Text = Button13.Text Or Button10.Text = Button14.Text Then

    MessageBox.Show("There is a Horizontal Error with Button10")

    Exit Sub

    End If

    If Button10.Text = Button2.Text Or Button10.Text = Button4.Text Or Button10.Text = Button12.Text Then

    MessageBox.Show("There is a Vertical Error with Button10")

    Exit Sub

    End If

    If Button10.Text = Button9.Text Or Button10.Text = Button11.Text Or Button10.Text = Button12.Text Then

    MessageBox.Show("There is a Regional Error with Button10")

    Exit Sub

    End If

    End If

    If Button11.Text <> "" Then

    If Button11.Text = Button12.Text Or Button11.Text = Button15.Text Or Button11.Text = Button16.Text Then

    MessageBox.Show("There is a Horizontal Error with Button11")

    Exit Sub

    End If

    If Button11.Text = Button9.Text Or Button11.Text = Button3.Text Or Button11.Text = Button1.Text Then

    MessageBox.Show("There is a Vertical Error with Button11")

    Exit Sub

    End If

    If Button11.Text = Button12.Text Or Button11.Text = Button9.Text Or Button11.Text = Button10.Text Then

    MessageBox.Show("There is a Regional Error with Button11")

    Exit Sub

    End If

    End If

    If Button12.Text <> "" Then

    If Button12.Text = Button11.Text Or Button12.Text = Button15.Text Or Button12.Text = Button16.Text Then

    MessageBox.Show("There is a Horizontal Error with Button12")

    Exit Sub

    End If

    If Button12.Text = Button2.Text Or Button12.Text = Button4.Text Or Button12.Text = Button10.Text Then

    MessageBox.Show("There is a Vertical Error with Button12")

    Exit Sub

    End If

    If Button12.Text = Button9.Text Or Button12.Text = Button10.Text Or Button9.Text = Button11.Text Then

    MessageBox.Show("There is a Regional Error with Button12")

    Exit Sub

    End If

    End If

    If Button13.Text <> "" Then

    If Button13.Text = Button9.Text Or Button13.Text = Button10.Text Or Button13.Text = Button14.Text Then

    MessageBox.Show("There is a Horizontal Error with Button13")

    Exit Sub

    End If

    If Button13.Text = Button5.Text Or Button13.Text = Button7.Text Or Button13.Text = Button15.Text Then

    MessageBox.Show("There is a Vertical Error with Button13")

    Exit Sub

    End If

    If Button13.Text = Button14.Text Or Button13.Text = Button15.Text Or Button13.Text = Button16.Text Then

    MessageBox.Show("There is a Regional Error with Button13")

    Exit Sub

    End If

    End If

    If Button14.Text <> "" Then

    If Button14.Text = Button9.Text Or Button14.Text = Button10.Text Or Button14.Text = Button13.Text Then

    MessageBox.Show("There is a Horizontal Error with Button14")

    Exit Sub

    End If

    If Button14.Text = Button6.Text Or Button14.Text = Button8.Text Or Button14.Text = Button16.Text Then

    MessageBox.Show("There is a Vertical Error with Button14")

    Exit Sub

    End If

    If Button14.Text = Button13.Text Or Button14.Text = Button15.Text Or Button14.Text = Button16.Text Then

    MessageBox.Show("There is a Regional Error with Button14")

    Exit Sub

    End If

    End If

    If Button15.Text <> "" Then

    If Button15.Text = Button5.Text Or Button15.Text = Button7.Text Or Button15.Text = Button13.Text Then

    MessageBox.Show("There is a Horizontal Error with Button15")

    Exit Sub

    End If

    If Button15.Text = Button11.Text Or Button15.Text = Button12.Text Or Button15.Text = Button16.Text Then

    MessageBox.Show("There is a Vertical Error with Button15")

    Exit Sub

    End If

    If Button15.Text = Button13.Text Or Button15.Text = Button14.Text Or Button15.Text = Button16.Text Then

    MessageBox.Show("There is a Regional Error with Button15")

    Exit Sub

    End If

    End If

    If Button16.Text <> "" Then

    If Button16.Text = Button11.Text Or Button16.Text = Button12.Text Or Button16.Text = Button15.Text Then

    MessageBox.Show("There is a Horizontal Error with Button16")

    Exit Sub

    End If

    If Button16.Text = Button6.Text Or Button16.Text = Button8.Text Or Button16.Text = Button14.Text Then

    MessageBox.Show("There is a Vertical Error with Button16")

    Exit Sub

    End If

    If Button16.Text = Button13.Text Or Button16.Text = Button14.Text Or Button16.Text = Button15.Text Then

    MessageBox.Show("There is a Regional Error with Button16")

    Exit Sub

    End If

    End If

    If Button1.Text <> "" And Button2.Text <> "" And Button3.Text <> "" And Button4.Text <> "" _

    And Button5.Text <> "" And Button6.Text <> "" And Button7.Text <> "" And Button8.Text <> "" _

    And Button9.Text <> "" And Button10.Text <> "" And Button11.Text <> "" And Button12.Text <> "" _

    And Button13.Text <> "" And Button14.Text <> "" And Button15.Text <> "" And Button16.Text <> "" Then

    MessageBox.Show("You've Won! Congradulations")

    End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Timer1.Enabled = False 'disable timer at startup

    Randomize()

    Dim i, j, k As Integer

    Dim row, col As Integer

    For i = 1 To 16

    Next i

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click

    'Exit the project

    Me.Close()

    End Sub

    Dim counter As Integer

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    counter = counter + 1

    Label1.Text = counter

    IncrementLabel(Label1.Text)

    End Sub

    Private Sub IncrementLabel(ByRef time As String)

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

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

    End Sub

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

    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click

    Timer1.Enabled = True 'starts the timer by enabling it

    End Sub

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click

    Timer1.Enabled = False 'stops the timer by disabling it

    End Sub

    Private CycleNumber As Integer = 0

    Private SudokuGrid(16) As Integer

    Private SudokuTemp(16) As String

    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click

    Dim sw As StreamWriter = New StreamWriter("SudokuFile" & CycleNumber & ".txt")

    sw.WriteLine(Button1.Text)

    sw.WriteLine(Button2.Text)

    sw.WriteLine(Button3.Text)

    sw.WriteLine(Button4.Text)

    sw.WriteLine(Button5.Text)

    sw.WriteLine(Button6.Text)

    sw.WriteLine(Button7.Text)

    sw.WriteLine(Button8.Text)

    sw.WriteLine(Button9.Text)

    sw.WriteLine(Button10.Text)

    sw.WriteLine(Button11.Text)

    sw.WriteLine(Button12.Text)

    sw.WriteLine(Button13.Text)

    sw.WriteLine(Button14.Text)

    sw.WriteLine(Button15.Text)

    sw.WriteLine(Button16.Text)

    sw.Close()

    End Sub

    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click

    LoadFile("SudokuFile" & CycleNumber & ".txt")

    End Sub

    Private Sub LoadFile(ByVal filename As String)

    Dim sr As StreamReader = New StreamReader(filename)

    Button1.Text = sr.ReadLine()

    Button2.Text = sr.ReadLine()

    Button3.Text = sr.ReadLine()

    Button4.Text = sr.ReadLine()

    Button5.Text = sr.ReadLine()

    Button6.Text = sr.ReadLine()

    Button7.Text = sr.ReadLine()

    Button8.Text = sr.ReadLine()

    Button9.Text = sr.ReadLine()

    Button10.Text = sr.ReadLine()

    Button11.Text = sr.ReadLine()

    Button12.Text = sr.ReadLine()

    Button13.Text = sr.ReadLine()

    Button14.Text = sr.ReadLine()

    Button15.Text = sr.ReadLine()

    Button16.Text = sr.ReadLine()

    sr.Close()

    End Sub

    Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click

    CycleNumber = CycleNumber + 1

    If CycleNumber > 5 Then

    CycleNumber = 0

    End If

    End Sub

    Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click

    Button1.Text = Int(4 * Rnd()) + 1

    Button2.Text = Int(4 * Rnd()) + 1

    Button3.Text = Int(4 * Rnd()) + 1

    Button4.Text = Int(4 * Rnd()) + 1

    Button5.Text = Int(4 * Rnd()) + 1

    Button6.Text = Int(4 * Rnd()) + 1

    Button7.Text = Int(4 * Rnd()) + 1

    Button8.Text = Int(4 * Rnd()) + 1

    Button9.Text = Int(4 * Rnd()) + 1

    Button10.Text = Int(4 * Rnd()) + 1

    Button11.Text = Int(4 * Rnd()) + 1

    Button12.Text = Int(4 * Rnd()) + 1

    Button13.Text = Int(4 * Rnd()) + 1

    Button14.Text = Int(4 * Rnd()) + 1

    Button15.Text = Int(4 * Rnd()) + 1

    Button16.Text = Int(4 * Rnd()) + 1

    End Sub

    End Class

     

     

     

     

     

    Monday, February 12, 2007 4:03 AM

Answers

  • Hi,

    As it's a 16 x 16 grid you could use an array.

    Dim grid(16,16) As String

    Insert your characters into the grid.

     I would look at putting 16 x 16 textboxes or buttons on a panel then you could then use a For Each loop to check every controls value in that panel.

    If you did it with buttons then cycle through 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F then back to 0 again on the button click event.

    If you do it with textboxes then use the text_changed event to check the value in that row and in that column and in each 4 x4 group.

    You could flash the two textboxes backcolors if they are the same every second with a timer until one number is changed or for 5 seconds maybe.

    You could add a "Check Grid" button maybe?

     

    Regards,

    S_DS

     

     

     

    Monday, February 12, 2007 1:42 PM