excel - How to programmatically determine current setting for Option Base in VBA -


how can programmatically determine current setting option base in vba? option base can set 0 or 1, , determines whether array indices start @ 0 or 1 (see msdn).

however, can't see easy way find out current setting is. hoping there might option() function pass parameter to, like:

debug.print option("base") 

and tell me, doesn't seem there.

while agree @jonsharpe if you're using lbound(arr) , ubound(arr), don't need know @ runtime, think it's interesting question.

first, example of looping through array.

for = lbound(arr) ubound(arr)     ' next 

now, in order exactly asked, you'll need access use vbide library. otherwise known "microsoft visual basic applications extensibility" library. provides access ide , code with-in it. can use discover if option base 1 has been declared. don't recommend trying @ runtime though. more useful kind of static code analysis during development.

first, you'll need add reference library , grant code access itself. once you've done that, following code should like.

public sub findoptionbase1declarations()      dim startline long     startline = 1      dim startcol long     startcol = 1      dim endline long     endline = 1 ' 1 represents last line of module      dim endcol long     endcol = 1 ' endline, 1 designates last col      dim module codemodule     dim component vbcomponent     each component in application.vbe.activevbproject.vbcomponents ' substitute vbproject         set module = component.codemodule          if module.find("option base 1", startline, startcol, endline, endcol, wholeword:=true, matchcase:=true, patternsearch:=false)              debug.print "option base 1 turned on in module " & component.name              ' variables passed ref, tell exact location of statement             debug.print "startline: " & startline             debug.print "endline: " & endline             debug.print "startcol: " & startcol             debug.print "endcol: " & endcol              ' means have reset them before in next module             startline = 1             startcol = 1             endline = 1             endcol = 1         end if      next   end sub 

see codemodule.find documentation more information.


if using add-in option, @mat'smug , i's open source project rubberduck has code inspection show instances of throughout active project.

option base 1 code inspection

see more information on particular inspection.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -