Penny hapeny
2008-01-16 14:34:31 UTC
Hi I hope some of you can help me.
I am using Builder 6 standard and trying to learn C++ by attempting to write
a program to solve a Sudoku puzzle.
The following code is one of the routines in my program Grid[Row][Col][box]
is a three dimensional array
the first position in this array that I have called [box] here just for
clarity, contains the value where that is given at the start of the game.
If that value is zero then the following positions hold all the possible
solutions for that place on the Grid.
I have now added a button called Check_Singles2 this looks to see if any of
the predicted solutions give only one value, If this is
the case then I want to change the Font Color before entering that value
into the displayed Grid that consists of 9x9 Edit boxes. the color
originally when the given values were entered was Red. So the idea is that
by being Black one can see what has been entered at this stage.
The program compiles Ok but when Run produces the error shown lower down at
the point in the code that Builder indicates.
Later runs of the same program without any modification have only produced
the second message.
void __fastcall TForm1::Check_Singles2Click(TObject *Sender)
{
{//1 Open
bool Flag = false;
Row =0;
Col =0;
x = 1;
/*** This routine will be to find if there is only a single possibility and
if so enter it into that box, with a Black character font
***********/
/**** Checks if box contains a given value and set a flag
****/
if(Grid[Row][Col][0] != 0)
Flag = true; // If true set Flag true else false.
else Flag = false;
if(Flag == false) // If false do the following code. If true skip
following code.
{//2 Open
for(Row =0; Row <=9; Row++)
{//3 Open
for(Col =0; Col <=9; Col++)
{//4 Open
if((Grid[Row][Col][x] >> Grid[Row][Col][x+1]) &&
(Grid[Row][Col][x+1] == 0))
{//5 Open
// There is only one possible value.
Grid[Row][Col][0] = Grid[Row][Col][1]; // So copy it to the first
position in Grid
Grid[Row][Col][1] = 0; // And replace the value in
the second position with a zero.
TForm1::EditControls[Row][Col]->Font->Color = clBlack; // Now
change the Font Color to Black. But a Run error here.
With the above line of code highlighted.
Debugger Exception Notification
---------------------------
Project Project_024.exe raised exception class EAccessViolation with message
'Access violation at address 004049EC in module 'Project_022.exe'.
Read of address 00000069'. Process stopped. Use Step or Run to continue.
If I then pressed F9 (Run) at this point, I got the following message.
---------------------------
Access violation at address 004050E8 in module 'Project_024.exe'. Read of
address 00000069.
---------------------------
OK
Clicking OK and the program continues to run and the digits entered by this
function are now in Black.
EditControls[Row][Col]->Text = IntToStr (Grid[Row][Col][0]); // Show
the value in the Edit Box
}//5 Close
}//4 Open
}//3 Close
}//2 Close
}//1 Close
}
Thanks hoping for some help
Penny.
I am using Builder 6 standard and trying to learn C++ by attempting to write
a program to solve a Sudoku puzzle.
The following code is one of the routines in my program Grid[Row][Col][box]
is a three dimensional array
the first position in this array that I have called [box] here just for
clarity, contains the value where that is given at the start of the game.
If that value is zero then the following positions hold all the possible
solutions for that place on the Grid.
I have now added a button called Check_Singles2 this looks to see if any of
the predicted solutions give only one value, If this is
the case then I want to change the Font Color before entering that value
into the displayed Grid that consists of 9x9 Edit boxes. the color
originally when the given values were entered was Red. So the idea is that
by being Black one can see what has been entered at this stage.
The program compiles Ok but when Run produces the error shown lower down at
the point in the code that Builder indicates.
Later runs of the same program without any modification have only produced
the second message.
void __fastcall TForm1::Check_Singles2Click(TObject *Sender)
{
{//1 Open
bool Flag = false;
Row =0;
Col =0;
x = 1;
/*** This routine will be to find if there is only a single possibility and
if so enter it into that box, with a Black character font
***********/
/**** Checks if box contains a given value and set a flag
****/
if(Grid[Row][Col][0] != 0)
Flag = true; // If true set Flag true else false.
else Flag = false;
if(Flag == false) // If false do the following code. If true skip
following code.
{//2 Open
for(Row =0; Row <=9; Row++)
{//3 Open
for(Col =0; Col <=9; Col++)
{//4 Open
if((Grid[Row][Col][x] >> Grid[Row][Col][x+1]) &&
(Grid[Row][Col][x+1] == 0))
{//5 Open
// There is only one possible value.
Grid[Row][Col][0] = Grid[Row][Col][1]; // So copy it to the first
position in Grid
Grid[Row][Col][1] = 0; // And replace the value in
the second position with a zero.
TForm1::EditControls[Row][Col]->Font->Color = clBlack; // Now
change the Font Color to Black. But a Run error here.
With the above line of code highlighted.
Debugger Exception Notification
---------------------------
Project Project_024.exe raised exception class EAccessViolation with message
'Access violation at address 004049EC in module 'Project_022.exe'.
Read of address 00000069'. Process stopped. Use Step or Run to continue.
If I then pressed F9 (Run) at this point, I got the following message.
---------------------------
Access violation at address 004050E8 in module 'Project_024.exe'. Read of
address 00000069.
---------------------------
OK
Clicking OK and the program continues to run and the digits entered by this
function are now in Black.
EditControls[Row][Col]->Text = IntToStr (Grid[Row][Col][0]); // Show
the value in the Edit Box
}//5 Close
}//4 Open
}//3 Close
}//2 Close
}//1 Close
}
Thanks hoping for some help
Penny.