Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

Can I Use a String Variable to Specify the File Used by Save or Load in Xmath?

Primary Software: MATRIXx
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: I am trying to save Xmath variables to a file. I want to specify the filename as a string variable. I have tried the following:
v=[1:10];
filename="myfile.xmd";
dirname="c:\temp\";
savename="file="+dirname+filename

save savename


It won't give me any error but if I look inside the c:\temp folder there is no myfile.xmd file. However it does work if I do the following:
save file="c:\temp\myfile.xmd"

What is the difference between using a variable that stores the path and the name to a file and writing the whole path and file name in the SAVE or LOAD command?

Solution: The SAVE and LOAD commands accept both variables and the name of the file as a string. So how does SAVE know what is a variable and what is a file name.  From the help:
     The order of the SAVE syntax is not significant (for example, a
      filename can be listed before, after, or between variables).

So obviously it is not the order of the variables.  Rather what it is sensitive to is if it is a string constant or a variable.  In other words it can't tell the difference between savename containing a string that tells it to save it to a certain file, versus it being the same string but being a variable that is to be saved. In the first example above, what is happening is that save is saving value of the variable to file with a default name. It is saving the value of savename, instead of treating it as a string that contains the path.

The way to get the intended effect is to use a macro so that variable is evaluated first and then executed:
v=[1:10];
filename="myfile.xmd"
dirname="c:\temp\"
savename = """"+dirname+filename+""""

execute "save file="+savename+";"


Related Links:

Attachments:





Report Date: 11/07/2005
Last Updated: 11/08/2005
Document ID: 3R6HUHRY

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit