If Integer.Parse(btn1.Text) <> answers(0) Then
numberwrong += 1
btn1.BackColor = Color.Red
btn1check = True
wronganswer(0) = 1
This is an example of a code block that'll check every square. The wronganswer array is where I was hoping to store my incorrect answers. I've been instructed to simply put a msgbox within the if statement that checks each square. If the user were to answer all 81 boxes incorrectly, there'd be 81 message windows open and I'm not one to swamp my users in that fashion. Is there a way to redim the array by the number of another variable in a way like:
ReDim
wronganswer(numberwrong)so I have wronganswer() with the numberwrong number of dimensions? Even if I can figure out how to do that, is there a way to dynamically reproduce that in the msgbox for which buttons are actually incorrect?
AlanPosted Jun 23, 2007, 8:32 AM
As Mike said, you need to concatenate the wrong answers into a single string before calling the Msgbox function. If wrongAnswer is your ArrayList, then try this:
Dim squares As String = ""
Dim answer As Integer
Dim count As Integer = wrongAnswer.Count
wrongAnswer.Sort ' omit this line if sorting not needed
For i As Integer = 1 To count
answer = DirectCast(wrongAnswer(i - 1), Integer)
squares &= " " + answer.ToString
If i = Count Then Exit For
If i Mod 9 <> 0 Then
squares &= ","
Else
squares &= Chr(13)
End If
Next i
MsgBox("You need to check these squares : " & Chr(13) & Chr(13) & squares)
keith woodPosted Jun 23, 2007, 12:53 AM
MsgBox(
"You need to check " & wronganswer() & ".")MsgBox(
"You need to check " & wronganswer.ToString & ".") 'this successfully outputs the array typeI looked up more information on this subject and found a great tutorial on how to output this to a console app, but considering that's not what I have to work with, it won't help me. Since I can't run an If or For statement within a MsgBox, I'm stumped. I know this s probably really basic for your forum, and I thank you for your patience.
Mike GoldPosted Jun 22, 2007, 6:50 PM
I suspect you are asking how to keep track of wrong answers in the sudoku grid? Definitely try not to use GUI components to represent a part of your array. You should keep the grid stored in memory. (e.g. Dim SudokuBoardAnswers(9,9) As Integer) Initialize the grid to 0, and if someone has a wrong answer put it in the correct location in the rectangular array.
Also, as you said, you definitely don't want to pop up 81 message boxes. Consider writing all the wrong answers to a string and then putting it in the message box. Loop through the wrong answer grid and concatenate the wrong answers to the string.