Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

text import file structures

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    text import file structures

    I am new to Alpha five, but an old hand at Dbase (I've had a license since Dbase II, and still have a Visual Foxpro license) My question concerns importing text files, and defining the file structures into which they are imported. Dbase and Foxpro used the append command with a SDF tag to import text files directly into the database. Once you defined your file structure for the database, you were through. Access does somewhat the same thing, if you define your table and then do an export, saving the export specification, you can use the export specification to import the text file into the datbase. I have not found the methodology to do this in Alpha 5V5--can anyone give me a hint?

    #2
    RE: text import file structures

    BTW, I forgot to mention that the text file I am trying to import is NOT delimited, and DOES NOT contain field names. It is a fixed record length ascii file dump, with each field having defined, specific lengths.

    Comment


      #3
      RE: text import file structures

      From the control panel, click on the operations tab. Then click new and build an import or export operation.

      There are multiple options to choose, but once defined you can reuse as needed.

      Had you tried this before or is this what you are looking for?
      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.
      "Make it as simple as possible, but not simpler."
      Albert Einstein

      http://www.iadn.com/images/media/iadn_member.png

      Comment


        #4
        RE: text import file structures

        Thanks for the reply--but not exactly. I already have a table defined that has the proper structure--is there any way to move that table's structure definition into the "import card"? I don't relish the thought of having to reenter the field specs. One would think that the "suggest structure" option would look to an existing table, if defined for the import, for the field definitions.

        Comment


          #5
          RE: text import file structures

          Yes, just click on the save button (on the toolbar) and you will be asked to name the import spec. (operation in A5).

          You can continue to use this same import operation from then on.

          You then may want to use Action scripting to assign and run the import operation from a button on a form.

          Comment


            #6
            RE: text import file structures

            Oops, misread your post.

            The answer is no...there is no real way to take a structure fron an existing table and create an import spec.

            Sorry, that would be nice though.

            Comment


              #7
              RE: text import file structures

              Okay, give me one more stab at this answer.

              I also have wanted to be able to do this.

              But, here is a (not too cumbersome) work around.

              Note, your table structure should have about 20 or more field to make this adventure worth while.

              1. open up the table whose structure you would like to use as a basis for an import operation in "Design mode", like you were going to edit the structure.

              2. Highlight all the rows and columns.

              3. Press ctrl-c to copy the highlighted structure.
              (for some reason the edit menu is grayed out)

              4. open MS Word.

              5. Paste the structure of the table into Word

              6. You will notice if you do a "Reveal Codes" in Word, that the the Alpha Five table structure you copied is simply TAB delimited text.

              However, the structure you copied is missing two (2) important columns of information needed for the ASCII Table Import Operation. Thry are:

              a. Import (yes or no)
              b. Offet (The starting point for each field)

              So, to enter the "Import" column

              (with reveal codes on in Word)

              aa. Insert the "Import" column between the "fieldname" column and the "Type" column by inserting a TAB and the word "Yes" or "No". This will tell Alpha Five if you want to bring in the field data or not.

              bb. Insert the "offset" column between the "Type" and the "Width" column by inserting a TAB and the starting position (number) of eash field.

              The first field's offset is usually 1. Simply, add the first field's length to that number to get the offset for the second fields offset...and so on.

              7. When you have this complete creating the import spec in Word. Highlight all the rows and columns.

              8. Open up an empty Import card in A5

              9. Paste the spec into the Import card.

              10. Fill in the input (text) file's name. Fill in the output's (DBF) name.

              11. Save and name your Import Operation



              Note: this is easier to do than explain.

              This job is a little easier if your trying to create a "Character Separated ASCII file" Import spec, because there is no "Offset".


              Comment


                #8
                RE: text import file structures








                New Page 1




                Here is an Xbasic function that does what you want. It will import a fixed
                length ascii file into an existing table.
                The ascii file must match the structure of the table. e.g. if the table has 3
                fields:
                firstname,c20
                lastname,c30
                state,c2

                then the ascii file must have data starting in columns 1, 21 and 51
                Here is sample usage:
                a5_import_into_table("customers","c:\data\newcustomer.txt")
                The function returns the number of records imported as a character string.
                If, instead of actually doing the import, you want to see the Xbasic code that
                gets generated do this:
                code = a5_import_into_table("customers","c:\data\newcustomer.txt", .t.)
                a5_show_variable(code)

                function a5_Import_into_Table as
                C (target_table as c , ascii_filename as c, show_code = .f. )
                'DESCRIPTION:Imports a fixed length ascii file into an existing table. Ascii
                file must match the structure of the table.
                'LIMITATIONS:X



                dim preamble as c
                preamble = ""%code%
                dim temp_table as c
                dim temp_folder as c
                temp_folder = file.temp_path_get()

                temp_table = file.temp_path_get() + "TempImport" +remspecial(file.temp_create(""))
                + ".dbf"
                import.type = 1
                import.names = "none"
                import.file = ascii_filename
                import.db = temp_table
                import.skip_lines = 0
                import.skip_bytes = 0
                import.field_sep = ""
                import.record_sep = ""CR""LF""
                import.text_qualifier = ""
                import.record_len = __record_length__
                import.rem_blanks = .F.
                import.escape_newlines = .F.
                import.fields = __field_count__
                %code%


                DIM count AS N
                DIM fields AS C
                DIM i AS N
                DIM offset AS N
                DIM reclength AS N


                fields = table.external_field_name_get(target_table,"N|t|W|d")
                count = line_count(fields)
                dim a_fields[count] as p
                a_fields.initialize_properties("name|type|width|dec",fields)
                reclength = 0
                offset = 1
                for i = 1 to count

                a_fields[i].spec = a_fields[i].name + "," + a_fields[i].type + "," + offset +
                "," + a_fields[i].width + "," + a_fields[i].dec
                a_fields[i].spec = "import.field" + i + " = " + quote( a_fields[i].spec)

                a_fields[i].append_field = "append.m_field" + i + " = " + quote(a_fields[i].name)
                a_fields[i].append_exp = "append.m_exp" + i + " = " + quote("@")+"+" +"file.filename_parse(temp_table,\"n\")"
                +"+"+ quote("-"" + a_fields[i].name)

                offset = offset + val(a_fields[i].width)
                reclength = reclength + val(a_fields[i].width)
                next i

                preamble = stritran(preamble,"__field_count__",""+count)
                preamble = stritran(preamble,"__record_length__",""+(reclength + 2) )


                dim import_code as c
                import_code = preamble + crlf() + a_fields.dump_properties("spec") + crlf() +
                "import()" + crlf()

                'a5_show_variable(import_code)


                dim append_preamble as c
                append_preamble = ""%code%
                a_tbl = table.open(target_table)
                dim start_recs as n
                start_recs = a_tbl.records_get()
                append.t_db = temp_table
                append.m_key = ""
                append.t_key = ""
                append.m_filter = ""
                append.t_filter = ""
                append.type = "All"
                append.m_count = __field_count__
                %code%

                append_preamble = stritran(append_preamble,"__field_count__",""+count)

                dim append_code as c
                append_code = append_preamble + crlf() + a_fields.dump_properties("append_field")
                + crlf() + a_fields.dump_properties("append_exp")

                append_code = append_code + crlf() + ""%code%
                append.t_count = 0
                a_tbl.append()
                dim end_recs as n
                end_recs = a_tbl.records_get()
                a_tbl.close()
                if file.exists(temp_table) then
                file.remove(temp_table)
                end if
                %code%


                dim all_code as c
                all_code = import_code + crlf() + append_code

                if show_code = .t. then
                a5_Import_into_Table = all_code
                else
                a5_Import_into_Table = ""
                dim result as c
                result = evaluate_template(all_code)
                if result "" "" then
                ui_msg_box("Error",result)
                a5_Import_into_Table = ""
                else
                dim recs_imported as n
                recs_imported = end_recs - start_recs
                a5_Import_into_Table = "" + recs_imported
                end if
                end if


                end function





                Comment


                  #9
                  RE: text import file structures

                  note.

                  to use this function, just create a new, empty function in the code editor and past this in.

                  be careful with word wrapping. when you paste, there may be a lot of erroneous line breaks. fix these up before saving the function.

                  Comment


                    #10
                    RE: text import file structures

                    Thanks Selwyn, the function works great!

                    Comment


                      #11
                      RE: text import file structures

                      Thanks for the reply--I think you and Vince have grasped what I am trying to explain. However, I think the answer is as you have proposed--an Xbasic script. It would be nice in a future release for such a function to be included. To be truly user friendly, the import function would simply need an extra button that would say " use destination file spec for import file" or something like that. Until such a time, I guess one could create an export operation, reveal the Xbasic code, and copy the table structure into an import operation script (with some modifications) and get it to work that way.

                      Comment


                        #12
                        RE: text import file structures

                        randy

                        i think you may be missing the point of the function.

                        i have added the function to the language, so it will be built into the next patch of a5.

                        it is very easy to use. you don't need to bother with low level xbasic code.

                        to use the function you just execute this xbasic (which could be in a button on a form, or from the interactive window etc.)

                        a5_Import_into_Table("customer","c:\newcustomers.txt")


                        where "customer" is the name of the table you want to import into, and "c:\newcustomers.txt" is your ascii file.

                        Comment


                          #13
                          RE: text import file structures

                          Thanks!!--I'll try it, and I sincerely appreciate the help

                          I admit i'm a newbie, and quite rusty at writing / reviewing code.

                          Comment

                          Working...
                          X