+ Reply to Thread
Results 1 to 3 of 3

Thread: Variant vs Array

  1. #1
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Variant vs Array

    Quick question, for the below, the second loop is faster than the first.

    Is this due to the overhead associated with the Variant type? - Granted it's not much slower though

    Sub DirectArray()
    Dim arr(1 To 10000) As Long
    Dim rngArr
    Dim x As Long
    Dim y As Long
    Dim t As Class1
    
    
    For x = 1 To 10000
        arr(x) = x
    Next x
    
    
    rngArr = Application.Transpose(Sheet2.Range("A1:A10000").Value)
    
    
    Set t = New Class1
    With t
        .StartCounter
        For x = 1 To 10000
            y = rngArr(x) + y
        Next x
        Debug.Print "rngArr: " & .TimeElapsed
        
        y = 0
        
        .StartCounter
        For x = 1 To 10000
            y = arr(x) + y
        Next x
        Debug.Print "arr: " & .TimeElapsed
    End With
    End Sub
    Last edited by Kyle123; 01-26-2012 at 08:50 AM.
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  2. #2
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Variant vs Array

    Yes - you are having to coerce data types to do the arithmetic.
    Good luck.

  3. #3
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Variant vs Array

    Cheers, that's what I thought
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

+ 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.2.0