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. Getting integer values (not double-precision) from a slider (trackbar)

Getting integer values (not double-precision) from a slider (trackbar)

Scheduled Pinned Locked Moved C#
hardwarequestion
9 Posts 3 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.
  • A Offline
    A Offline
    ant damage
    wrote on last edited by
    #1

    Does anybody knows a way to get integer values from the slider control, instead of double-precision values? My slider control is from 0 to 255 and I want use it as way of getting an integer value, to be able to send it throw the serial port to the arduino duemilanove.

    A L 2 Replies Last reply
    0
    • A ant damage

      Does anybody knows a way to get integer values from the slider control, instead of double-precision values? My slider control is from 0 to 255 and I want use it as way of getting an integer value, to be able to send it throw the serial port to the arduino duemilanove.

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      Can't you just cast the double to an int? Or better yet, Round it to the nearest whole number then cast it to an int?

      double someVal = 0.5782;
      int intVal = (int)Math.Round(someVal);

      My current favourite quote is: Punch them in the face, see what happens!

      -SK Genius

      1 Reply Last reply
      0
      • A ant damage

        Does anybody knows a way to get integer values from the slider control, instead of double-precision values? My slider control is from 0 to 255 and I want use it as way of getting an integer value, to be able to send it throw the serial port to the arduino duemilanove.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        In my books TrackBar.Value[^] is an integer. :confused:

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read formatted code with indentation, so please use PRE tags for code snippets.


        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


        A 1 Reply Last reply
        0
        • L Luc Pattyn

          In my books TrackBar.Value[^] is an integer. :confused:

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read formatted code with indentation, so please use PRE tags for code snippets.


          I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


          A Offline
          A Offline
          ant damage
          wrote on last edited by
          #4

          I'm using C# but in WPF Application (XAML) the snippet using Math.Round works perfectly

          L 1 Reply Last reply
          0
          • A ant damage

            I'm using C# but in WPF Application (XAML) the snippet using Math.Round works perfectly

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            you should have said so. it is the (int) cast that solves it, rounding/ceiling/flooring is up to you. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


            A 1 Reply Last reply
            0
            • L Luc Pattyn

              you should have said so. it is the (int) cast that solves it, rounding/ceiling/flooring is up to you. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              A Offline
              A Offline
              ant damage
              wrote on last edited by
              #6

              It doesn't matter to make a (int) cast, since the value of slider is to be stored in a label. In XAML, label.Content is of type 'object'

              A L 2 Replies Last reply
              0
              • A ant damage

                It doesn't matter to make a (int) cast, since the value of slider is to be stored in a label. In XAML, label.Content is of type 'object'

                A Offline
                A Offline
                ant damage
                wrote on last edited by
                #7

                I'm fine for now. I have no more questions. Thanks for everyone!

                1 Reply Last reply
                0
                • A ant damage

                  It doesn't matter to make a (int) cast, since the value of slider is to be stored in a label. In XAML, label.Content is of type 'object'

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  :confused: :confused: :confused: :confused: you asked for an integer value, see the subject line.

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read formatted code with indentation, so please use PRE tags for code snippets.


                  I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                  A 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    :confused: :confused: :confused: :confused: you asked for an integer value, see the subject line.

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read formatted code with indentation, so please use PRE tags for code snippets.


                    I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                    A Offline
                    A Offline
                    ant damage
                    wrote on last edited by
                    #9

                    Here is the point: Getting a number from the slider control and make it integer (a.k.a. removing fractional part) so that I can send it through the serial port When speaking about integers, it doesn't mean to be a 'int' variable, but in other words, a natural number

                    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