Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) Export Spec not loading (Read 2038 times)
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Export Spec not loading
May 11th, 2010 at 9:29pm
Print Post Print Post  
Am in the middle of conversion from Q&A, still using Q&A database files with Sesame for a while.
Need to "Copy Record" from Sesame into Q&A, so I using Export from Sesame to Q&A, and using Q&A Import followed by Mass Update to fix the differences.

Using Sesame 2.5.1 .....

Record set in Sesame for records with Export Date field empty.
Sorted by Record number.
Export to Sesame.rec file.
Mark the Export Date field with today's date.

Problem is that the Export Spec is not loading.  The Spec does exist.  Can manually Retrieve Records, Open Spec Manager, Export, and the file comes out perfect.  But cannot get to work with RecordSet method, don't want to open the form, just run from a Menu Command button.

Here is the code with some WriteLn and MsgBox commands that won't be in final code.
===================
Code
Select All
var vTemp as Int
var vFormName as String
var vPath as String
var vExportFile as String
var vRSHandle as Int
var vRSRecordCount as Int
var vLoop as Int

vFormName = "frmWarehouse"
// Next path is for SS testing
vPath = "C:\Sesame2\Data\Company\InProcess\"
// Next path is for Company, same folder as location of 0010lum.dtf database.
// vPath = "G:\Apps\Qadata\Database\"
vExportFile = "Sesame.rec"
// =====================================

// From sbasic_include.sbas: //SEARCH_MODE_AND = 0 // SEARCH_SYNTAX_QA = 2

vRSHandle = @XResultSetSearch(@FN,"tblWarehouse",0,2,"!datExportDate==")
IF(vRSHandle > -1) Then {
	XResultSetSort(vRSHandle, "numRecord:1")
	vRSRecordCount = @XResultSetTotal(vRSHandle)
	IF @ASKUSER("ARE YOU SURE YOU", "WANT TO COPY " + vRSRecordCount + " RECORDS","INTO Q&A?") = "YES" THEN {

		// Delete old export file.
		If FileExists(vPath + vExportFile) Then {
			FileDelete(vPath + vExportFile)
			}

		vTemp = @LoadExportSpec("COPY TO Q&A")
		If vTemp = 1 Then {
			@MSGBOX("Spec was loaded successfully","","")
			} ELSE {
			@MSGBOX("Spec did NOT load","vTemp value is: " + vTemp,"","")
			}

		// Export the data to new export file.
		RunExportSpec(vPath + vExportFile,",","",0,0,0,0,0,0,0,0)

		If FileExists (vPath + vExportFile) Then {
			@MSGBOX(vRSRecordCount + " records have been exported","to " + vPath + vExportFile,"")

			// Enter the date into Export Date field for each record.
			For vLoop = 1 to vRSRecordCount
				XResultSetCurrentPosition(vRSHandle, vLoop)
				// TMP Prevent field update until export is good.....
                                // vTemp XResultSetValue(vRSHandle, "datExportDate", @STR(@Date))
				WriteLn(@Str(vLoop) + " Of " + @Str(vRSRecordCount) + " records have been date stamped")
			Next

			} Else {
			@MSGBOX(vRSRecordCount + " records have NOT been exported","to " + vPath + vExportFile,"Call Bob for help")
			}

		XResultSetClose(vRSHandle)
		}
	}
 


The result of vTemp = 0 where @LoadExportSpec("COPY TO Q&A") happens.  I thought perhaps the "&" was a problem, so I doubled it to "COPY TO Q&&A" and eliminated it as "COPY TO QA". No change, still does not load.

« Last Edit: May 12th, 2010 at 7:36pm by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Export Spec not loading
Reply #1 - May 12th, 2010 at 3:47am
Print Post Print Post  
I have also tried two other variations, total of three now:

Including sbasic_include.sbas:
vTemp = @SpecCommand(Spec_Operation_Load, Spec_Type_Export, "COPY TO Q&A")

