WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Variables and Parameters

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Variable Substitution Tips

Keywords: variable subtitution	 

Question:

I have a variable, say Z, that is a counter. In a routine I append the variable Z to a literal, say DRV, and store a value. The variable DRV1 has a value, the variable DRV2 has a value, etc. How can I get to the value of DRV1, DRV2, etc. in a For loop?

I've tried %%DRV%Z%%%, %%DRV%%Z%%, and several other combinations.

Answer:

Note: The use of arrays, introduced in WinBatch 2001, eliminates many of these and other %substitution% problems.

  1. It would be DRV%Z% if it would work, but you cannot use %substitution% variables in a for loop.
  2. Try this:
    temp=drv%z%
    for xx = 1 to temp
    next
    
    or maybe:
    for temp = 1 to 10
        drv%z% = temp
    next
    
    Depends on what you plan to do.

The rule is that you do not generally need (or want) to use %substitution% EXCEPT as a quick and dirty shortcut inside quoted strings.

DON'T using %substitution% to put the variable list data into your line. Where you have, for ex:

	"%listvariablename%"
just use:
	listvariablename
When you use the %'s around the variable name, it substitutes it right then and there, then looks at your new line and decides, oops, it is over 256 characters. So no go.

Question on 256K Limit with Parameters:

I've got a nifty little script that FTPs files dropped on the EXE to a remote server. Works like a charm, except there's a limit as to how many files I can drop on the EXE.

I believe it has to do with the fact that the files I'm dropping are way down deep in a sub-sub-sub-directory, and it's making each passed param(1-n) a very long string, and thus reaching the 256 char limit.

Does anyone know of a way to truncate params to just pass the filename? (so as to shortent the passed string).

Here's the script:

;here's the dest info
host="foo.bar.com"
userid="xxxx"
pswd="xxxx"
acct=""
destdirectory="/blah/blah/blah/"


;Here's the call of my ftp enging script 

g = "c:\winnt\profiles\admin\desktop\scripts\ftp_engine.wbc"
p1 = "%param1%"
p2 = "%param2%"
p3 = "%param3%"
p4 = "%param4%"
p5 = "%param5%"
p6 = "%param6%"
p7 = "%param7%"
p8 = "%param8%"
p9 = "%param9%"


Call(g, "%p1% %p2% %p3% %p4% %p5% %p6% %p7% %p8% %p9%") 

Answer:

Rule #7: Don't use %substitution% for anything useful.
        ;here's the dest info
	host="foo.bar.com"
	userid="xxxx"
	pswd="xxxx"
	acct=""
	destdirectory="/blah/blah/blah/"


	;here's the call of my ftp enging script 

        g = "c:\winnt\profiles\admin\desktop\scripts\ftp_engine.wbc"
        p1 = "%param1%"
        p2 = "%param2%"
        p3 = "%param3%"
        p4 = "%param4%"
        p5 = "%param5%"
        p6 = "%param6%"
        p7 = "%param7%"
        p8 = "%param8%"
        p9 = "%param9%"




        Call(g, strcat(p1," ",p2," ",p3," ",p4," ",p5," ",p6," ",p7," ",p8," ",p9)) 

Question (continued):

Thanks, have tried that, didn't help. The real problem is the location of the original files, their path is too long, I need to truncate just to the filename. Any thougts?

Answer:

Still getting the "line too long" message???? or its just not working now. To truncate...
	p1="%param1%"
	if p1!="" then p1=strcat(FileRoot(p1),".",FileExtension(p1)) 

Question on Substitution and For Loops:

Using WIL engine 2.3mbn... Run this code:
	===========================
	n = 1
	nMax = 9

	for nThisURL%n% = 1 to nMax
	next
===========================
When the For stmt is executed (for the 2nd time around I think) you get a WIL error: "3074 Expression continues past expected end" "1 to nMax"

If the iterator is nThisURL instead of nThisURL%n%, it works fine.

Answer:

Unwritten rule #1762.

Substitution not allowed in FOR statements.


Article ID:   W13924
Filename:   Variable Substitution Tips.txt
File Created: 2001:01:08:12:39:56
Last Updated: 2001:01:08:12:39:56