Enum or something else?
-
Hi all, I want to make this piece of code more simple:
//***PseudoCode***//
enum selectSentMode { sent, notSent, sentError }
int sentStatus;private void portExt_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//
Other code ..........
//
if (sendIndex > 512)
{
sentStatus=(int) selectSentMode.sent;
}
else if (sendIndex == 0)
{
sentStatus = (int)selectSentMode.notSent;
}
else
{
sentStatus = (int)selectSentMode.sentError;
}
}
}private void tmrPortExt_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//
Code........
//switch (sentStatus) { case(int) selectSentMode.sent: DoSomthing; break; case(int) selectSentMode.notSent: DoSomthing; break; case(int) selectSentMode.sentError: ErrorHandling; break; default: break; } }
what I want is something like this:
//***PseudoCode***//
selectSentMode { sent, notSent, sentError }
private void portExt_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//
Other code ..........
//
if (sendIndex > 512)
{
selectSentMode = sent;
}
else if (sendIndex == 0)
{
selectSentMode=notSent;
}
else
{
selectSentMode=sentError;
}
}
}private void tmrPortExt_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//
Code........
//switch (selectSentMode) { case sent: DoSomthing; break; case notSent: DoSomthing; break;
-
Hi all, I want to make this piece of code more simple:
//***PseudoCode***//
enum selectSentMode { sent, notSent, sentError }
int sentStatus;private void portExt_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//
Other code ..........
//
if (sendIndex > 512)
{
sentStatus=(int) selectSentMode.sent;
}
else if (sendIndex == 0)
{
sentStatus = (int)selectSentMode.notSent;
}
else
{
sentStatus = (int)selectSentMode.sentError;
}
}
}private void tmrPortExt_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//
Code........
//switch (sentStatus) { case(int) selectSentMode.sent: DoSomthing; break; case(int) selectSentMode.notSent: DoSomthing; break; case(int) selectSentMode.sentError: ErrorHandling; break; default: break; } }
what I want is something like this:
//***PseudoCode***//
selectSentMode { sent, notSent, sentError }
private void portExt_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//
Other code ..........
//
if (sendIndex > 512)
{
selectSentMode = sent;
}
else if (sendIndex == 0)
{
selectSentMode=notSent;
}
else
{
selectSentMode=sentError;
}
}
}private void tmrPortExt_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//
Code........
//switch (selectSentMode) { case sent: DoSomthing; break; case notSent: DoSomthing; break;
Can you please repost using
<pre>
</pre>
tags? /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Hi all, I want to make this piece of code more simple:
//***PseudoCode***//
enum selectSentMode { sent, notSent, sentError }
int sentStatus;private void portExt_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//
Other code ..........
//
if (sendIndex > 512)
{
sentStatus=(int) selectSentMode.sent;
}
else if (sendIndex == 0)
{
sentStatus = (int)selectSentMode.notSent;
}
else
{
sentStatus = (int)selectSentMode.sentError;
}
}
}private void tmrPortExt_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//
Code........
//switch (sentStatus) { case(int) selectSentMode.sent: DoSomthing; break; case(int) selectSentMode.notSent: DoSomthing; break; case(int) selectSentMode.sentError: ErrorHandling; break; default: break; } }
what I want is something like this:
//***PseudoCode***//
selectSentMode { sent, notSent, sentError }
private void portExt_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//
Other code ..........
//
if (sendIndex > 512)
{
selectSentMode = sent;
}
else if (sendIndex == 0)
{
selectSentMode=notSent;
}
else
{
selectSentMode=sentError;
}
}
}private void tmrPortExt_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//
Code........
//switch (selectSentMode) { case sent: DoSomthing; break; case notSent: DoSomthing; break;
You're almost there, you just need to correct the syntax.
enum selectSentMode { sent, notSent, sentError }
selectSentMode sentStatus ;
sentstatus = selectSentMode.sent ;
switch ( sentstatus )
case selectSentMode.sent :
-
You're almost there, you just need to correct the syntax.
enum selectSentMode { sent, notSent, sentError }
selectSentMode sentStatus ;
sentstatus = selectSentMode.sent ;
switch ( sentstatus )
case selectSentMode.sent :
Thank U very much, I changed my code and it works! This way my code is much more readable and simpler. Thanks, Groover.
-
Thank U very much, I changed my code and it works! This way my code is much more readable and simpler. Thanks, Groover.
:thumbsup:
-
Thank U very much, I changed my code and it works! This way my code is much more readable and simpler. Thanks, Groover.
While a thank you is appreciated it is customary to award a good answer with a 5!
Never underestimate the power of human stupidity RAH
-
While a thank you is appreciated it is customary to award a good answer with a 5!
Never underestimate the power of human stupidity RAH
I don't know why PIEBald didn't get three 5's, so added a 5 of my own to his post :)
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
I don't know why PIEBald didn't get three 5's, so added a 5 of my own to his post :)
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
You're too kind.