1 Attachment(s)
Have a few quick questions about a program I'm writing
Ok I have the general idea of what i want in this program, but I just need some help in some areas.
For one thing I want to make sure in the email textbox that the user must enter text, a "@" and a "." then more text in that perticular order. As it is right now I used an if statement that checks that the characters are both there but does not make sure they are placed in that specific order
here is a sample of the code i used
Code:
private void txtEmail_TextChanged(object sender, EventArgs e)
{
//We will use "contains to make sure the user enters
// "@" and "." in their email address
Email = txtEmail.Text.Trim();
Email = txtEmail.Text;
string CheckEmailChar1 = "@";
string CheckEmailChar2 = ".";
if (Email.Contains(CheckEmailChar1) && Email.Contains(CheckEmailChar2))
{
}
else
{
MessageBox.Show("Please include @ and . in the email feild");
}
}
I am aslo having a aproblem in the "Loan amount requested textbox and I'm not sure exactly why. The program runs but as soon as I input anything into that textbox, I end up with an error and the program stops running.
I am a bit tired so I hope my post was still somewhat coherent, I will get back to this post later and try and get this fixed fairly soon. You will find the full program in the zip file attached.
Re: Have a few quick questions about a program I'm writing
Validating email address is best with regex.
Re: Have a few quick questions about a program I'm writing
What is the error message you receive when typing in the textbox?
Re: Have a few quick questions about a program I'm writing
It says FormatException was unhandled
call stack
> BankLoan.exe!BankLoan.Form1.txtIncome_TextChanged(object sender = {Text = "$5.00"}, System.EventArgs e = {System.EventArgs}) Line 273 C#
[External Code]
BankLoan.exe!BankLoan.Form1.txtLoanRequest_TextChanged(object sender = {Text = "5"}, System.EventArgs e = {System.EventArgs}) Line 282 + 0x2b bytes C#
[External Code]
BankLoan.exe!BankLoan.Program.Main() Line 18 + 0x1d bytes C#
[External Code]
Re: Have a few quick questions about a program I'm writing
Can you post the code in txtIncome_TextChanged and txtLoanRequest_TextChanged ?
Re: Have a few quick questions about a program I'm writing
Code:
private void txtLoanRequest_TextChanged(object sender, EventArgs e)
{
//convert the input into currency
LoanAmtRequest = txtLoanRequest.Text;
decimal finput = Convert.ToDecimal(LoanAmtRequest);
txtIncome.Text = finput.ToString("c");
}
Re: Have a few quick questions about a program I'm writing
Also can someone give me an example of how to use regular expressions here:
Code:
private void txtEmail_TextChanged(object sender, EventArgs e)
{
//We will use "contains to make sure the user enters
// "@" and "." in their email address
Email = txtEmail.Text.Trim();
Email = txtEmail.Text;
string CheckEmailChar1 = "@";
string CheckEmailChar2 = ".";
if (Email.Contains(CheckEmailChar1) && Email.Contains(CheckEmailChar2))
{
}
else
{
MessageBox.Show("Please include @ and . in the email feild");
}
Re: Have a few quick questions about a program I'm writing
Quote:
Originally Posted by
chipninja
Code:
private void txtLoanRequest_TextChanged(object sender, EventArgs e)
{
//convert the input into currency
LoanAmtRequest = txtLoanRequest.Text;
decimal finput = Convert.ToDecimal(LoanAmtRequest);
txtIncome.Text = finput.ToString("c");
}
Code:
private void txtLoanRequest_TextChanged(object sender, EventArgs e)
{
//convert the input into currency
LoanAmtRequest = txtLoanRequest.Text;
decimal finput = 0;
decimal.TryParse(LoanAmtRequest, out finput);
txtIncome.Text = finput.ToString("c");
}
Re: Have a few quick questions about a program I'm writing
Also wouldn't regex only work on the web and not withing the program? Meaning Id have to use something else for my email validation?
Re: Have a few quick questions about a program I'm writing
I'm terrible at Regex as the pattern syntax is like Klingon to me, but I do know that it is in no way bound to only web usage.
A Regex (in C#) is simply a class you can create like any other class in C#.
Re: Have a few quick questions about a program I'm writing
ohh ok thank you now i know. I'm still not sure how to use regex either. I looked at the webpage and it didnt make sense to me. I would need an example to understand it.
Also. After I run the code i get an error here:
Code:
private string ProperCase(string name)
{
string firstcharacter = "";
string restofstring = "";
int namelength = 0;
firstcharacter = name.Substring(0, 1);
namelength = name.Length - 1;
restofstring = name.Substring(1, namelength);
firstcharacter = firstcharacter.ToUpper();
restofstring = restofstring.ToLower();
name = firstcharacter + restofstring;
return name;
}
it says ArgumentOutof Range Exeption was unhandled
Re: Have a few quick questions about a program I'm writing
In regards to the "@" and "." issue, this is what I would do.
Firstly put it in the txtEmail_Leave instead of the _Textchanged. This way it will check once the user has finished putting in the email address, opposed to checking after every character they type (which will being up the Message Box for exery single character). Next I would create two integers, index of '@' and index of '.' and check to see if the index of '@' is lower than that of '.'. Therefore checking if the @ is before the .
private void txtEmail_Leave(object sender, EventArgs e)
{
//We will use "contains to make sure the user enters
// "@" and "." in their email address
Email = txtEmail.Text.Trim();
Email = txtEmail.Text;
string CheckEmailChar1 = "@";
string CheckEmailChar2 = ".";
if (Email.Contains(CheckEmailChar1) && Email.Contains(CheckEmailChar2))
{
int first = Email.IndexOf('@');
int second = Email.IndexOf('.');
if (first < second)
{
}
else
{
MessageBox.Show("Please include @ and . in the email feild, in the corrct order");
}
}
else
{
MessageBox.Show("Please include @ and . in the email feild");
}
}
Re: Have a few quick questions about a program I'm writing
I'm still getting runtime errors when i run the program. Its telling me FormatExeptionwa Unhandled here:
Code:
private void txtIncome_Leave(object sender, EventArgs e)
{
//convert the input into currency
Income = txtIncome.Text;
decimal sinput = Convert.ToDecimal(Income);
txtIncome.Text = sinput.ToString("c");
}
Re: Have a few quick questions about a program I'm writing
Quote:
Originally Posted by
chipninja
I'm still getting runtime errors when i run the program. Its telling me FormatExeptionwa Unhandled here:
Code:
private void txtIncome_Leave(object sender, EventArgs e)
{
//convert the input into currency
Income = txtIncome.Text;
decimal sinput = Convert.ToDecimal(Income);
txtIncome.Text = sinput.ToString("c");
}
Look at my last post in this thread..