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

Join 137,265 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,507 people online right now. Registration is fast and FREE... Join Now!




Sudoku Checker

 
Reply to this topicStart new topic

Sudoku Checker, might be to advance for ya'll

czanime
25 Nov, 2006 - 05:46 PM
Post #1

New D.I.C Head
*

Joined: 30 Oct, 2006
Posts: 2


My Contributions
'Maybe this isn't possible but does anybobdy know how to highlight the cells that come up as a "problem"
CODE

Option Explicit
Sub Sudokutest()
Dim row As Integer
Dim col As Integer
Dim I As Integer
Dim IsBlank As Variant
Dim CellValue As Integer
Dim foundone As String
Dim foundtwo As String
Dim foundthree As String
Dim foundfour As String
Dim foundfive As String
Dim foundsix As String
Dim foundseven As String
Dim foundeight As String
Dim foundnine As String
Dim problem As Variant  'not sure if it is an integer or string
Dim Sec1 As Integer

'Checks columns for errors
col = 1
For col = 1 To 9
    For I = 1 To 9
    CellValue = Cells(I, col).Value
    Select Case CellValue
        Case 1
            If foundone = "yes" Then
              problem = "yes"
            Else
                foundone = "yes"
            End If
        Case 2
            If foundtwo = "yes" Then
              problem = "yes"
            Else
                foundtwo = "yes"
            End If
        Case 3
            If foundthree = "yes" Then
                problem = "yes"
            Else
                foundthree = "yes"
            End If
        Case 4
            If foundfour = "yes" Then
                problem = "yes"
            Else
                foundfour = "yes"
            End If
        Case 5
            If foundfive = "yes" Then
                problem = "yes"
            Else
                foundfive = "yes"
            End If
        Case 6
            If foundsix = "yes" Then
                problem = "yes"
            Else
                foundsix = "yes"
            End If
        Case 7
            If foundseven = "yes" Then
                problem = "yes"
            Else
                foundseven = "yes"
            End If
        Case 8
            If foundeight = "yes" Then
                problem = "yes"
            Else
                foundeight = "yes"
            End If
        Case 9
            If foundnine = "yes" Then
                problem = "yes"
            Else
                foundnine = "yes"
            End If
        End Select
        If problem = "yes" Then
            MsgBox ("You have a repeated number in a cell")
            Cells("").Select
    With Selection.Interior
        .ColorIndex = 6
        .Pattern = xlSolid
    End With
            Exit For
        End If
    Next I
    'reset all found variables
    CellValue = 0
    foundone = "no"
    foundtwo = "no"
    foundthree = "no"
    foundfour = "no"
    foundfive = "no"
    foundsix = "no"
    foundseven = "no"
    foundeight = "no"
    foundnine = "no"
     MsgBox "done with column" & col
  Next col
  
'Check Rows for errors
  row = 1
For row = 1 To 9
    For I = 1 To 9
    CellValue = Cells(row, I).Value
    Select Case CellValue
        Case 1
            If foundone = "yes" Then
              problem = "yes"
            Else
                foundone = "yes"
            End If
        Case 2
            If foundtwo = "yes" Then
              problem = "yes"
            Else
                foundtwo = "yes"
            End If
        Case 3
            If foundthree = "yes" Then
                problem = "yes"
            Else
                foundthree = "yes"
            End If
        Case 4
            If foundfour = "yes" Then
                problem = "yes"
            Else
                foundfour = "yes"
            End If
        Case 5
            If foundfive = "yes" Then
                problem = "yes"
            Else
                foundfive = "yes"
            End If
        Case 6
            If foundsix = "yes" Then
                problem = "yes"
            Else
                foundsix = "yes"
            End If
        Case 7
            If foundseven = "yes" Then
                problem = "yes"
            Else
                foundseven = "yes"
            End If
        Case 8
            If foundeight = "yes" Then
                problem = "yes"
            Else
                foundeight = "yes"
            End If
        Case 9
            If foundnine = "yes" Then
                problem = "yes"
            Else
                foundnine = "yes"
            End If
        End Select
        If problem = "yes" Then
            MsgBox ("You have a repeated number in a row")
            Cell.Select
                With Selection.Interior
                .ColorIndex = 6
                .Pattern = xlSolid
                End With
            Exit For
        End If
    Next I
    'reset all found variables
    CellValue = 0
    foundone = "no"
    foundtwo = "no"
    foundthree = "no"
    foundfour = "no"
    foundfive = "no"
    foundsix = "no"
    foundseven = "no"
    foundeight = "no"
    foundnine = "no"
     MsgBox "done with row" & row
  Next row


            
End Sub


edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Sudoku Checker
25 Nov, 2006 - 06:29 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,013



Thanked: 18 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
noone is going to help you unless you follow the simple rule of putting [code ][ /code] brackets around your code (edit this post and add them)

also be more specific about your problem

Also your dims can be condensed: Dim f As String, f As String

I'm also having trouble understanding your combonation of a switch like VB and if's... there must be an easier way...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 07:25PM

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