Excluding sbasic_include.sbas:
vTemp = @SpecCommand(0, 3, "COPY TO Q&A")

and this original one:
vTemp = @LoadExportSpec("COPY TO Q&A")

In all cases vTemp comes back as "0"

I guess the next step is to create a few other Export Specs and see if they all behave the same way.....
Made two other Export Specs, none of them are loading either.  They all load OK manually.  Maybe I need to do something different because it is a ResultSet, not a form result.  Will have to review ResultSet commands.  That is sounding like a good idea, but probably only because I have tried all the bad ones.. Roll Eyes

Running out of things to try ..... Cry Cry
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: Export Spec not loading
Reply #2 - May 12th, 2010 at 1:07pm
Print Post Print Post  
Hello Bob!
i thank you must run  a retrieve as:

vStr = @SpecCommand(SPEC_OPERATION_LOAD, SPEC_TYPE_RETRIEVE, "COPY TO Q&A")

// Runs the currently loaded retrieve spec
vStr = @SpecCommand(SPEC_OPERATION_RUN, SPEC_TYPE_RETRIEVE, "")


vRSHandle = @XResultSetSearch(@FN,"tblWarehouse",0,2,"!datExportDate==")
IF(vRSHandle > -1) Then {.....
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Export Spec not loading
Reply #3 - May 12th, 2010 at 2:10pm
Print Post Print Post  
I have a result set of five sorted records when I run this:

Code
Select All
vRSHandle = @XResultSetSearch(@FN,"tblWarehouse",0,2,"!datExportDate==")
IF(vRSHandle > -1) Then {
	XResultSetSort(vRSHandle, "numRecord:1")
        vRSRecordCount = @XResultSetTotal(vRSHandle) 



The five records have no value in the field datExportDate, and are sorted in ascending order by the field numRecord.  But I will try adding those lines to test your idea, thanks.

---------------
OK, I did try your suggestion.  I had a Retrieve Spec defined as "TO BE EXPORTED".  But I ended up with no different result.  Yes the include line is there for the sbasic file.  I also tried including the full path to that file, no change.

Code
Select All
vInt = @SpecCommand(SPEC_OPERATION_LOAD, SPEC_TYPE_RETRIEVE, "TO BE EXPORTED")
WriteLn("Load Retrieve = " + vInt)

// Runs the currently loaded retrieve spec
vInt = @SpecCommand(SPEC_OPERATION_RUN, SPEC_TYPE_RETRIEVE, "")
WriteLn("Run Retrieve = " + vInt) 



I inserted a WriteLn and got back values of 0 on both lines, probably because no form is loaded.  
The programming continues with same result as before, not loading ExportSpec.  Again, I don't think those two lines are needed, the following XResultSetSearch does return the records I want to process, so I am removing these lines.


  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Export Spec not loading
Reply #4 - May 12th, 2010 at 3:24pm
Print Post Print Post  
Hello Bob,

The Spec commands need the Form to be open in order for the them to work. You can do it all using XResultSet, you'll have to write the export file in programming by looping through the records and then looping through the fields you wanna export, writing them out as you go.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Export Spec not loading
Reply #5 - May 12th, 2010 at 4:03pm
Print Post Print Post  
Quote:
The Spec commands need the Form to be open in order for the them to work.

That is what I suspected when I saw the earlier suggestion.  My original and existing code does not include the SpecCommands.

Back to my original code stripped of non essentials:
Code
Select All
vRSHandle = @XResultSetSearch(@FN,"tblWarehouse",0,2,"!datExportDate==")
IF(vRSHandle > -1) Then {
	XResultSetSort(vRSHandle, "numRecord:1")
	vRSRecordCount = @XResultSetTotal(vRSHandle)
	vTemp = @LoadExportSpec("COPY TO Q&A")
	RunExportSpec(vPath + vExportFile,",","",0,0,0,0,0,0,0,0)
        } 

 
Why does @LoadExportSpec("COPY TO Q&A") not load when a Result Set exists?  I don't think a form needs to be opened for that, it is not a SpecCommand

If I need to export from a ResultSet you are saying I must do something like Open a File Handle, Start the loop, and for each record, Write the value of 25+ fields, one programming line for each field, one at a time to the file with delimiters, then close the file?  

I cannot use a Saved Export Spec?  If I want to Add/Delete a field value, I need to change the hard code vs. changing the content of a Saved Export Spec?  That does not sound correct.
Please tell me I am missing something.  
There must be a way to loop through the 25+ fields of the ExportSpec, in the Spec order, to write them out so I do not need to hard code the field names to write them out.  I seem to recall a command that detailed some specs, but I can't seem to locate it.

A sample would be appreciated.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Export Spec not loading
Reply #6 - May 12th, 2010 at 4:31pm
Print Post Print Post  
Bob_Hansen wrote on May 12th, 2010 at 4:03pm:
Why does @LoadExportSpec("COPY TO Q&A") not load when a Result Set exists?  I don't think a form needs to be opened for that, it is not a SpecCommand

SpecCommand is a replacement for all the individual commands that operate on different kinds of specs. Specs are always attached to Forms, not to ResultSets. Specs are client-side tools and need a Form.

Quote:
If I need to export from a ResultSet you are saying I must do something like Open a File Handle, Start the loop, and for each record, Write the value of 25+ fields, one programming line for each field, one at a time to the file with delimiters, then close the file?

Yes. You probably already have a number of examples of this, since you are likely doing something similar when you automate mailmerges and suchlike. 

Quote:
I cannot use a Saved Export Spec?  If I want to Add/Delete a field value, I need to change the hard code vs. changing the content of a Saved Export Spec?  That does not sound correct.

No, you just can't use a saved export spec to operate on an XResultSet in code. Specs operate on Forms.

Quote:
Please tell me I am missing something.

OK, you're missing something.  Wink
 
Quote:
There must be a way to loop through the 25+ fields of the ExportSpec, in the Spec order, to write them out so I do not need to hard code the field names to write them out.  I seem to recall a command that detailed some specs, but I can't seem to locate it.

@SpecCommand can do this with the SPEC_OPERATION_VIEW operation.

Quote:
A sample would be appreciated.

OK. I went into Customers, chose Set All on the Export Spec, saved it as EMF Test, and ran the following Mass Update to get the list of fields.

Code
Select All
#include "sbasic_include.sbas"

var vSpec as String

	vSpec = @SpecCommand(SPEC_OPERATION_VIEW, SPEC_TYPE_EXPORT, "EMF Test")
	vSpec = @Replace(vSpec, "=Open0", "")
	WriteLn(vSpec) 



The following appeared in the WriteLn window:
Code
Select All
KEY;Active;First;MI;Last;Company;Add1;Add2;City;State;ZIP;Phone;Email;Position;Interests;Numerical;Credit_Limit;Date_Entered;Time_Field 



Edited:
Also: Be aware that your Export Spec uses element names and the XResultSet uses field names. Using the Export Spec this way won't work as is if they don't match. You'd have to add another loop that translates the element names to their bound field names.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Export Spec not loading
Reply #7 - May 12th, 2010 at 5:56pm
Print Post Print Post  
Quote:
OK, you're missing something.   Wink

Finally, something that explains it all!  That's what I wanted to hear!  Best support in the world.
==========================================

Before I read your great response, I remembered doing something similar for mail merge, just as you noted....

I have one variable that is a double quote on text, comma delimited, string of the merge field values.  Then all I do is write the single variable.  All that code was usually activated from a button on the individual record.  

In this case I want to run from a menu command button, no forms to be opened.  So I can just loop, create the export variable for each record, append the variables to the export file, and close loop after last record.  There will not be a need to write 25+lines hard coded.  And I could also use a text file pulled in for the variable string so the text file can be modified as needed, but the code will be fixed.

And thanks for finding that missing command:
@SpecCommand(SPEC_OPERATION_VIEW, SPEC_TYPE_EXPORT, "COPY TO Q&A")  I knew it was there someplace.

Thanks for the ideas.  Sorry for the interruptions.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Export Spec not loading
Reply #8 - May 12th, 2010 at 8:03pm
Print Post Print Post  
Thought that I had it but still missing something.  Here is the final code I thought was going to work

Code
Select All
vRSHandle = @XResultSetSearch(@FN,"tblWarehouse",0,2,"!datExportDate==")
IF(vRSHandle > -1) Then {
	XResultSetSort(vRSHandle, "numRecord:1")
	vRSRecordCount = @XResultSetTotal(vRSHandle)
	IF @ASKUSER("ARE YOU SURE YOU", "WANT TO COPY " + vRSRecordCount + " RECORDS","INTO Q&A?") = "YES" THEN {

		// Delete old export file.
		If FileExists(vPath + vExportFile) Then {
			FileDelete(vPath + vExportFile)
			}

		// Loop through each record, appending field values to export file.
		For vLoop = 1 to vRSRecordCount
			XResultSetCurrentPosition(vRSHandle, vLoop)
			vExportData += @CHR(34)+@MID(datDate,6,5)+"/"+@LEFT(datDate,4)+@CHR(34)+","+@CHR(34)
			vExportData += txtSpecies+@CHR(34)+","+@CHR(34)
			vExportData += txtGrade+@CHR(34)+","+@CHR(34)
			vExportData += txtGradedBy+@CHR(34)+","+@CHR(34)
			vExportData += txtLocation+@CHR(34)+","+@CHR(34)
                        vExportData += txtDisposition+@CHR(34)+","+@CHR(34)
			vExportData += @STR(numFT6)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(numFT8)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT10)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT12)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT14)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT16)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT3)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT4)+@CHR(34)+","+@CHR(34)
	 		vExportData += @STR(FT5)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT7)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT18)+@CHR(34)+","+@CHR(34)
			vExportData += @STR(FT20)   +@CHR(34)+","+@CHR(34)
			vExportData += @STR(Tally)  +@CHR(34)+","+@CHR(34)
			vExportData += @STR(Footage)+@CHR(34)+","+@CHR(34)
			vExportData += Description  +@CHR(34)+","+@CHR(34)+ "*" +    @STR(TagNumber) + "*" + @CHR(34)+","+@CHR(34)
			vExportData += @STR(TagNumber)+@CHR(34)

			// Create export file.
			vFileHandle = FileOpen(vPath + vExportFile)
			If vFileHandle >= 0 {
				fileSeek(vFileHandle, fileSize(vFileHandle))
				fileWrite(vFileHandle, vExportData)
				FileWrite(vFileHandle, vCrLf)
				fileClose(vFileHandle)
				}

			// Mark record as exported
			XResultSetValue(vRSHandle, "datExportDate", @STR(@Date))
			WriteLn(@Str(vLoop) + " Of " + @Str(vRSRecordCount) + " records have been exported and date stamped")
		NEXT
                ...........  



