+ Reply to Thread
Results 1 to 3 of 3

general question about variables

  1. #1
    Registered User
    Join Date
    05-09-2006
    Posts
    21

    general question about variables

    I can't for the life of me get this line of code to work:

    deltaX = .01

    When I go to the immediate window I find deltaX = 0 (the immediate window of the visual basic editor)

    I can't assign a decimal value to that variable. I remember it was much easier in quick basic to do this What am I doing wrong?

    BTW the variable deltaX has been dimensioned as LONG

    The good news is that I almost have a custom function that will allow integration by the trapezoidal method.
    Last edited by integreat; 05-19-2006 at 10:40 PM.

  2. #2
    JMB
    Guest

    RE: general question about variables

    Long is an integer data type

    Maybe Currency, Single, or Double would work better?


    Single
    (single-precision floating-point) 4 bytes -3.402823E38 to -1.401298E-45 for
    negative values; 1.401298E-45 to 3.402823E38 for positive values

    Double
    (double-precision floating-point) 8 bytes -1.79769313486231E308 to
    -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to
    1.79769313486232E308 for positive values

    Currency
    (scaled integer) 8 bytes -922,337,203,685,477.5808 to
    922,337,203,685,477.5807

    "integreat" wrote:

    >
    > I can't for the life of me get this line of code to work:
    >
    > deltaX = .01
    >
    > When I go to the immediate window I find deltaX = 0
    >
    > I can't assign a decimal value to that variable. I remember it was much
    > easier in quick basic to do this What am I doing wrong?
    >
    > BTW the variable deltaX has been dimensioned as LONG
    >
    > The good news is that I almost have a custom function that will allow
    > intergration by the trapezoidal method.
    >
    >
    > --
    > integreat
    > ------------------------------------------------------------------------
    > integreat's Profile: http://www.excelforum.com/member.php...o&userid=34282
    > View this thread: http://www.excelforum.com/showthread...hreadid=543908
    >
    >


  3. #3
    joeu2004@hotmail.com
    Guest

    RE: general question about variables

    "integreat" wrote:
    > I can't for the life of me get this line of code to work:
    > deltaX = .01
    > When I go to the immediate window I find deltaX = 0
    > [....] BTW the variable deltaX has been dimensioned as LONG


    That is precisely your mistake. Type long is an integer type.
    When you assign a floating-point value to an integer type, the
    value is rounding (apparently using banker's rounding! :-<) to
    integer value. Either declare deltaX as a floating-point type,
    e.g. double, or do not declare its type at all, which some
    people consider "poor form".

+ 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