Results 1 to 4 of 4

Thread: Confusing Piece of VBA Code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2004
    Location
    Right here
    Posts
    275

    Confusing Piece of VBA Code

    I'm trying to come to grips with someone else's spreadsheet and am having trouble with some of the VBA code. Here is an example of it (the original is similar to this just a lot longer):

    Code:
    Public Sub Set_Z2()
      Z2(1, 1, 0) = 5
      Z2(1, 1, 1) = 0.62
      Z2(1, 1, 2) = 0.79
      Z2(1, 1, 3) = 0.89
      Z2(1, 1, 4) = 0.97
      Z2(1, 1, 5) = 1.02
     End Sub
    The part I don't understand is the bit in brackets. "Z2" is (I'm pretty sure) supposed to be a variable but why is it followed by 3 numbers in brackets?

    Cheers
    -Rob
    http://www.sudsolutions.com

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Confusing Piece of VBA Code

    Its a 3 dimensional array. How is it defined - dynamic bounds or is it a static declaration of elements? What type double?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2004
    Location
    Right here
    Posts
    275

    Re: Confusing Piece of VBA Code

    Code:
    Public Z2(1 To 2, 1 To 12, 0 To 5) As Single
    There's also this bit:

    Code:
    Public summer(100) As Single
    Public Winter(100) As Single
    So I take it that means that this declares two variables (summer and winter) as Single variables but also as arrays with 100 (or 101?) elements?
    http://www.sudsolutions.com

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Confusing Piece of VBA Code

    Yes, 101 unless you have an Option Base 1 statement at the top of the class/module.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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