private void btnEnter_Click(object sender, EventArgs e)
{
// Strings MessageBox's
string a, c, d, f, g, h, i, j, k, l;
// Assign Values
a = "You Got it! Heres your next clue:\nCLUE";
c = "You Got it! Heres your next clue:\nCLUE";
d = "You Got it! Heres your next clue:\nCLUE";
f = "You Got it! Heres your next clue:\nCLUE";
g = "You Got it! Heres your next clue:\nCLUE";
h = "You Got it! Heres your next clue:\nCLUE";
i = "You Got it! Heres your next clue:\nCLUE";
j = "You Got it! Heres your next clue:\nCLUE";
k = "You Got it! Heres your next clue:\nCLUE";
l = "You Got it! Heres your next clue:\nCLUE";
int userNumber = int.Parse(txtEnter.Text);
switch (value)
{
case "5849":
return MessageBox.Show(a);
break;
case "4865":
return MessageBox.Show(c);
break;
default:
break;
}
}
//This add's an check if the value we try to "convert" can be converted to an Integer
if (int.TryParse(textBox1.Text, out userNumber))
{
if (userNumber == 5849)
MessageBox.Show(a);
else if (userNumber == 4865)
MessageBox.Show(c);
else MessageBox.Show("Invalid Number");
}
else MessageBox.Show("Something went wrong...");
//-----------------------------------------------
//We're not using any Exception here
try
{
int.Parse(textBox1.Text);
}
catch
{
MessageBox.Show("Error");
}
private void btnEnter_Click(object sender, EventArgs e)
{
//Base message string.
string strBaseMessage = "You Got it! Heres your next clue:\n";
int intUserNumber;
//If the user has some invalid input, tell them and stop exection of the method.
if (!int.TryParse(txtEnter.Text, out intUserNumber))
{
MessageBox.Show("Ya dun goofed");
return;
}
switch (value)
{
case "5849":
return MessageBox.Show(strBaseMessage + "CLUE");
break;
case "4865":
return MessageBox.Show(strBaseMessage + "CLUE");
break;
default:
break;
}
}
private void btnEnter_Click(object sender, EventArgs e)
{
int intUserNumber;
//Check for valid user input
if (int.TryParse(txtEnter.Text, out intUserNumber))
{
ProceedWithInput(intUserNumber);
}
else
{
MessageBox.Show("Ya dun goofed");
}
}
private void ProceedWithInput(int intUserInput)
{
//Base message string.
string strBaseMessage = "You Got it! Heres your next clue:\n";
switch (intUserInput)
{
case "5849":
return MessageBox.Show(strBaseMessage + "CLUE");
break;
case "4865":
return MessageBox.Show(strBaseMessage + "CLUE");
break;
default:
break;
}
}
switch (intUserInput)
{
case "5849":
MessageBox.Show(strBaseMessage + "CLUE");
return;
break;
case "4865":
MessageBox.Show(strBaseMessage + "CLUE");
return;
break;
default:
break;
}