But the compiler crashes on vExportData = lines.
All the referenced names are FIELD names, no form is open, I am operating with a RecordSet.
I tried changing to ELEMENT names, no form opened, only one form exists in that database.

Simple test lines, mixing field and element names all fail....All of the first four lines are flagged by the Editor.  the fifth line, of course, is OK and gets written out to the file.
Code
Select All
vExportData += txtSpecies
vExportData += Species
vExportData += txtLocation
vExportData += Location
vExportData += "One" + "Two" + "Three" 



I must have missed something again re collecting the data from the fields in the record set result records
     
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Export Spec not loading
Reply #9 - May 12th, 2010 at 9:07pm
Print Post Print Post  
You need to use @XResultSetValue() to get the data from the fields.

ex:
Code
Select All
vExportData += @XResultSetValue(vRSHandle, "txtSpecies")
vExportData += @XResultSetValue(vRSHandle, "txtLocation")
 



Also on the lines where you are using @Str() to make it a string, you won't need to do that as @XResultSetValue() always returns a string.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Export Spec not loading
Reply #10 - May 12th, 2010 at 9:08pm
Print Post Print Post  
Looks like you are trying to read the contents of a field that does not exist on the current form? If you want the value from the XResultSet, you need to be using @XResultSetValue().

If that is the case, try something like the following
Code
Select All
vExportData += @XResultSetValue(vRSHandle, "txtSpecies")
 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Export Spec not loading
