PerfectScript Journal
 

January 1998 Macro Q&A 

Using filenames stored as variables  
Q. I need a macro to save a document. The filename is stored in a variable called vFilename, but the variable does not include the path. When I use the command:
 FileSave("c:\myfiles\vFilename.wpd")                  

my file is saved with that exact name. How can I get the file saved correctly?  

A. Strings must be surrounded by quotation marks within macro commands, but variables cannot be. If you place quote marks around a variable name it is treated as a string. This is what is happening to you.

Instead, you need to concatenate the path string and the variable together to get the desired result. You can use plus symbols to concatenate, as shown below.

FileSave("c:\myfiles\"+vFilename+".wpd")
                   

FORNEXT vs. FOR 
Q. What's the difference between the FORNEXT and the FOR commands?

A. Basicaly, the syntax. Both commands will give you the same result. It is just a matter of personal preference for which one you'll use the most.

A FORNEXT command will look like this:
FORNEXT(x; 1; 10; 1)
    // the commands to be invoked
ENDFOR

The equivalent FOR command looks like this:
FOR(x; 1; x<10; x+1)
     // the commands to be invoked
ENDFOR

The first and second parameters of the FOR command are identical to the same parameters in the FORNEXT command.

The third parameter of the FOR command is actually an expression. The FOR loop will be invoked until that expression is false.

The fourth parameter is also an expression that must increment a value. You can't put just a 1 -- you must actually specify the variable to be incremented. (This is handy if you want to increment a value other than x.)

I prefer the FORNEXT because it is more straightforward. You just drop in your start and stop values, and an increment if you choose and all is well. With a FOR command you must also supply two correct expressions in order to get the FOR command to work properly.

Both have their advantages and disadvantages. Just use the one you are most comfortable with.


If you have a question about PerfectScript or WordPerfect for DOS macros, you may submit it may emailing me. Include the words PSJournal-Question in the Subject line.

Sorry, I can't publish or acknowledge all submissions. All submissions become the property of PerfectScript Journal.

 

Copyright Notice: The information included in the PerfectScript Journal is protected by US Copyright. The author grants you the right to use the routines in your own macros as needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No representations are made regarding the fitness of this information for your   particular purpose, or for your ability or inability to use the information. You   are advised to make backups of all relevant files before implementing any suggestion  or technique.
© Copyright 1998 by J. Jeppson.