vba - Access variables and their names from the current scope -


is possible to:

  1. access list of variables in vba runtime environment?
  2. access name of variable vba?

example:

function v2s(str string) string     each variable in variables         dim integer         = 1 10             v2s = replace(v2s,"%" & variable.name & "%", variable.value)         next     next end function 

example use case:

dim skycolor string skycolor = "green" debug.print v2s("the sky %skycolor% today!") 

there application can send commands via com object , wish along lines of:

dim integer = 1 mi.eval("numtables()")     mi = getobject(,"mapinfo.application.x64")     debug.print mi.eval(v2s("tableinfo(%i%,1)")) ' print name of table next 

the above looks cleaner than:

dim integer = 1 mi.eval("numtables()")     mi = getobject(,"mapinfo.application.x64")     debug.print mi.eval(v2s("tableinfo(" & & ",1)")) ' print name of table next 

but of course if possible want general may difficult...

for own use case this pretty good.

however still isn't readable. option. it's more readable more cluttered:

sub main()     dim vars object, mystring string     set vars = createobject("scripting.dictionary")     vars.add "var1","val1"     vars.add "var2","val2"     '...     mystring = r("var1: #{var1} , var2: #{var2}", vars) end sub  function r(byval s string, byval o object) string     each key in o.keys         s = replace(s,"#{" & key & "}",o.item(key))     next     r = s end function 

i wish string interpolation functionality existed default in vba.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -