Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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;

 

if (value > 0) {
  // Stuff...
}
else {
  // Less than 0.
}

Gamer extraordinaire. Programmer wannabe.
  • Leaders
Posted

you could always use the switch statement , here's a simple example :)

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;
}
}

  • *Experts*
Posted
That's a pretty cheesy thing to do. :p Also, highly unnecesary, when this will do:
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.

  • Leaders
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...