+ Reply to Thread
Results 1 to 5 of 5

Dim i,j,k As Integer

Hybrid View

  1. #1
    Arne Hegefors
    Guest

    Dim i,j,k As Integer

    If you write:
    Dim i,j,k As Integer

    does that mean that only one of the variables actually is declared as an
    Integer (i or k) and the are declared as Variant?

    Also is it true that Integer no longer really exists in VBA (at least v.
    6.3)? I am told that an Integer is converted to a Long so it is better to use
    Long to begin with since the program does not have to convert the Integer to
    Long.

    Please ansewer these questions only if you are positive (I do not mean to
    come off as rude but I need to be sure). Thanks very much in advance!

  2. #2
    Bernie Deitrick
    Guest

    Re: Dim i,j,k As Integer

    Arne,

    With this:
    > Dim i,j,k As Integer


    i and j are variants, k is an integer.

    Use

    Dim i As Integer
    Dim j As Integer
    Dim k As Integer

    To check your last point, if this errors on the last line, then i is truly an integer

    Sub Test()
    Dim i As Integer
    Dim j As Long
    j = 654321
    j = 654321
    End Sub


    HTH,
    Bernie
    MS Excel MVP


    "Arne Hegefors" <[email protected]> wrote in message
    news:[email protected]...
    > If you write:
    > Dim i,j,k As Integer
    >
    > does that mean that only one of the variables actually is declared as an
    > Integer (i or k) and the are declared as Variant?
    >
    > Also is it true that Integer no longer really exists in VBA (at least v.
    > 6.3)? I am told that an Integer is converted to a Long so it is better to use
    > Long to begin with since the program does not have to convert the Integer to
    > Long.
    >
    > Please ansewer these questions only if you are positive (I do not mean to
    > come off as rude but I need to be sure). Thanks very much in advance!




  3. #3
    Arne Hegefors
    Guest

    Re: Dim i,j,k As Integer

    Thanks alot for your help! Regarding the last question I had your cod edoes
    not answer the question. I am told that vb automatically converts Integer to
    Long. Thus, any variable declared as Integer automatically transforms into
    Long implying that it can take any data that a variable declared as Long can
    do. The only difference is that the program needs to convert Integer to Long
    i.e. you do not notice the conversion it is just a waste of program memory
    capacity. If anyone knows if this is true or not please let me know! Thanks
    alot in advance!

    "Bernie Deitrick" skrev:

    > Arne,
    >
    > With this:
    > > Dim i,j,k As Integer

    >
    > i and j are variants, k is an integer.
    >
    > Use
    >
    > Dim i As Integer
    > Dim j As Integer
    > Dim k As Integer
    >
    > To check your last point, if this errors on the last line, then i is truly an integer
    >
    > Sub Test()
    > Dim i As Integer
    > Dim j As Long
    > j = 654321
    > j = 654321
    > End Sub
    >
    >
    > HTH,
    > Bernie
    > MS Excel MVP
    >
    >
    > "Arne Hegefors" <[email protected]> wrote in message
    > news:[email protected]...
    > > If you write:
    > > Dim i,j,k As Integer
    > >
    > > does that mean that only one of the variables actually is declared as an
    > > Integer (i or k) and the are declared as Variant?
    > >
    > > Also is it true that Integer no longer really exists in VBA (at least v.
    > > 6.3)? I am told that an Integer is converted to a Long so it is better to use
    > > Long to begin with since the program does not have to convert the Integer to
    > > Long.
    > >
    > > Please ansewer these questions only if you are positive (I do not mean to
    > > come off as rude but I need to be sure). Thanks very much in advance!

    >
    >
    >


  4. #4
    Andy Pope
    Guest

    Re: Dim i,j,k As Integer

    Have a read of the discussion
    http://www.dailydoseofexcel.com/arch...ng-vs-integer/

    Cheers
    Andy

    Arne Hegefors wrote:
    > Thanks alot for your help! Regarding the last question I had your cod edoes
    > not answer the question. I am told that vb automatically converts Integer to
    > Long. Thus, any variable declared as Integer automatically transforms into
    > Long implying that it can take any data that a variable declared as Long can
    > do. The only difference is that the program needs to convert Integer to Long
    > i.e. you do not notice the conversion it is just a waste of program memory
    > capacity. If anyone knows if this is true or not please let me know! Thanks
    > alot in advance!
    >
    > "Bernie Deitrick" skrev:
    >
    >
    >>Arne,
    >>
    >>With this:
    >>
    >>>Dim i,j,k As Integer

    >>
    >>i and j are variants, k is an integer.
    >>
    >>Use
    >>
    >>Dim i As Integer
    >>Dim j As Integer
    >>Dim k As Integer
    >>
    >>To check your last point, if this errors on the last line, then i is truly an integer
    >>
    >>Sub Test()
    >>Dim i As Integer
    >>Dim j As Long
    >>j = 654321
    >>j = 654321
    >>End Sub
    >>
    >>
    >>HTH,
    >>Bernie
    >>MS Excel MVP
    >>
    >>
    >>"Arne Hegefors" <[email protected]> wrote in message
    >>news:[email protected]...
    >>
    >>>If you write:
    >>>Dim i,j,k As Integer
    >>>
    >>>does that mean that only one of the variables actually is declared as an
    >>>Integer (i or k) and the are declared as Variant?
    >>>
    >>>Also is it true that Integer no longer really exists in VBA (at least v.
    >>>6.3)? I am told that an Integer is converted to a Long so it is better to use
    >>>Long to begin with since the program does not have to convert the Integer to
    >>>Long.
    >>>
    >>>Please ansewer these questions only if you are positive (I do not mean to
    >>>come off as rude but I need to be sure). Thanks very much in advance!

    >>
    >>
    >>


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

  5. #5
    NickHK
    Guest

    Re: Dim i,j,k As Integer

    Arne,
    If, for some reason, you want to limit your values to the max range of an
    Integer, you are still free to use them.
    However, since the underlying system is 32 bit, unless you are using a very
    old or very new system, you may as well forego any conversion and use the
    "native" numeric data type.
    Dim i as long
    for i=1 to 10
    ....etc

    NickHK

    "Arne Hegefors" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]...
    > Thanks alot for your help! Regarding the last question I had your cod
    > edoes
    > not answer the question. I am told that vb automatically converts Integer
    > to
    > Long. Thus, any variable declared as Integer automatically transforms into
    > Long implying that it can take any data that a variable declared as Long
    > can
    > do. The only difference is that the program needs to convert Integer to
    > Long
    > i.e. you do not notice the conversion it is just a waste of program memory
    > capacity. If anyone knows if this is true or not please let me know!
    > Thanks
    > alot in advance!
    >
    > "Bernie Deitrick" skrev:
    >
    >> Arne,
    >>
    >> With this:
    >> > Dim i,j,k As Integer

    >>
    >> i and j are variants, k is an integer.
    >>
    >> Use
    >>
    >> Dim i As Integer
    >> Dim j As Integer
    >> Dim k As Integer
    >>
    >> To check your last point, if this errors on the last line, then i is
    >> truly an integer
    >>
    >> Sub Test()
    >> Dim i As Integer
    >> Dim j As Long
    >> j = 654321
    >> j = 654321
    >> End Sub
    >>
    >>
    >> HTH,
    >> Bernie
    >> MS Excel MVP
    >>
    >>
    >> "Arne Hegefors" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > If you write:
    >> > Dim i,j,k As Integer
    >> >
    >> > does that mean that only one of the variables actually is declared as
    >> > an
    >> > Integer (i or k) and the are declared as Variant?
    >> >
    >> > Also is it true that Integer no longer really exists in VBA (at least
    >> > v.
    >> > 6.3)? I am told that an Integer is converted to a Long so it is better
    >> > to use
    >> > Long to begin with since the program does not have to convert the
    >> > Integer to
    >> > Long.
    >> >
    >> > Please ansewer these questions only if you are positive (I do not mean
    >> > to
    >> > come off as rude but I need to be sure). Thanks very much in advance!

    >>
    >>
    >>




+ 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