DPlot Forum Index DPlot
http://www.dplot.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FileSaveAs function syntax error

 
Post new topic   Reply to topic    DPlot Forum Index -> Excel
View previous topic :: View next topic  
Author Message
eha



Joined: 07 Jul 2010
Posts: 2

PostPosted: Wed Jul 07, 2010 3:49 pm    Post subject: FileSaveAs function syntax error Reply with quote

I'm using DDE to control DPlot from Excel, and am trying to save a 3D contour plot I have DPlot generate from Excel data. The problem I have is that when I try to execute the macro it gives me a syntax error in the FileSaveAs command. Apparently it expects the open quotation for the file name to be the terminator for the command. However, as far as I can tell I'm following the definition of the FileSaveAs command per the DPlot manual, and everything BUT the FileSaveAs command works fine. Any idea what I am doing wrong?

Here is the example from the manual:
FileSaveAs(1,"c:\mydata\|TITLE1|.grf")


Here is an excerpt from my macro:

For row = 1 To nrows
DDEExecute Channel, "[XYZEx(0,1," + Str$(Sel.Cells(row, 1)) + "," + Str$(Sel.Cells(row, 2)) + "," + Str$(Sel.Cells(row, 3)) + ")]"
Next row

Application.Wait (Now + TimeValue("0:00:03"))
'Adds a delay before displaying the plot
DDEExecute Channel, "[XYZRegen()][ViewRedraw()]"
'Displays the plot
DDEExecute Channel, "[ContourLevels(41,0,1)]"
'Sets contour levels
DDEExecute Channel, "[FileSaveAs(1,"d:\|TITLE1|.grf")]"

DDETerminate Channel

End Sub
Back to top
View user's profile Send private message
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2290
Location: Vicksburg, Mississippi

PostPosted: Wed Jul 07, 2010 5:15 pm    Post subject: Reply with quote

Does your graph have a first title line? If not, that's the problem (though the error message could be a bit more helpful).

Oh wait... that isn't it, and you meant a syntax error produced by Excel rather than DPlot. It's the quotation marks. The entire command is a character string and so must be surrounded with quotation marks. Character string arguments also must be surrounded with quotation marks, but this:

Code:
DDEExecute Channel, "[FileSaveAs(1,"d:\|TITLE1|.grf")]"


is interpreted as the command

"[FileSaveAs(1,"

followed by

d:\|TITLE1|.grf")]"

which Excel sees as nonsense. The easiest way to handle this in VB/VBA, when the string is a constant as it is in this case, is to double-up on the quotes, as in:

Code:
DDEExecute Channel, "[FileSaveAs(1,""d:\|TITLE1|.grf"")]"


If instead your character string argument is a variable, as in

Code:
Dim arg as string

arg = "d:\|TITLE1|.grf"


... then you'd need to do something like this:

Code:
DDEExecute Channel, "[FileSaveAs(1," & chr$(34) & arg & chr$(34) & ")]"


In my defense, the example you cite is for the DPlot macro editor, where the quotation mark thing isn't an issue. And it is explained in the parent topic, but I need to do a better job explaining this in each of the many dozens of topics for commands that include character string arguments.

I'm curious about why you want to use Excel's DDEExecute, etc. rather than the Add-In commands (DPlot_Command in this case). With the latter you'll get better error diagnostics.
_________________
David Hyde
support@dplot.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    DPlot Forum Index -> Excel All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group