Exporting A Set Works Manually But Not In A Sequence


RBlabs

Recommended Posts

Hi Guru,

 

When I run RB_Export by right clicking this export set in the Workspace and selecting "begin export set" it works just fine. But when I try to do the same thing in the sequence below it produces a .csv file with no data, just a header. Please what am I doing wrong?

 

 

if (component.EditBox_Export_FileName.strContents == "")
   system.MessageBox("Pleae enter a FileName to Export to in the box just above. You may use the <DIR> button to select the last saved filename, then press <+Copy> to use that name incremented by one. ")
else
   if (system.MessageBox("Export Graph data set to .csv file? Note: To export a subset of data points select the starting point with MarkerA [and optionally the ending point with MarkerB]." ,"OKCancel") == "OK")
      Export.RB_Export.strFileName = strExportPath + strExportFileName
      Try
         Export.RB_Export.Start()
         Export.RB_Export.Stop()
      Catch()
         System.ErrorMessage(strLastError)
         ?StrLastError
      endcatch
      strExportLastFileName = StrExportFileName
      component.EditBox_Export_Last_FileName.strContents = strExportFileName
      StrExportFileName = ""
      component.EditBox_Export_FileName.strContents = ""
   endif
endif

Link to comment
Share on other sites

There's no reason to stop the export set.  Let it run.  It will do so quite quickly, then stop on its own.  This is different than logging sets which stay running continuously.  In fact that's really the difference in the two.  Logging sets are designed to run all the time and log data as it comes in.  Export sets are designed to run and stop, processing existing data only.

 

So, remove the line:

 

Export.RB_Export.Stop()

Link to comment
Share on other sites

Thanks. Works. So easy!

 

One more question please. The try/catch code does not seem pick up the error C1013 that I get when the file I am writing to is already open, in Excel, for example. What file function is available to test the file beforehand?

Link to comment
Share on other sites

Export sets, like logging sets, run in a separate thread, so your script triggers the export set then moves on.  Because of this, it can't catch an errors in the export set.  For total control you should instead use the File. functions, but you can probably get away with checking if you can write to the file by doing this:

try
   private handle = file.open(Export.RB_Export.strFileName, 0, 1, 1, 0)
   file.close(handle)
   Export.RB_Export.Start()
catch()
   ? "file in use"
endcatch

That simply opens the file for writing (appending), then immediately closes it.  The open will fail if the file is locked by Excel.  If it doesn't fail, you should be able to safely run the export set.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.