TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
simon taylor
NA
38
69.2k
Trouble with case/switch statent
Jan 18 2011 6:36 AM
Hi,
i am having problems trying to validate my form controlls which are all text boxes. I am using a switch statment to testing things like if the fields are blank ect. However, when i run my app and place an @ sign in my postcode field for example, with all the other text boxes left blank. It shows my messegboxes correctly up to the point at with it sees the @ sign. Instead it displays my user generated message of: " Job center fied cannot be blank". However, i have a check for the @ sign . Why does it not display the correct message when it sees an @ sign?
private
void
cmdAdd_Click(
object
sender, EventArgs e)
{
JobCenter jCenter =
new
JobCenter();
string
jobCenterName;
string
jobCenterAdd;
jCenter.set_jobCenterName(txtJobCenterName.Text) ;
jobCenterName = jCenter.get_jobCenterName();
switch
(jobCenterName)
{
case
""
:
MessageBox.Show(
"Job Center Name cannot be blank"
);
this
.allClear();
break
;
case
"@"
:
MessageBox.Show(
"Job Center Name field cannot contain special characters e.g @ "
);
this
.allClear();
break
;
case
"+"
:
// does not seemt to validate
MessageBox.Show(
"Job Center Name will not take values such as positive + sign"
);
this
.allClear();
break
;
case
"-"
:
MessageBox.Show(
"Job Center Name will not take minus values"
);
this
.allClear();
break
;
case
"!"
:
MessageBox.Show(
"Job Center Name field will not accept specail characters such as exclamtion mark"
);
this
.allClear();
break
;
default
:
return
;
}
string
jobPostCd;
jCenter.set_jobCenterPostCode(txtJobCenterPostCode.Text);
jobPostCd = jCenter.get_jobCenterPostCode();
switch
(jobPostCd)
{
case
""
:
MessageBox.Show(
"Job Center Post Code cannot be blank"
);
this
.allClear();
break
;
case
"@"
:
MessageBox.Show(
"Job Center Post Code field cannot contain special characters e.g @ "
);
this
.allClear();
break
;
case
"+"
:
MessageBox.Show(
"Job Center Post Code will not take values such as positive + sign"
);
this
.allClear();
break
;
case
"-"
:
MessageBox.Show(
"Job Center Post Code will not take minus values"
);
this
.allClear();
break
;
case
"!"
:
MessageBox.Show(
"Job Center Post Code field will not accept specail characters such as exclamtion mark"
);
this
.allClear();
break
;
default
:
return
;
}
I have skipped the other case stements because they are doing the same thing.
Reply
Answers (
1
)
Relative Primenumber
Passing variables between forms