Cannot convert double to long.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • willemr
    New Member
    • May 2010
    • 9

    Cannot convert double to long.

    Hi guys,


    I have another problem.

    I have to use a long in my webservice function, but I have to get some data in it that won't fit.

    I need to get this in a long 003002a0. And it only seems to go in a double.

    Can anyone help?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    The range of a long is –9,223,372,036, 854,775,808 to 9,223,372,036,8 54,775,807

    So I think 3,146,400 (003002a0) will fit just fine.

    Comment

    • willemr
      New Member
      • May 2010
      • 9

      #3
      I still can't fix it.


      When it put

      RFID = (long)003002a0

      It's still gives a wrong value..

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I have no idea what your RFID variable is, or what your code is or what you mean by "it still gives me a wrong value" since that isn't a genuine message from Visual Studio.

        It helps the volunteers here tremendously when you post the actual code that is causing you problems. Not the entire application. Just the parts you have written that are causing the problem.

        1 - Copy the code from Visual Studio
        [imgnothumb]http://clint.stlaurent .net/bytes/code-copy.jpg[/imgnothumb]

        2 - In your question thread, click the [code] tags button. Its the one that looks like # symbol
        [imgnothumb]http://clint.stlaurent .net/bytes/tags-code.jpg[/imgnothumb]
        Code tags have magically appeared in your post with the cursor right between them.

        [code]|[/code]

        Just paste and you should see this
        [CODE] public void BrokenMethod()
        {
        // I don't understand why this doesn't work
        int Yogi = "Bear";
        }[/CODE]

        Which will look like this
        Code:
                public void BrokenMethod()
                {
                    // I don't understand why this doesn't work
                    int Yogi = "Bear";
                }
        More on tags. They're cool. Check'em out.

        Comment

        • willemr
          New Member
          • May 2010
          • 9

          #5
          This is the piece I wrote

          Code:
          private void RFIDtoID()
                  {
                                  
                          getKeyTag4Number _RFID = new getKeyTag4Number();
                          _RFID.login = login;
                          _RFID.electronicNumber = (long)003002a0;
                          long ID = wService.getKeyTag4Number(_RFID).@return.keyTagID;
                          string KTName = wService.getKeyTag4Number(_RFID).@return.keyTagTerminalDisplayName;
                          label1.Text = ID.ToString();
                          label3.Text = KTName;
          I have to search a database via a webservice. And therefore I need to get the RFIDcode in a long, because the function will only accept a long.
          When I use the debugger, I can see that _RFID has the wrong value for the electronicnumbe r.

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            _RFID.electroni cNumber = (long)0x003002a 0;
            ??
            Not sure how your code compiles.

            Comment

            • willemr
              New Member
              • May 2010
              • 9

              #7
              Thanks man, that worked :D

              Thanks a lot

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                I doubt this even compiles considering you aren't using proper notation for your hex number.
                Code:
                _RFID.electronicNumber = (long)003002a0;
                [imgnothumb]http://files.me.com/tlhintoq/qvq0dv[/imgnothumb]

                Try this

                Code:
                long temp = (long) 0x3002a0;
                MessageBox.Show(temp.ToString(), "0x3003a0");

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  In the future, please just tell us the real problem.
                  Obviously your code didn't compile, so there is no way it gave you a wrong value: It never ran.

                  We are more than happy to help with the real problem if you give us the real error.

                  Comment

                  Working...