Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate Export Table Specifications 1

Status
Not open for further replies.

sera

Technical User
Jun 29, 2000
360
US
I am not a corel programmer. I have figured out (with your help) how to programatically export a file using ExportAsciiFixed(). However you have to save the table specs and use them in the function. Is there a way for me to programatically export the table specs?
Please let me know if this doesn't make sense!



Sera
I often believe that...
My computer is possessed!
 
You can use exportSpreadsheet to export the specification table to a spreadsheet, or exportAsciiVar to export it to a text document.
 
Well that isn't really the answer I am looking for. I am already exporting the data using exportASCIIFixed. But that function needs a table spec in order to run. I have no choice but to use exportASCIIFixed. The only way that I have found to export the table specifications is manually. I need a function call to export the specs.



Sera
I often believe that...
My computer is possessed!
 
I'm still not clear as to what you are trying to achieve. I understand that you are able to use exportAsciiFixed to export a Paradox table. I understand that the exportAsciiFixed method requires a spec table to describe the structure of the export data. What I thought you were asking for was: "a way to programatically export the table specs" (i.e. the spec table used by the exportAsciiFixed method). However, your answer makes me think that you want to export the paradox spec (i.e. the table structure) for the table being exported. Is this what you want to do?
 
What I thought you were asking for was: "a way to programatically export the table specs" (i.e. the spec table used by the exportAsciiFixed method). However, your answer makes me think that you want to export the paradox spec (i.e. the table structure) for the table being exported. Is this what you want to do?

I thought these were the same. I think we are having terminology problems so I am gonna try to provide an example.

TableForExport
TableForExportSpecs

ExportAsciiFix("TableForExport.db",
"textfile.txt",
"TableForExportSpecs.db")

How I currently am obtaining that TableForExportSpecs.db
is I have to (in Paradox) right click on the TableForExport
and choose export from the menu, then I have to select from the ExportData dropdown ExportAsciiFixed and then go to tab "to fields" and click save spec button and create the TableForExportSpecs.db that I am using int that function call.

I want to automate that process. Does that make sense? Please don't give up on me....



Sera
I often believe that...
My computer is possessed!
 
I think what you want is a script. Just right click on 'Scripts' in the project viewer, pick new and paste the below line into it.

exportASCIIFix("myTable.db", "MyExportedText.txt", "mySpecs.db", True )


Substitute your own table/file names. You could automate it further by assigning variables and accepting input so you could convert different tables without changing the script, but that is more complex.

This will work as long as all the tables and the script are in the working directory. Otherwise you will need to use paths or look at using aliases.

If you need help let us know.


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Here's the more complicated version. This is barebones - no error checking at all.

Code:
var
  myTable,myTextFile	string
endvar

myTable = "Table Name Here"
myTextFile = "Text File Name Here"

myTable.view("Enter Table Name")
myTextFile.view("Enter Text File Name")

exportASCIIFix(myTable, MyTextFile, "mySpecs.db", True)

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
p.s. Dont change any of the "This Table Name Here" type texts - those are prompts when you run the script.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
No...I have a script working right now. What you are doing I am doing as well. I want to automate the process I described above....where I have to manually save the specs of the table to use in the function. Here is why:

The db admin of the database I am exporting may change a field size...or a field name....

in that case my script breaks because it looks at the tablespec.db and says whoa...this table isn't like this. So, if the dbadmin changes anything I have to go over and resave manually all of the table specs...so the script will work.

Does this make sense? This is starting to get frustrating...I really don't know how to say it any differently...

I am automating the export already.
I want to automate the export of mySpec.db

or maybe I should say...I want to automate the process of
saving mySpec.db?






Sera
I often believe that...
My computer is possessed!
 
I do really appreciate you guys trying to interpret what I am saying and sticking with me...I really need to get this figured out....



Sera
I often believe that...
My computer is possessed!
 
This may be a little complicated if you are not used to ObjectPAL. But to do what I think you want will require the combination of the enumFieldStruct() method, some math, and using a tCursor to modify your tableSpec table.

Essentially you will obtain the new structure of the table using enumFieldStruct (the tCursor method is probably best - see the help file). Then you will have to empty the tableSpce table and repopulate it with data from the tCursor created in the enumFieldStruct() method, using a simple equation to calculate the field start and stop points.



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
If you need help with the code, I'll try and toss something together.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Well that isn't the simple saveTabletoSpec function I was hoping for. I do need help with the code because I am no where near being good enough at ObjectPal to do this. I can probably figure it out....Unfortunately, I just don't have the time on this project to learn ObjectPal. I will probably never be a paradox db admin or even much of a programmer. If this is something that you can throw out off the top of your head...then please do...even if it is mostly pseudocode....I can figure it out from there.

Thanks so much


Sera
I often believe that...
My computer is possessed!
 
Give me a bit - I'm in the midst of something.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Here is the script code to update the Specs table. Of course you will need to add your existing table names. It assumes everything is in the :work: directory, but you can add aliases if necessary. I stuck in some very basic error checking which you can modify or ditch if needed. Look for typos as this was done after testing.

myDB.db is the table that your guy keeps changing.

myNewStruct.db is the table created by the enumFieldStruct function to report the new structure of myDB.db

mySpecs.db is the export specifications for the fixed ASCII export.

Code:
var
  tc,tc2   TCursor
  ChangedDB, ExportStruct, MyNewStruct String
  cntr	longint
endVar

cntr = 1
ChangedDB = "myDB.db"
ExportStruct = "myNewStruct.db"
MyNewSpecs = "mySpecs.db"

if not empty(myNewSpecs)
   then msgInfo("Error","Can't empty "+myNewSpecs)
        return
endif

if not tc.open(ChangedDB)
   then msgInfo("Error","Can't open "+ChangedDB)
        return
endif

if not tc.enumFieldStruct(ExportStruct)
   then msgInfo("Error","Can't export the structure of "+ChangedDB)
        return
endif

tc.close()


if not tc.open(MyNewSpecs)
   then msgInfo("Error","Can't open "+myNewSpecs)
        return
endif

if not tc.edit()
   then msgInfo("Error","Can't edit"+myNewSpecs)
        return
endif


if not tc2.open(ExportStruct)
   then msgInfo("Error","Can't open "+ExportStruct)
        return
endif



scan	tc2:

		tc.insertAfterRecord()
		tc."Field Name" = tc2."Field Name"
		tc."Type" = "C"
		tc."Start" = string(cntr)
		tc."Length" = tc2."Size"
		cntr = cntr + int(tc2."Size")

endScan


tc.endEdit()
tc.close()
tc2.close()

The table I used to test this on was very simple (only 3 fields), and the export Specs table fields are based on the help file recommendation. It worked perfectly. Sorry it's not fancier, I a bit covered up at the moment.

Let me know if you need any more help.


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Well I cannot try this right now ... I have to wait until Monday...but I will keep you updated on my progress! Thank you!

Sera
I often believe that...
My computer is possessed!
 
Well Monday was a long way away...

I have gotten the script to run. It has a few problems. I think it is within the call to EnumFieldStruct(ExportStruct). This is not exporting the table specs that the function exportAsciiFixed needs.

Maybe a better way to say it is when I go through the manual method to get a MySpecs.db table I get a different MySpecs.db than if I run this code.

I will keep working on it. But I am wondering if you know of other ways to get the Table ExportStruct other than the EnumFieldStruct(ExportStruct) method?



Sera
I often believe that...
My computer is possessed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top