Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Option Base Declaring arrays with lower bound <> 0

Hi,

Option Base Declaring arrays with lower bound <> 0 is not in VB script only in VBA.

What does this mean and can any experts provide an example on this?
0
csharp_learner
Asked:
csharp_learner
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
In VBA, this code runs  

Option Explicit
'Option Base 1

Private Sub UserForm_Click()
Dim a(2)
Debug.Print LBound(a)
Debug.Print UBound(a)
Debug.Print a(0)
End Sub

Open in new window


But this (commenting out removed) will give an an error

Option Explicit
Option Base 1

Private Sub UserForm_Click()
Dim a(2)
Debug.Print LBound(a)
Debug.Print UBound(a)
Debug.Print a(0)
End Sub

Open in new window

0
 
csharp_learnerAuthor Commented:
so meaning Option Base Declaring arrays with lower bound <> 0 means that in only VB script, you can set the start of the array?
0
 
GrahamSkanRetiredCommented:
As you say, there is no Option Base statement in VBScript. Nor can you explicitly set the lower bound value. This works in VBA, but not in VBScript:

Dim a(0 To 2)

All arrays in VBScript have a lower bound of zero.


0
 
Bill PrewCommented:
It is true that all arrays have a lower bound of 0 in VBS, no way around that.  This always puzzled me since they chose to include the LBound() function, even though it will always return 0.  I guess just for code compatibility.

~bp
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now