VB6/VB.NET Case is < 0 - in c# how?

chuawenching

Regular
Joined
Jul 26, 2003
Messages
66
Hi there. I need some help here.

I am trying to convert a sample application for learning purposes. But i am stuck to see this:

Select Case ShipPitchSM
Case Is > 0
ShipPitchSM = ShipPitchSM - Friction
If ShipPitchSM < 0 Then ShipPitchSM = 0
If ShipPitchSM > 0.03 Then ShipPitchSM = 0.03
Case Is < 0
ShipPitchSM = ShipPitchSM + Friction
If ShipPitchSM > 0 Then ShipPitchSM = 0
If ShipPitchSM < -0.03 Then ShipPitchSM = -0.03
End Select

Select Case ShipYawSM
Case Is > 0
ShipYawSM = ShipYawSM - Friction
If ShipYawSM < 0 Then ShipYawSM = 0
If ShipYawSM > 0.03 Then ShipYawSM = 0.03
Case Is < 0
ShipYawSM = ShipYawSM + Friction
If ShipYawSM > 0 Then ShipYawSM = 0
If ShipYawSM < -0.03 Then ShipYawSM = -0.03
End Select

Select Case ShipRollSM
Case Is > 0
ShipRollSM = ShipRollSM - Friction
If ShipRollSM < 0 Then ShipRollSM = 0
If ShipRollSM > 0.03 Then ShipRollSM = 0.03
Case Is < 0
ShipRollSM = ShipRollSM + Friction
If ShipRollSM > 0 Then ShipRollSM = 0
If ShipRollSM < -0.03 Then ShipRollSM = -0.03
End Select

Any help?

How do you code that in c#? I try my best to place conditions in case statements, but compile errors.

Thanks.

Regards,
Chua Wen Ching :p
 
I don't believe you can do that in C#. Just use a simple if statement, it'd be cleaner for what you're doing anyway;

C#:
if (value > 0) {
   // Stuff...
}
else {
   // Less than 0.
}
 
you could always use the switch statement , here's a simple example :)
C#:
private void val()
{
	int x =-1;
	switch(x.CompareTo(0)<0)
	{
		case true:
			MessageBox.Show("the value is less than zero!");
		break;
		case false:
            MessageBox.Show("the value is greater than zero!");
		break;
	}
}
 
That's a pretty cheesy thing to do. :p Also, highly unnecesary, when this will do:
C#:
if (x < 0)
  MessageBox.Show("the value is less than zero!");
else
  MessageBox.Show("the value is greater than zero!");
Unless you are looking at the value of one variable, and comparing it to many others (3+ more), if statements are generally cleaner than switch statements.
 
just proving a point that it can be done with switch ( he posted the same question on codeproject's forum and was basiclly under the impression that it wasn't possible with switch ) ;)
i like to prove the impossible wrong , regardless how cheesey it may be:p
 
Back
Top