Has the name entered in the name TextBox at least one
char?.
If yes, return true. The out parameter will have a valid
value returning to the caller.
If no
show a message box with a friendly error message
Set the focus to the textbox
return false
This is what i have
if (txtName.Text.Length > 0)
{
}
else
{
MessageBox.Show("Enter Letters Only", "Invalid Character", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
i have the problem whit the true false return can
first define a variable and pass it as ref parameter to function... and function itself is having retrun type as bool
so, varialbe name result will give u whether returned true or false and using strNameEntered after function call willl give u textbox value if textbox was not empty
hope this helps...
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
Marked as answer by Kalle_114 on Feb 22, 2012 01:06 PM
Kalle_114
Member
15 Points
12 Posts
Textbox exercise
Feb 22, 2012 12:19 PM|LINK
hello
Im going to do this.
Has the name entered in the name TextBox at least one
char?.
If yes, return true. The out parameter will have a valid
value returning to the caller.
If no
show a message box with a friendly error message
Set the focus to the textbox
return false
This is what i have
if (txtName.Text.Length > 0) { } else { MessageBox.Show("Enter Letters Only", "Invalid Character", MessageBoxButtons.OK, MessageBoxIcon.Error); } i have the problem whit the true false return cankedarrkulkar...
All-Star
34013 Points
5468 Posts
Re: Textbox exercise
Feb 22, 2012 12:51 PM|LINK
from the code u posted, i assume u r referring to c# winform app
then, u can try using ref parameter
define function like this
public bool FunctionName(ref string strName)
{
if(txtName.Text.Length > 0)
{
strName = txtName.Text;
return true;
}
else
{
MessageBox.Show("Enter Letters Only", "Invalid Character", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtName.Focus();
return true;
}
}
then, call the function like this
string strNameEntered; bool result=FunctionName(ref strNameEntered);first define a variable and pass it as ref parameter to function... and function itself is having retrun type as bool
so, varialbe name result will give u whether returned true or false and using strNameEntered after function call willl give u textbox value if textbox was not empty
hope this helps...
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Kalle_114
Member
15 Points
12 Posts
Re: Textbox exercise
Feb 22, 2012 01:01 PM|LINK
thx:D
i have private bool ReadAndValidateName(out string name) thx alot for it.
string strNameEntered; bool result=FunctionName(ref strNameEntered); going to the textbox? im new to winform appkedarrkulkar...
All-Star
34013 Points
5468 Posts
Re: Textbox exercise
Feb 22, 2012 01:05 PM|LINK
did my answer helped? or you are asking for something else/extra
please mark as answer on the post which helps you so that visitors can understand you have been helped and how
KK
Please mark as Answer if post helps in resolving your issue
My Site
Kalle_114
Member
15 Points
12 Posts
Re: Textbox exercise
Feb 22, 2012 01:07 PM|LINK
yes thx for the help