Consulting

View Poll Results: Which one data type would you use for a columns array? Considering only 255 columns.

Voters
12. You may not vote on this poll
  • Integer

    1 8.33%
  • Long

    10 83.33%
  • Byte

    1 8.33%
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 30

Thread: Integer, Byte or Long for Columns?

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location

    Question Integer, Byte or Long for Columns?

    Hi,

    considering excel can manage 65,536 rows and 256 columns, would you agree that a good approach is to use Long data type when refering to rows AND Byte data type when refering to columns (even knowing that our array will never hold all the columns but all less one, as Byte data type can hold only up to 255) because of performance?
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  2. #2
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    While it may be technically correct, it's hard enought to explain the code without the reasoning behind the data type. Having read the Microsoft article, I think I'll just go for "long". It's shorter than Integer anyway!

  3. #3
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi MD,

    Ok, for rows I would go for "Long" too, my doubt is for columns. Integer, Long or Byte.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    I'm voting Long, (having not read the article,) just in case MS decides to add more columns one day!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Given the speed of my typing V the speed of my computer, I think on balance the less characters I type the better. so Columns are Long too.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi guys,

    you know what. Lets make it a poll on columns. What do you think? I am creating it.

    Well, so far we all have agreed on Long for rows.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  7. #7
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Why 255?? Anyways Long should be fastest (not that speed matters anymore).

    There is no other choice for Rows really. Long is the fastest for Columns as well.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi guys,

    well I proposed 255 columns to make it possible to use Byte and other that who uses that many columns?

    I dont think Long is faster than Byte, as it is faster than Integer and Byte requires less memory (only one byte). So why not use it?

    Check http://msdn.microsoft.com/library/de...rdatatypes.asp
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  9. #9
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Are you sure its faster than Byte? Remember that byte costs less memory.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  10. #10
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    I always try to work with the KISS principle, it's easier to just put long for both rather than having to think - 'now, was it long for columns and byte for rows or was that the other way round?'

    After reading the article & the other comments, I agree that any speed and/or memory saving is inconsequental with modern computers, so, Keep It Simple = "Long" for me from now on...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  11. #11
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    If you are writing code you should account for all posibilities. You assume that someone would not use the code for 256 columns so you use Byte, but Byte can only go up to 255 and in a loop only to 254 without error handling.

    You could use Integer for rows and just assume nobody would ever use more than 32,768 rows, but why limit your self.

    And even if Byte is technically faster, stop and think for a minute about what difference it actually makes. If you are looping 1000's of times we are still only talking about a small fraction of a second difference.

  12. #12
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Gee,ok Jake, you won again. You right, I choose Long too. Thanks guys.

    Sorry, for insisting in it but this way I just have learned more. I have readen that article from MS and got in doubt, but now thanks for the support from all of you my doubt is gone. I understood Long is better.

    Thanks guys.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  13. #13
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    Quote Originally Posted by Paleo
    Hi guys,

    well I proposed 255 columns to make it possible to use Byte and other that who uses that many columns?

    I dont think Long is faster than Byte, as it is faster than Integer and Byte requires less memory (only one byte). So why not use it?

    Check http://msdn.microsoft.com/library/de...rdatatypes.asp
    Using the Byte data type is NOT faster then the Long.
    Dermot balsome has a workbook displaying this here ....

    http://www.webace.com.au/~balson/InsaneExcel/Other.htm

    Speed of different variable types (new)

    On tests I done long was faster then integer by around 12% and faster then Byte by a whopping 44%. I would have expected this as there is less conversion from Integer to long as from Byte to long. VBA Op codes are 32bit data types so the less conversion the faster the op.
    Kind Regards,
    Ivan F Moala From the City of Sails

  14. #14
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Ivan,

    well looks like I was VERY mistaken on that... Anyway now I have learned more things on it.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  15. #15
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi Carlos,

    I realise that this thread is marked as 'Solved' but I thought I'd add my 2p worth anyway

    Just based upon experience I would have suggested that Longs would have been quicker (and this has been proved to be the case in the responses detailed above).

    However, I think the key point here has been made by Jake - for the sake of a fraction of a second in most cases, performance isn't really an important factor. It's far more important to concentrate on the integrity and maintainability of your code - assume that users will do things that you have asked them not to. At the end of the day we should try to use whatever data type is most appropriate for the scenario, not necessarily which one will be the fastest.

  16. #16
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Richie,

    agreed on that with you. My point was Byte is less memory consuming not necessarily faster, so you could work with bigger workbooks on weaker computers, but I think you all right. Long is better by being faster and most appropriate for the scenario.

    Thanks guys.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  17. #17
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Quote Originally Posted by Richie(UK)
    assume that users will do things that you have asked them not to.
    Now, come on!!
    When has that EVER happened to anybody?? Users ALWAYS do exactly what you tell them!!

    :rofl :rofl :rofl :rofl
    ~Anne Troy

  18. #18
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Quote Originally Posted by Dreamboat
    Now, come on!!
    When has that EVER happened to anybody?? Users ALWAYS do exactly what you tell them!!

    :rofl :rofl :rofl :rofl
    Users, our nightmare :rofl
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  19. #19
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Paleo
    Gee,ok Jake, you won again. You right, I choose Long too. Thanks guys.

    Sorry, for insisting in it but this way I just have learned more. I have readen that article from MS and got in doubt, but now thanks for the support from all of you my doubt is gone. I understood Long is better.

    Thanks guys.
    long is faster than either integer or byte, not to mention that the word objects/properties use longs for column numbers, so why cause needless conversions.

  20. #20
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Howard,

    it was just a memory issue, but thats okay, I have learned I was wrong, even if we dont feel the performance improvement the impact on memory can be less dangerous than what a user can do...
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

Posting Permissions

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