Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Enum or something else?

Enum or something else?

Scheduled Pinned Locked Moved C#
question
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrooverFromHolland
    wrote on last edited by
    #1

    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;
    
    R P 2 Replies Last reply
    0
    • G GrooverFromHolland

      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;
      
      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Can you please repost using <pre> </pre> tags? /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • G GrooverFromHolland

        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;
        
        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        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 :

        G 1 Reply Last reply
        0
        • P PIEBALDconsult

          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 :

          G Offline
          G Offline
          GrooverFromHolland
          wrote on last edited by
          #4

          Thank U very much, I changed my code and it works! This way my code is much more readable and simpler. Thanks, Groover.

          P M 2 Replies Last reply
          0
          • G GrooverFromHolland

            Thank U very much, I changed my code and it works! This way my code is much more readable and simpler. Thanks, Groover.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            :thumbsup:

            1 Reply Last reply
            0
            • G GrooverFromHolland

              Thank U very much, I changed my code and it works! This way my code is much more readable and simpler. Thanks, Groover.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              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

              P 1 Reply Last reply
              0
              • M Mycroft Holmes

                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

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #7

                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

                P 1 Reply Last reply
                0
                • P Paul Conrad

                  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

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  You're too kind.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups