Results 1 to 7 of 7

Thread: what is # in vb?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Unhappy what is # in vb?

    Hi All,

    I've to fix an old vb6 code and I've encounter the following lines

    hours = 300#
    if test * 100#/hours = abc then
    ' do something
    end if

    what is this # doing in the above code? I've never seen it before. I am completely stuck and can't move forward in my work until i figure out what this # is.

    thank you very much

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: what is # in vb?

    I think it forces the number into double (if not its single or currency)

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: what is # in vb?

    Moved from CodeBank

    Hi khaleefa, welcome to VBForums!

    The # is a shortcut for the data type Double, so this:
    VB Code:
    1. Dim a#
    is the same as:
    VB Code:
    1. Dim a as Double

    In your example it is just ensuring that the numbers 100 and 300 are worked with as Double rather than integer (I'm not sure why tho!).

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Resolved Re: what is # in vb?

    great, thank you veryyy much for your help (both of you

  5. #5
    Member
    Join Date
    Jun 2005
    Location
    Bolton, UK
    Posts
    42

    Re: what is # in vb?

    Just like to add for Khaleefa's benefit,

    ! = Single
    & = Long
    @ =Currency

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Re: what is # in vb?

    oh GOD, why couldn't they do it a simpler and more logical way?

    anyways thank you W00dy

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: what is # in vb?

    % = Integer
    $ = String
    Quote Originally Posted by si_the_geek
    In your example it is just ensuring that the numbers 100 and 300 are worked with as Double rather than integer (I'm not sure why tho!).
    Well VB treats numbers without a decimal as Integers unless they are to large in which case a Long is automatically used. By adding the # sign after those integer numbers VB will treat it as a Double already at compile time which makes the code run slightly faster since VB doesn't need to convert the Integer into a Double at run-time.

Posting Permissions

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



Click Here to Expand Forum to Full Width