I'm trying to get a user input number from text box on my GUI, then there are some calculation for that number and display it later in the same text box. Number entered is supposed to have hyphens which are then stripped to check for validity of that ISBN number. My ISBNChecker class strips hyphens, then calculates the check digit as follows.
public void stripHyphens()
{
numberEntered = numberEntered.Replace("-", "");
number = Convert.ToInt64(numberEntered);
}
public void separateDigits ()
{
if (numberEntered.Length == 10)
{
checkDigit = Convert.ToInt16(this.number % 10);
number = number / 10;
}
// logic for either 9-or 10- digit number
digit9 = Convert.ToInt16(this.number % 10); //this means class level not local level
number = number / 10;
digit8 = Convert.ToInt16(this.number % 10);
number = number / 10;
digit7 = Convert.ToInt16(this.number % 10);
number = number / 10;
digit6 = Convert.ToInt16(this.number % 10);
number = number / 10;
digit5 = Convert.ToInt16(this.number % 10);
number = number / 10;
digit4 = Convert.ToInt16(this.number % 10);
number = number / 10;
digit3 = Convert.ToInt16(this.number % 10);
number = number / 10;
digit2 = Convert.ToInt16(this.number % 10);
number = number / 10;
digit1 = Convert.ToInt16(this.number % 10);
} // end method separateDigits
public void calculateCheckDigit()
{
sumOfDigits = ((digit1 * 10) + (digit2 * 9) + (digit3 * 8) + (digit4 * 7) + (digit5 * 6) +
(digit6 * 5) + (digit7 * 4) + (digit8 * 3) + (digit9 * 2));
Console.WriteLine("sum: " + sumOfDigits);
Console.ReadLine();
Console.WriteLine("The check digit is: " + displayCheckDigit()); //wrapping method inside the method - implicit conversion
Console.ReadLine();
} //end method calculateCheckDigit
My GUI so far checks two methods:
namespace ISBNChecker
{
public partial class ISBNGUI : Form
{
ISBNChecker check = new ISBNChecker();
public ISBNGUI()
{
InitializeComponent();
}
private void xValidatebutton_Click(object sender, EventArgs e)
{
check.setNumberEntered("test");
check.inspectNumber();
}
The problem is I know there is a data type confusion in the NumberEntered parameter, but I don't know how to fix this. So far, it's grabbing the "test" value all the time. I tried to leave this blank "", it crashed. Can somebody please help me? I am really not sure where I am supposed to change this data type from string to long. I've tried to write a separate method to convert NumberEntered to long, that did not work either.