Alpha DevCon 2018
Page 1 of 2 12 LastLast
Results 1 to 30 of 33

Thread: Write Structure to File.

  1. #1
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Write Structure to File.

    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!

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default Re: Write Structure to File.

    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.

  3. #3
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Write Structure to File.

    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!

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Write Structure to File.


  5. #5
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default Re: Write Structure to File.

    Right, Tom. And the "File" functions will do that nicely.

    -- tom

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Write Structure to File.

    Here is little code to help

    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
    Just need to format the foo.value before writing to the file to make it easier to read.

    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

  7. #7
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Write Structure to File.

    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!

  8. #8
    Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,503

    Default Re: Write Structure to File.

    Quote Originally Posted by Keith Hubert View Post
    I have A5 Doc and can print out a file structure, what I would also like to do is save it as text file.
    The easiest way is to open up the structure dialog, highlight, copy &paste into notepad or whatever,

  9. #9
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,757

    Default Re: Write Structure to File.

    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.

  10. #10
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Write Structure to File.

    Keith

    To make it easier I wrote a function

    Dump_tbl_structure()

    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
    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.

    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

  11. #11
    Member Ton Spies's Avatar
    Real Name
    Ton Spies
    Join Date
    Apr 2002
    Location
    Leeuwarden, The Netherlands
    Posts
    555

    Default Re: Write Structure to File.

    Quote Originally Posted by Peter.Greulich View Post
    The easiest way is to open up the structure dialog, highlight, copy &paste into notepad or whatever,
    Peter,

    I remember an estafette in XDialog about the structure of a table/tables.
    You were one of the participants.
    Can you please point us to that thread?

    I think this is usable and easy to adopt for a txtfile

    Ton
    Most things are simple but unfortunately only after the first time

  12. #12
    Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,503

    Default Re: Write Structure to File.

    Quote Originally Posted by Ton Spies View Post
    You were one of the participants.
    Can you please point us to that thread?
    Hi Ton,

    Sorry, I don't remember at all. :confused:

  13. #13
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Write Structure to File.

    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!

  14. #14
    Member Ton Spies's Avatar
    Real Name
    Ton Spies
    Join Date
    Apr 2002
    Location
    Leeuwarden, The Netherlands
    Posts
    555

    Default Write Structure to File for Keith

    Quote Originally Posted by Peter.Greulich View Post
    Hi Ton,

    Sorry, I don't remember at all. :confused:
    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

  15. #15
    "Certified" Alphaholic
    Real Name
    Charlie Crimmel
    Join Date
    Apr 2000
    Location
    West Virginia
    Posts
    1,695

    Default Re: Write Structure to File.

    To All:
    here was my version
    I added Forms and reports and sets

    Thanks cal for your help

    Charlie Crimmel

  16. #16
    "Certified" Alphaholic
    Real Name
    Charlie Crimmel
    Join Date
    Apr 2000
    Location
    West Virginia
    Posts
    1,695

    Default Re: Write Structure to File.

    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

  17. #17
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Write Structure to File.

    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

  18. #18
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Write Structure to File.

    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!

  19. #19
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Write Structure to File.

    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

  20. #20
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,674

    Default Re: Write Structure to File.

    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.

  21. #21
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,674

    Default Re: Write Structure to File.

    And I'll add my changes to Charlies code too...

  22. #22
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,757

    Default Re: Write Structure to File.

    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.)

    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()
    NOTES:
    - 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.

  23. #23
    Member
    Real Name
    D.Chiasson
    Join Date
    Jan 2004
    Location
    West Coast of Canada
    Posts
    622

    Default Re: Write Structure to File.

    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.

  24. #24
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,757

    Default Re: Write Structure to File.

    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.

  25. #25
    Member
    Real Name
    D.Chiasson
    Join Date
    Jan 2004
    Location
    West Coast of Canada
    Posts
    622

    Default Re: Write Structure to File.

    thanks for the quick reply.....tried the sort and got this error...

    sort error.jpg

  26. #26
    Member
    Real Name
    D.Chiasson
    Join Date
    Jan 2004
    Location
    West Coast of Canada
    Posts
    622

    Default Re: Write Structure to File.

    should have mentioned the DBF's are in same folder as the ADB

  27. #27
    Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,431

    Default Re: Write Structure to File.

    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.

  28. #28
    Member
    Real Name
    D.Chiasson
    Join Date
    Jan 2004
    Location
    West Coast of Canada
    Posts
    622

    Default Re: Write Structure to File.

    That did the trick....thanks. Al & Cal, both first rate!!!! You make this one of the best MB on the net.

  29. #29
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,757

    Default Re: Write Structure to File.

    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.

  30. #30
    Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,431

    Default Re: Write Structure to File.

    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.

Similar Threads

  1. Replies: 10
    Last Post: 12-07-2007, 10:11 AM
  2. Help with write to file
    By Peter Lear in forum Alpha Five Version 5
    Replies: 3
    Last Post: 02-13-2003, 10:31 PM
  3. file.write v. file.write_line
    By Graham Wickens in forum Alpha Five Version 4
    Replies: 1
    Last Post: 06-04-2002, 06:35 AM
  4. file write command
    By fgpylant in forum Alpha Five Version 4
    Replies: 2
    Last Post: 02-08-2002, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •