943,678 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1184
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 23rd, 2009
0

case statement not working

Expand Post »
I have a case statement that evaluates a string in a combo box on a form which is either English or Metric. What I'm finding is that the case statement does not see the pull down box contents which is loaded by default unless it is physically reselected by the user. In other words the combo box defaults to "metric" but the case statement does not recognize it unless I go and reselect "metric" in the combo box. Any help would be appreciated.
Similar Threads
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009
Feb 23rd, 2009
0

Re: case statement not working

Whats wrong with the other question you already have a thread on this subject for?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Feb 23rd, 2009
0

Re: case statement not working

different problem
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009
Feb 23rd, 2009
0

Re: case statement not working

i don't understand very well your problem. Give us the code, example... don't let us guess.
Reputation Points: 11
Solved Threads: 7
Posting Whiz in Training
Clawsy is offline Offline
225 posts
since Feb 2008
Feb 23rd, 2009
0

Re: case statement not working

If this is the problem I think it is, I usually fix it by using the Text property of the combo box. It should allow you to get the text of what's in the combo box without the user actually having to select it.
Reputation Points: 23
Solved Threads: 10
Light Poster
bcasp is offline Offline
45 posts
since Apr 2008
Feb 23rd, 2009
0

Re: case statement not working

that is what im using the text property of the combo box
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009
Feb 23rd, 2009
0

Re: case statement not working

OK...have you tried using the SelectedItem property?
Reputation Points: 23
Solved Threads: 10
Light Poster
bcasp is offline Offline
45 posts
since Apr 2008
Feb 26th, 2009
0

Re: case statement not working

Click to Expand / Collapse  Quote originally posted by bcasp ...
OK...have you tried using the SelectedItem property?
Yes I get an error saying " a value of an integral type is expected"
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009
Feb 26th, 2009
0

Re: case statement not working

Show some code, show the line with the error, show what you tried to do to fix it
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Feb 26th, 2009
0

Re: case statement not working

Click to Expand / Collapse  Quote originally posted by LizR ...
Show some code, show the line with the error, show what you tried to do to fix it
Here is my code and when I run it always gets to the default althought there are strings showing in the combo box that came from the data base

switch (bunitsCB.Text)
{
case "Metric":
bl = Convert.ToDecimal(blanklTB.Text) / Convert.ToDecimal(25.4);
bw = Convert.ToDecimal(blankwTB.Text) / Convert.ToDecimal(25.4);
bp = Convert.ToDecimal(blankpTB.Text) / Convert.ToDecimal(25.4);
pd = Convert.ToDecimal(partdepthTB.Text) / Convert.ToDecimal(25.4);break;
case "English":
bl = Convert.ToDecimal(blanklTB.Text);
bw = Convert.ToDecimal(blankwTB.Text);
bp = Convert.ToDecimal(blankpTB.Text);
pd = Convert.ToDecimal(partdepthTB.Text);break;
default:
bl = 0;
bw = 0;
bp = 0;
pd = 0;
checkLB.Items.Add("YOU MUST SELECT A BLANK UNIT OF MEASURE");break;
}
switch (dieunitsCB.Text)
{
case "Metric":
dl = Convert.ToDecimal(dielTB.Text) / Convert.ToDecimal(25.4);
dw = Convert.ToDecimal(diewTB.Text) / Convert.ToDecimal(25.4);
ds = Convert.ToDecimal(dieshTB.Text) / Convert.ToDecimal(25.4);break;
case "English":
dl = Convert.ToDecimal(dielTB.Text);
dw = Convert.ToDecimal(diewTB.Text);
ds = Convert.ToDecimal(dieshTB.Text);break;
default:
dl = 0;
dw = 0;
ds = 0;
checkLB.Items.Add("YOU MUST SELECT A DIE UNIT OF MEASURE");break;
}
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: operator overloading
Next Thread in C# Forum Timeline: Passing Parameters/Arguments to a C# .NET Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC