Hello,
I am writing code to correct the error in a digital scanner that sometimes reads 2 as ">".
If the scanner includes this wrong character then the code below will execute:
if ((string)row.Cells[1].Value != txtScannedIn.Text.Trim())
{
string editedtext;
editedtext = ScanFix(txtScannedIn.Text, (string)row.Cells[1].Value);
txtScannedIn.Text = editedtext;
}
The method that it uses to fix the code is this:
private string ScanFix(string NotFound, string rightpart)
{
string replacer;
if (NotFound.Contains('>'))
{
replacer = NotFound.Replace('>', '2');
if (replacer == rightpart)
{
MessageBox.Show(replacer + " " + rightpart);
return replacer;
}
else return NotFound;
}
else
{
return NotFound;
}
}
These two code segments work exactly as they should when executed like this, however when I try to make the first block of code display a MessageBox with the updated "editedtext" string, the messagebox displays the original incorrect scan with the ">" in it.
if ((string)row.Cells[1].Value != txtScannedIn.Text.Trim())
{
string editedtext;
editedtext = ScanFix(txtScannedIn.Text, (string)row.Cells[1].Value);
MessageBox.Show(editedtext);
txtScannedIn.Text = editedtext;
}
What I have tried:
I have tried creating a separate variable to set the editedtext string equal to and then displaying that (if it works when I declare the txtScannedIn.Text to it why would it not allow that variable to be used?), and I have inserted MessageBox commands in other areas of the code to determine if they run (from my understanding including this messagebox OUTSIDE of the ScanFix method changes it to return the original NotFound value).
One thing that did allow the messagebox to display the correct scan/ the editedtext string to be updated the right way was if the message box is
MessageBox.Show(editedtext = ScanFix(txtScannedIn.Text, (string)row.Cells[1].Value));
I have never used this forum but I cannot find any documented case of this problem and nothing I have tried is allowing the Messagebox to simply display the return of the fixed scan the right way. If anyone sees this and knows how to fix this, I will greatly appreciate your help.
Thank you