Reply #11 - May 12th, 2010 at 9:10pm
Print Post Print Post  
Ah, Ray you beat me to it.   Smiley
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Export Spec not loading
Reply #12 - May 12th, 2010 at 9:12pm
Print Post Print Post  
Also, if I remember correctly, it has been said that you shouldn't use "+=" with text values, only numbers.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Export Spec not loading
Reply #13 - May 12th, 2010 at 11:37pm
Print Post Print Post  
Thanks for the answer Ray and Carl.

I knew I had been doing more work on other projects, but was amazed at how much I was missing.
The only final tweak I started to do to this was to strip out the decimals.

So this line vExportData = vExportData + @CHR(34) + @XResultSetValue(vRSHandle, "numTagNumber")+@CHR(34)+"," ended up included 8 decimals.
So, to just get the integer value, I had to modify like this:
vExportData = vExportData + @CHR(34) + @Left(@XResultSetValue(vRSHandle, "numTagNumber",@Len(@XResultSetValue(vRSHandle)-9), "numTagNumber)+@CHR(34)+","
This would be needed on all number fields that now were strings.  Good thing I have a naming convention for my fields that identifies numbers.  
But WAIT!!  The good news was that I realized I did not need to do this cleanup for this export file.  This is being imported by Q&A so the fields will be formatted there.  If going to Word I could also have used Field Formatting to clean up the extra decimals.  No need to make more work than needed.

And, "Yes" Carl.  My notes from way back also mention not using += for strings.  Thanks for the reminder.  

Here is the original mention of that by Erika in 2007:
Quote:
This shortcut is deprecated. It is not really part of SBasic and is not reliable when used with strings. That it works at all is coincidental, not intentional. That's why 2.0's documentation does not include it. It's really not worth a couple of keystrokes to rely on something that only works by coincidence. I recommend you use the explicit syntax.
 The full posting is here:  http://www.lantica.com/Forum3/cgi-bin/yabb2/YaBB.pl?num=1195239769/6#6
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Export Spec not loading
Reply #14 - May 13th, 2010 at 1:29pm
Print Post Print Post  
Bob_Hansen wrote on May 12th, 2010 at 11:37pm:
So, to just get the integer value, I had to modify like this:
vExportData = vExportData + @CHR(34) + @Left(@XResultSetValue(vRSHandle, "numTagNumber",@Len(@XResultSetValue(vRSHandle)-9), "numTagNumber)+@CHR(34)+","


FYI: You don't need to get so complicated about this and you certainly don't want to make two trips to the result set for the same value. Use something like @Decimals. If you need to do more complicated processing on a value before writing it out to the file, then return the value to a variable where you can work with it without having to hit the result set again.

@Decimals method
Code
Select All
vExportData = vExportData + @CHR(34) + @Decimals(@XResultSetValue(vRSHandle, "numTagNumber"), 0) + @CHR(34) + "," 



Variable method 1
Code
Select All
var vVal as Int

vVal = @ToNumber(@XResultSetValue(vRSHandle, "numTagNumber"))
vExportData = vExportData + @CHR(34) + vVal + @CHR(34) + "," 



Variable method 2
Code
Select All
var vVal as String

vVal = @XResultSetValue(vRSHandle, "numTagNumber")
vVal = @Left(vVal, @Len(vVal) - 9)
vExportData = vExportData + @CHR(34) + vVal + @CHR(34) + "," 


  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print