Page 1 of 1

Can you call a .set from VBA?

Posted: Sun Apr 25, 2010 10:43 am
by Phillip Mathis
David,

I'm new to VBA programming and just learned how to call the xyyy sub procedure. We just finished testing and have 1000+ csv files that have to be plotted. It would be helpful if the process could be further automated by calling the .set function within Dplot. This may not be possible since the .set file does not reside within the dplot library, but any recommendations would be appreciated.

Thanks,

Phil Mathis

Posted: Sun Apr 25, 2010 10:54 am
by DPlotAdmin

Code: Select all

    Dim doc As Long
    Dim ret As Long
    .
    .
    Call XYXY
    doc = DPlotGetActiveDocument()
    If doc > 0 Then
        ret = DPlot_Command(doc, "[GetPreferences(""filename.set"")]")
    End If
But if you're always using the same settings file and can remember to leave the first plot open, you might find it more convenient to check "Use settings for current plot" on the Add-In Options command.

Posted: Wed Apr 28, 2010 8:38 pm
by Phillip Mathis
David, thanks for the help. The code errors out with doc =DplotGetActiveDocument. I'll look through and see if I can't debug and find where i'm making an error. Thanks again,

Phil

Posted: Wed Apr 28, 2010 10:50 pm
by DPlotAdmin
My best guess is you're using an older version of the Add-In, in which DPlotGetActiveDocument is marked "Private" - that is, it is inaccessible from other modules. To change it to "Public" open VBA and click on the + sign next to "dplotlib (dplotlib.xla)" in the left pane. (If you are prompted for a password, use "dplot" w/o the quotes. Then click next to Modules, and double-click on DPlotData. Search for DPlotGetActiveDocument and change

Private Function DPlotGetActiveDocument() As Long

to

Public Function DPlotGetActiveDocument() As Long

Posted: Thu Apr 29, 2010 8:25 pm
by Phillip Mathis
Changing from Private to Public worked. Thanks! Can you explain why the double quotes are necessary in the arguement for GetPreferences? Newbie question.

Posted: Thu Apr 29, 2010 8:32 pm
by DPlotAdmin
Yes, and the same applies to any character string arguments to DPlot_Command commands. The entire command is a character string and has another character string embedded. VBA would see

DPlot_Command(doc, "[GetPreferences("filename.set")]")

as

DPlot_Command(doc, "[GetPreferences("

followed by nonsense and report a syntax error. The doubled quotes are the same as (but much easier than):

DPlot_Command(doc, "[GetPreferences(" & char(34) & "filename.set" & char(34) & ")]")