Hi All,
I have A5 Doc and can print out a file structure, what I would also like to do is save it as text file.
Is there a function to do this?
Hi All,
I have A5 Doc and can print out a file structure, what I would also like to do is save it as text file.
Is there a function to do this?
Regards
Keith Hubert
Alpha Guild Member
London.
KHDB Management Systems
Skype = keith.hubert
For your day-to-day Needs, you Need an Alpha Database!
Keith, it's easy enough to save an image or pdf file from the print preview of the A5 Doc file using 3rd party tools. I don't know of a single function that can create a "text" file, but it wouldn't be that difficult to create one in xbasic.
Hi Tom,
I'm sure it wouldn't be too difficult in xbasic if one knew which functions to work with to read the DBF structure and write to a text file. The same as A5 Doc does but not printing it as a report.
Regards
Keith Hubert
Alpha Guild Member
London.
KHDB Management Systems
Skype = keith.hubert
For your day-to-day Needs, you Need an Alpha Database!
Keith
look at
http://support.alphasoftware.com/alp...INFO_GET().htm
or
http://support.alphasoftware.com/alp...NFO_DUMP().htm
Still have to get that into a text file
Tom Baker
Right, Tom. And the "File" functions will do that nicely.
-- tom
Here is little code to help
Just need to format the foo.value before writing to the file to make it easier to read.Code:dim tbl as p tbl=table.open("yourtablename") dim struct as c struct=tbl.Field_Info_Dump("n,t,W") tbl.close() 'msgbox("",struct) dim foo as c dim fp as p dim ln1 as n =20 'this is the length of first column in text fp=file.create("c:\testingfp2.txt",FILE_RW_EXCLUSIVE) 'this would be the name of your text file for each foo in struct n1=word(foo.value,1,",") padout=20-len(n1) n1=n1+space(padout) n2=word(foo.value,2,",")+space(2) n3=word(foo.value,3,",") select 'this allow for space for the length of the type field from 1 to 3 spaces case len(n3)=1 n3=space(2)+n3 case len(n3)=2 n3=space(1)+n3 case else n3=n3 end select fp.write_line(n1+n2+n3) next
Tom Baker
edit:changed the coding to allow for formatting the text file structure
Last edited by Tbaker; 09-11-2010 at 01:00 PM. Reason: change the coding
Hi Tom,
Thanks for that.
That is just what I was looking for.
Regards
Keith Hubert
Alpha Guild Member
London.
KHDB Management Systems
Skype = keith.hubert
For your day-to-day Needs, you Need an Alpha Database!
It's not an "official" page yet because I still have a lot of videos to create but take a look at the "App Basics" video on this page that shows (or will show) how each of my AIMS Grab Bag routines are used. I started building videos because some of the routines are very hard to explain adequately in writing. The output from the App Basics routine is more basic (surprise, surprise) than what A5Doc does - it isn't as fancy or as complete but it's fast, relatively easy to print, and may meet your needs.
Last edited by CALocklin; 09-11-2010 at 02:35 PM.
Keith
To make it easier I wrote a function
Dump_tbl_structure()
It takes one parameter, that is the name of the table you want to send the structure to a text. I have attached a zip file with the text that you can import to your code tab and will put the dump_tbl_structure() function on the code tab of your app. It will get the path of the tablename and then break the structure down and format it to a text file in the folder of your app.Code:FUNCTION dump_tbl_structure AS L (Tablename AS C) dim pt as c dim tbl as p dim hdr_txt as c dim struct as c pt=a5.Get_Path() hdr_txt=upper(Tablename)+"->Table Structure"+crlf()+chr_multi(45,25)+crlf() Tablename=pt+chr(92)+Tablename txt_file=Tablename+"_tbl_structure.txt" tbl=table.open(Tablename) struct=tbl.Field_Info_Dump("n,t,W") tbl.close() dim foo as c dim fp as p dim ln1 as n =20 'this is the length of first column in text fp=file.create(txt_file,FILE_RW_EXCLUSIVE) 'this would be the name of your text file fp.write_line(hdr_txt) for each foo in struct n1=word(foo.value,1,",") padout=20-len(n1) n1=n1+space(padout) n2=word(foo.value,2,",")+space(2) n3=word(foo.value,3,",") select 'this allow for space for the length of the type field from 1 to 3 spaces case len(n3)=1 n3=space(2)+n3 case len(n3)=2 n3=space(1)+n3 case else n3=n3 end select fp.write_line(n1+n2+n3) next END FUNCTION
For instance dump_tbl_structure("ABC") will dump the table structure to a text file name ABC_tbl_structure.txt.
The function used tablename as its imput so you use control down arrow to get the names of the tables in the current app.
Tom Baker
Most things are simple but unfortunately only after the first time
Tom,
Thank you so much for that script, that was very kind of you and is very much appreciated.
Regards
Keith Hubert
Alpha Guild Member
London.
KHDB Management Systems
Skype = keith.hubert
For your day-to-day Needs, you Need an Alpha Database!
Searched for it in V9 and could not find it because its in the code archive
http://msgboard.alphasoftware.com/al...ad.php?t=79628
This thread was started by Chris Hawkes (with code from Mike Wilson, Cal Locklin, Lenny Forziati, & Andy Dibble) with improvements by Chris and Peter.
Something for you Keith?
Ton
Most things are simple but unfortunately only after the first time
To All:
here was my version
I added Forms and reports and sets
Thanks cal for your help
Charlie Crimmel
Keith and others:
if you copy the attached code to a button on a form
It will Pop up a list of tables in the database
check to see if the directory "structures" exists
If not it will create it
Write the structure of the selected table to a text file.
I put comments in the code to explain my directory structure.
yours may be different so you might have to change the lines
that get the paths.
Charlie Crimmel
This is a revision to the original script/function
It now presents you with a dialog box. The Dialog box will show and alphabetized list of all the tables in the current database. You can select "ALL" which will send the table strutures to text file in the same folder as the database, or you can select each individual table you would want to send to a text file.
FWIW
Tom Baker
Last edited by Tbaker; 09-12-2010 at 11:42 AM. Reason: Wrong attachment uploaded - new one is here and in post #19
Hi Tom,
This is very neat.
What is the extra line needed to show the decimal value?
Regards
Keith Hubert
Alpha Guild Member
London.
KHDB Management Systems
Skype = keith.hubert
For your day-to-day Needs, you Need an Alpha Database!
Keith
Here is the revised script
This is the one that should have gone out
It has the decimal in this one.
Sorry
Tom Baker
Here's my take on it...
I used the original f_TablesFieldsIndexes function (now called f_TablesFieldsIndexesDoc) and added Documentation. You'll need to create a table (didnt' want to do this automatically - but it can be added) named tbltabledefs with a structure of
fldname
fldtype
fldwidth
flddecimal
fldrules
The function will write out the currently selected table structure to tbltabledefs. If there's data in tbltabledefs then it will ask to clear it.
After the selected table's structure is written out to tbltabledefs you can create a report.
I'm changing it a bit further to add a key to handle the structure for multiple tables.
And I'll add my changes to Charlies code too...
I added some features to Tom's Dump_tbl_structure function.
The main changes are:
- Ability to select from a list of tables if none is given. (Can double click the table name.)
- Ability to output with tabs as separators so output can be cut and pasted into another table in design mode.
- Added decimal values.
- Automatically open the result file in whatever application is used to open .txt files. (I recommend WordPad or Notepad but quite often Word sets itself up as the default.)
NOTES:Code:'Date Created: 11-Sep-2010 03:48:00 PM 'Last Updated: 12-Sep-2010 12:44:08 PM 'Created By : Tom Baker 'Updated By : Cal Locklin FUNCTION Dump_tbl_structure as L ( Tablename="" as C, Format_for_pasting=.F. as L ) DIM base_name as C DIM dlg_text as C DIM format_for_pasting as L DIM hdr_txt as C DIM msg as C DIM ok_pressed as L DIM padout as N DIM struct as C DIM tbl as P DIM tbl as P DIM tlist as C DIM txt_file as C IF Tablename = "" 'Show list of ALL tables in the .adb folder - in the control panel or not. 'tlist = filefind.get( a5.Get_Path() + "\*.dbf", FILE_FIND_NOT_DIRECTORY, "n" ) 'Show list of all tables in the control panel: 'Since they are in the Control Panel, table.open() works even if they are in a different folder. tlist = A5.Table_Enum() ok_pressed = .F. dlg_text = <<%dlg% {ysize=.3}{units=F}{font=Arial,9,n}{sp}; (Format_for_pasting){font=Arial,9,b}Format for pasting into design mode.{font=Arial,9,n}{sp}{sp}<%I=$$generic.help;B=N%Help>; {stretch=height,width}[.80,15tablename^#tlist!tch_*]; {stickto=bottom,center} {sp}; {justify=center}<*15OK> <15Cancel> {comment Putting "Format_for_pasting" in a second time and hiding it was the only way I could get the pasting to work when using double click} {condition=1=2}(Format_for_pasting) %dlg% DIM dlg_result as C dlg_result = ui_dlg_box( "SELECT TABLE", dlg_text, <<%code% IF left( a_dlg_button, 4 ) = "tch_" IF a_dlg_button = "tch_dblclick" ok_pressed = .T. ELSE a_dlg_button = "" END IF ELSEIF a_dlg_button = "Help" msg = "This creates an output format that may not look as good in the printout " msg = msg + "but any field(s) can be cut and pasted into the table design mode." + crlf(2) msg = msg + "This can be handy for copying standard fields such as create and " msg = msg + "change dates or address fields to other tables." ui_msg_box( "INSTRUCTIONS", msg, ui_information_symbol ) a_dlg_button = "" ELSEIF a_dlg_button = "OK" IF tablename = "" msg = "Please select a table or press 'Cancel' to quit." ui_msg_box( "SELECTION REQUIRED", msg, ui_attention_symbol ) a_dlg_button = "" ELSE ok_pressed = .T. END IF END IF %code% ) IF .not. ok_pressed END' END IF base_name = Tablename END IF 'If Tablename includes the path (JIC), get the "base_name" for display. base_name = file.filename_parse( Tablename, "N" ) hdr_txt = upper( base_name ) + " -> Table Structure" + crlf() + chr_multi( 45, 45 ) + crlf(2) txt_file = base_name + "_tbl_structure.txt" tbl = table.open( Tablename ) struct = tbl.Field_Info_Dump( "n,t,W,D" ) tbl.close() IF .not. format_for_pasting DIM foo as C DIM new_struct as C DIM n1 as C DIM n2 as C DIM n3 as C DIM n4 as C new_struct = "" 'FYI FOR EACH foo in struct n1 = word( foo.value, 1, "," ) padout = 20 - len( n1 ) n1 = n1 + space( padout ) n2 = word( foo.value, 2, "," ) + space(2) n3 = word( foo.value, 3, "," ) n4 = space(4) + word( foo.value, 4, "," ) SELECT 'this allow for space for the length of the type field from 1 to 3 spaces CASE len( n3 ) = 1 n3 = space(2) + n3 CASE len( n3 ) = 2 n3 = space(1) + n3 CASE ELSE n3 = n3 END SELECT new_struct = new_struct + n1 + n2 + n3 + n4 + crlf() NEXT struct = new_struct ELSE 'use tabs so field info can be cut and pasted to the table design mode. struct = stritran( struct, ",", chr(9) ) END IF save_to_file( hdr_txt + struct, txt_file ) sys_open( txt_file ) END FUNCTION dump_tbl_structure()
- The dump_tbl_structure() call at the end just allows you to test it in the code editor.
- The second (Format_for_pasting) that is at the end of the "dlg_text" and hidden using "condition=1=2" (which is usually false:D) is there only because the value of Format_for_pasting always ended up false, even though the box remained checked, whenever a double click was used to select the table. After much trial and error, the only solution I could find was to add a second (Format_for_pasting). (Sometimes ya just have to do what works!:()
Last edited by CALocklin; 09-12-2010 at 01:30 PM.
Cal is there anyway that the list of DBFs are sorted alphabetically? Is there anyway to allow someone to dump to txt for all vs each one? This is a beauty!!!!! thanks.
Holy cow! I don't even remember doing that. Of course, it was 7 years ago.
If you want the list sorted, just add this after the line "tlist = A5.Table_Enum()":
tlist = sortsubstr( tlist )
or ... change the line to:
tlist = sortsubstr( A5.Table_Enum() )
Hmmm, I didn't check this so I don't recall if the A5.Table_Enum() function returns the whole path or not. I don't think it does unless the table is not in the same folder as the application (.adb) file but I'm not sure.
As for dumping all to a text file, it could be done but would involve more time to add a loop and the appropriate prompts, checks, and logic to handle it all.
thanks for the quick reply.....tried the sort and got this error...
sort error.jpg
should have mentioned the DBF's are in same folder as the ADB
tlist = sortsubstr( A5.Table_Enum() ,crlf())
Al Buchholz
Bookwood Systems, LTD
Weekly QReportBuilder Webinars Thursday 1 pm CST
Occam's Razor - KISS
Normalize till it hurts - De-normalize till it works.
Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.When we triage a problem it is much easier to read sample systems than to read a mind.
That did the trick....thanks. Al & Cal, both first rate!!!! You make this one of the best MB on the net.
Thanks for showing that correction Al. I swear there's a missing spot somewhere in my memory. I forget to add that delimiter about 80% of the time when I use that sortsubstr() function - and I've used it quite a bit. I guess it just seems like something that should have a default.
It's the same affliction I have - CRS - Can't Remember Stuff
Thank goodness it's in the documentation.
Al Buchholz
Bookwood Systems, LTD
Weekly QReportBuilder Webinars Thursday 1 pm CST
Occam's Razor - KISS
Normalize till it hurts - De-normalize till it works.
Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.When we triage a problem it is much easier to read sample systems than to read a mind.
Bookmarks