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. Other Discussions
  3. The Weird and The Wonderful
  4. What would he do if it were floats?

What would he do if it were floats?

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpquestion
5 Posts 4 Posters 1 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.
  • M Offline
    M Offline
    mav northwind
    wrote on last edited by
    #1

    Found in an article approved not too long ago... And no, I didn't throw out case 5.

    public int Volume
    {
    get { return this.volume; }
    set
    {
    if (value < 0) { this.volume = 0; }
    else if (value > 10) { this.volume = 10; }
    else { this.volume = value; }

    //  Set it on Windows Media Player
    
    //  Fix up
    
    switch ( this.volume )
    {
      case 0: this.volume = 10; break;
      case 1: this.volume = 9; break;
      case 2: this.volume = 8; break;
      case 3: this.volume = 7; break;
      case 4: this.volume = 6; break;
      case 6: this.volume = 4; break;
      case 7: this.volume = 3; break;
      case 8: this.volume = 2; break;
      case 9: this.volume = 1; break;
      case 10: this.volume = 0; break;
    }
    
    this.volume = this.volume \* -100;
    
    this.player.Volume = this.volume;
    //System.Windows.Forms.MessageBox.Show(this.player.Volume.ToString());
    

    }
    }

    Regards, mav -- Black holes are the places where God divided by 0...

    OriginalGriffO M T 3 Replies Last reply
    0
    • M mav northwind

      Found in an article approved not too long ago... And no, I didn't throw out case 5.

      public int Volume
      {
      get { return this.volume; }
      set
      {
      if (value < 0) { this.volume = 0; }
      else if (value > 10) { this.volume = 10; }
      else { this.volume = value; }

      //  Set it on Windows Media Player
      
      //  Fix up
      
      switch ( this.volume )
      {
        case 0: this.volume = 10; break;
        case 1: this.volume = 9; break;
        case 2: this.volume = 8; break;
        case 3: this.volume = 7; break;
        case 4: this.volume = 6; break;
        case 6: this.volume = 4; break;
        case 7: this.volume = 3; break;
        case 8: this.volume = 2; break;
        case 9: this.volume = 1; break;
        case 10: this.volume = 0; break;
      }
      
      this.volume = this.volume \* -100;
      
      this.player.Volume = this.volume;
      //System.Windows.Forms.MessageBox.Show(this.player.Volume.ToString());
      

      }
      }

      Regards, mav -- Black holes are the places where God divided by 0...

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      mav.northwind wrote:

      no, I didn't throw out case 5.

      Why would you? Anyone can see it isn't necessary and the original author has optimised it out for efficiency reasons. :laugh:

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • M mav northwind

        Found in an article approved not too long ago... And no, I didn't throw out case 5.

        public int Volume
        {
        get { return this.volume; }
        set
        {
        if (value < 0) { this.volume = 0; }
        else if (value > 10) { this.volume = 10; }
        else { this.volume = value; }

        //  Set it on Windows Media Player
        
        //  Fix up
        
        switch ( this.volume )
        {
          case 0: this.volume = 10; break;
          case 1: this.volume = 9; break;
          case 2: this.volume = 8; break;
          case 3: this.volume = 7; break;
          case 4: this.volume = 6; break;
          case 6: this.volume = 4; break;
          case 7: this.volume = 3; break;
          case 8: this.volume = 2; break;
          case 9: this.volume = 1; break;
          case 10: this.volume = 0; break;
        }
        
        this.volume = this.volume \* -100;
        
        this.player.Volume = this.volume;
        //System.Windows.Forms.MessageBox.Show(this.player.Volume.ToString());
        

        }
        }

        Regards, mav -- Black holes are the places where God divided by 0...

        M Offline
        M Offline
        Megidolaon
        wrote on last edited by
        #3

        How about:

        this.volume = 10 - this.volume;

        Or is that too verbose?

        mav.northwind wrote:

        this.volume = this.volume * -100;

        So, first prevent setting the volume to any value lower than 0 and than set it way below 0 every time?

        mav.northwind wrote:

        this.player.Volume = this.volume;

        Good job causing an endless recursion... X|

        OriginalGriffO 1 Reply Last reply
        0
        • M Megidolaon

          How about:

          this.volume = 10 - this.volume;

          Or is that too verbose?

          mav.northwind wrote:

          this.volume = this.volume * -100;

          So, first prevent setting the volume to any value lower than 0 and than set it way below 0 every time?

          mav.northwind wrote:

          this.player.Volume = this.volume;

          Good job causing an endless recursion... X|

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          I just love the effect of

          this.volume++;

          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • M mav northwind

            Found in an article approved not too long ago... And no, I didn't throw out case 5.

            public int Volume
            {
            get { return this.volume; }
            set
            {
            if (value < 0) { this.volume = 0; }
            else if (value > 10) { this.volume = 10; }
            else { this.volume = value; }

            //  Set it on Windows Media Player
            
            //  Fix up
            
            switch ( this.volume )
            {
              case 0: this.volume = 10; break;
              case 1: this.volume = 9; break;
              case 2: this.volume = 8; break;
              case 3: this.volume = 7; break;
              case 4: this.volume = 6; break;
              case 6: this.volume = 4; break;
              case 7: this.volume = 3; break;
              case 8: this.volume = 2; break;
              case 9: this.volume = 1; break;
              case 10: this.volume = 0; break;
            }
            
            this.volume = this.volume \* -100;
            
            this.player.Volume = this.volume;
            //System.Windows.Forms.MessageBox.Show(this.player.Volume.ToString());
            

            }
            }

            Regards, mav -- Black holes are the places where God divided by 0...

            T Offline
            T Offline
            theCPkid
            wrote on last edited by
            #5

            an old textbook way to improve your efficiency when your boss is using TLOC :) using float will make him much more efficient. :-D

            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