tl;dr
Skip to PROBLEM below.
CONTEXT
In my algebraic math program a formula can be entered in the following forms (as lines of VB6 code). (Spaces within strings will be ignored):
formula1$ = "SUM (a,b,c)"
formula2$ = "SUM (x,y,z)"
formula3$ = "PRODUCT (a,x)"
formula4$ = "PRODUCT ((SUM (a,b,c)) , (SUM (x,y,z))) "
formula5$ = "PRODUCT (" + formula1$ +") , (" + formula2$ +")"
(a bit fiddly for the user, I know, but better on balance when dealing with long formulae).
The content of formula5$ is then identical to the content of formula4$.
It is useful to have a variable formula5_descr$ which when inspected/printed describes the specification of formula5$ thus:
debug.print formula5_descr$ ' --> "PRODUCT (" + formula1$ +") , (" + formula1$ +")"
The code for formula5_descr$ can be produced manually. However it is difficult to do and the user cannot be expected to do it.
I want to let the user enter a simpler form of code like:
formula5$ = "PRODUCT (formula1$ ) , ( formula2$ )"
Then the program could be modified to parse the formula string "PRODUCT (formula1$ ) , ( formula2$ )"and replace any string references (i.e. formula1$ and formula2$) by the contents of the relevant strings (i.e. SUM (a,b,c) and SUM (x,y,z)).
PROBLEM
And here is the problem - how in VB6 to replace the name of a string variable inside a string by the contents of that string variable?
(User Joel Coehoorn has pointed out that a process for this called string interpolation is available in newer languages, like VB14+, C#, javascript.)
Ideally there would be a function REVEAL() such that:
REVEAL("formula1$") --> "SUM (a,b,c)"
NOTE The fact that a solution exists for VBA in MS Access does not mean that the solution automatically works for VB6. They are similar but distinct languages and an installation of VB6 will not necessarily have the same components installed as for MS Access.
CallByNameto implement the REVEAL method, although it would require implementing the variables as Properties. This approach could also be used after you parse out the embedded formulas in formula5.CallByNameobjects must be in a form or class. So you would need to do a little restructuring of your app to make it work.CallByName()will have zero use. Totally agree with you. It is still unclear to me, however, even after re-reading the question and comments several times over, if the "user" in this case is entering their "code" at run-time in a Form somehow, or if they are actually modifying source code.