Hi
Im new to this Macro language and have a small question about the explicit option VAREXPLICIT=1 and working with arrays
Example:
GETFILELIST>C:\temp\*.txt,filenames
SEPARATE>%filenames%,;,TextFilenames
That gives the array TextFilenames.
Now I would like to make a loop oing through all theses files, something like:
Let>f=0
Repeat>f
Let>f=%f%+1
Let>Filename=TextFilenames_%f%
Until>f,%TextFilenames_count%
but the line Let>Filename=TextFilenames_%f% are the problem.
It result in the filename TextFilenames_1, TextFilenames_2 etc. and not the content of tha array.
Have tried with:
Let>Filename=%TextFilenames_%f%%
Let>Filename=%TextFilenames_[%f%]%
Let>Filename=%TextFilenames_%%f%
What am I doing wrong??
In hope of an answer
/Carsten Stiller
The option explicit and using arrays???
Moderators: JRL, Dorian (MJT support)
To do that you need to set VAREXPLICIT=0. You can always switch it back on afterwords if you need it for other stuff:
Let>VAREXPLICIT=0
Repeat>f
Let>f=%f%+1
Let>Filename=TextFilenames_%f%
Until>f,%TextFilenames_count%
Let>VAREXPLICIT=1
Let>VAREXPLICIT=0
Repeat>f
Let>f=%f%+1
Let>Filename=TextFilenames_%f%
Until>f,%TextFilenames_count%
Let>VAREXPLICIT=1
MJT Net Support
[email protected]
[email protected]
Thanks for the answer
Thanks for the answer
I would have liked to work with the explicit option on all the way and not switching it on and off on the way
I see this as a small/minor bug in the script language
I just turn the explicit option off for good
But thanks anyway
/Carsten Stiller



I would have liked to work with the explicit option on all the way and not switching it on and off on the way

I see this as a small/minor bug in the script language
I just turn the explicit option off for good

But thanks anyway
/Carsten Stiller
It's not a bug. If VAREXPLICIT is on then:
Let>var_1=fred
Let>a=1
Let>b=var_%a%
Results in b = "var_1". That's what VAREXPLICIT=1 says.
But you actually want b to be the value of the VARIABLE held in var_1 which is created by var_%a% = var_1 = fred. You don't want the explicit value of var_%a% = var_1 you want the value held in var_1. So you need it to continue to resolve. VAREXPLICIT stops further resolution which is sometimes handy, but in this case you need continual variable resolution.
So it's not a bug. It's what you asked it.
Let>var_1=fred
Let>a=1
Let>b=var_%a%
Results in b = "var_1". That's what VAREXPLICIT=1 says.
But you actually want b to be the value of the VARIABLE held in var_1 which is created by var_%a% = var_1 = fred. You don't want the explicit value of var_%a% = var_1 you want the value held in var_1. So you need it to continue to resolve. VAREXPLICIT stops further resolution which is sometimes handy, but in this case you need continual variable resolution.
So it's not a bug. It's what you asked it.
MJT Net Support
[email protected]
[email protected]
Thank you support for clearing this up.
This is the third thread that I'm aware of in the past week on this same subject. Carsten's posting is the first one to mention VAREXPLICIT which should have been the obvious solution in the other threads. Personnally I knew VAREXPLICIT existed, but had never taken the time to investigate its usefulness.
The workaround that that has been suggested here:
http://www.mjtnet.com/usergroup/viewtopic.php?t=2079
and here:
http://www.mjtnet.com/usergroup/viewtopic.php?t=2067
Is simple and only involves one extra line of code.
Perhaps if Carsten does not want to mess with VAREXPLICIT, one of these other posts holds the answer. (More obvious in the first one.)
Wrote this this morning to show myself how VAREXPLICIT works. Maybe it can clear up questions for others as well.
Let>k=0
repeat>k
Let>k=k+1
Let>var_%k%=apple
Let>VAREXPLICIT=1
WriteLn>c:\varexplicit_test.txt,wresult,This is the result of VAREXPLICIT=1
WriteLn>c:\varexplicit_test.txt,wresult,var_%k%
WriteLn>c:\varexplicit_test.txt,wresult,%CRLF%%CRLF%
Let>VAREXPLICIT=0
WriteLn>c:\varexplicit_test.txt,wresult,This is the result of VAREXPLICIT=0
WriteLn>c:\varexplicit_test.txt,wresult,var_%k%
WriteLn>c:\varexplicit_test.txt,wresult,%CRLF%%CRLF%
Until>k,3
Run>Notepad.exe c:\varexplicit_test.txt
Again, thank you support,
Dick
This is the third thread that I'm aware of in the past week on this same subject. Carsten's posting is the first one to mention VAREXPLICIT which should have been the obvious solution in the other threads. Personnally I knew VAREXPLICIT existed, but had never taken the time to investigate its usefulness.
The workaround that that has been suggested here:
http://www.mjtnet.com/usergroup/viewtopic.php?t=2079
and here:
http://www.mjtnet.com/usergroup/viewtopic.php?t=2067
Is simple and only involves one extra line of code.
Perhaps if Carsten does not want to mess with VAREXPLICIT, one of these other posts holds the answer. (More obvious in the first one.)
Wrote this this morning to show myself how VAREXPLICIT works. Maybe it can clear up questions for others as well.
Let>k=0
repeat>k
Let>k=k+1
Let>var_%k%=apple
Let>VAREXPLICIT=1
WriteLn>c:\varexplicit_test.txt,wresult,This is the result of VAREXPLICIT=1
WriteLn>c:\varexplicit_test.txt,wresult,var_%k%
WriteLn>c:\varexplicit_test.txt,wresult,%CRLF%%CRLF%
Let>VAREXPLICIT=0
WriteLn>c:\varexplicit_test.txt,wresult,This is the result of VAREXPLICIT=0
WriteLn>c:\varexplicit_test.txt,wresult,var_%k%
WriteLn>c:\varexplicit_test.txt,wresult,%CRLF%%CRLF%
Until>k,3
Run>Notepad.exe c:\varexplicit_test.txt
Again, thank you support,
Dick