+ Reply to Thread
Results 1 to 7 of 7

Long variable returning unexpected result which appears to be only integer value

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Long variable returning unexpected result which appears to be only integer value

    hi,

    Please find the enclosed macro.

    I have a long data type (called junk1....see enclosed macro).

    I assign the cell contents of B4 to this junk1 variable.

    But for some reason the value sent to junk1 is 1..............when i expected it to be 0.893674293405114.

    If i dont define junk1 as a long data type it works............

    i am kinda confused..........i want junk1 to hold the number 0.893674293405114 and not the value of 1

    any ideas on whats going on?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Long variable returning unexpected result which appears to be only integer value

    Long is actually Long Integer try Double instead.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Long variable returning unexpected result which appears to be only integer value

    norie,

    i am confused................

    if i do the following in the code

    Please Login or Register  to view this content.
    junk2 will be displayed as 0.894.............this tells me that junk2 does not have to be an integer

    any thoughts?

    you are correct that if i change the data type to double then i get the desired result but ......dont understand

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Long variable returning unexpected result which appears to be only integer value

    Hey, not as confused as me.

    That's because when I run that code I see a 1 in the message box.

    If you are dealing with whole numbers use Long (integer) if you are dealing with decimales use Double(or Single, or Decimal).
    Last edited by Norie; 07-05-2013 at 10:01 AM.

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Long variable returning unexpected result which appears to be only integer value

    norie.........see enclosed macro........if you run it the 2nd dialog box shows a number like 0.894 which is not a whole number or integer

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Long variable returning unexpected result which appears to be only integer value

    Eh, junk2 hasn't been declared with any data type so is a Variant.

    Try this.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Long variable returning unexpected result which appears to be only integer value

    you're right...........ahhhhhhhhhhhhhhhhh

    so sorry about that...............guess thats why it helps to have someone review your code sometimes.............

    appologies..........thanks for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1