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

Editing txt or csv export files

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

    Editing txt or csv export files

    In an exported .csv file (or .txt) I would like to do one of two things:

    If the export exports field names in the first row, I would like to replace those names/row with a different set of names (e.g., a name may need a "#" or a space in it which Alpha does not support). Simply using fil.seek(0) and fil.write_line("blah#,blah 2,") will not work as it messes up the first row of data.

    If the export does not have field names for the top row, I would like to insert a row at the top with field names (e.g., "File#", "Doc type", the latter with no underscore). Have no idea how to do this without wiping out the first row of data.

    Anyone know the trick?

    Ray Lyons


    #2
    Re: Editing txt or csv export files

    Originally posted by Raymond Lyons View Post
    In an exported .csv file (or .txt) I would like to do one of two things:

    If the export exports field names in the first row, I would like to replace those names/row with a different set of names (e.g., a name may need a "#" or a space in it which Alpha does not support). Simply using fil.seek(0) and fil.write_line("blah#,blah 2,") will not work as it messes up the first row of data.

    If the export does not have field names for the top row, I would like to insert a row at the top with field names (e.g., "File#", "Doc type", the latter with no underscore). Have no idea how to do this without wiping out the first row of data.

    Anyone know the trick?

    Ray Lyons
    To preserve the first line, just capture it and concatenate a crlf() plus the first line to your new header.

    Code:
    fil = file.open("C:\exportedfilename.txt",FILE_RW_EXCLUSIVE)
    tmp = fil.read_line()
    fil.seek(0)
    newhead = "x,y,z"+crlf()+tmp
    fil.write_line(newhead)
    fil.flush()
    fil.close()
    I don't know how you would decide whether or not the file actually had a header line.
    Last edited by Stan Mathews; 12-06-2006, 05:55 PM.
    There can be only one.

    Comment


      #3
      Re: Editing txt or csv export files

      Hi Ray. I don't know if there is a trick as such, here's my approach.

      I export information in CSV text format a lot. Because I need a great deal of flexibility I end up writing my own Xbasic scripts to do this. It's quite easy, just output the fields enclosed in double quotes and separated by commas to a standard text file. To test if the file is formatted OK I open it in MS Excel. You should be able to achieve exactly what you want using this approach.

      Comment


        #4
        Re: Editing txt or csv export files

        Originally posted by Stan Mathews View Post
        To preserve the first line, just capture it and concatenate a crlf() plus the first line to your new header.

        Code:
        fil = file.open("C:\exportedfilename.txt",FILE_RW_EXCLUSIVE)
        tmp = fil.read_line()
        fil.seek(0)
        newhead = "x,y,z"+crlf()+tmp
        fil.write_line(newhead)
        fil.flush()
        fil.close()
        I don't know how you would decide whether or not the file actually had a header line.
        Stan,

        As usual I suppose I wasn't clear enough in stating what I needed. Your suggestion would work if there were only 1 line in the txt/csv file, as it would preserve it and insert another one above the preserved one. However, if the file contains multiple lines, at the very least the line below the preserved line will either be gone or all out of order. It's almost as if one has to preserve the entire file contents and then insert the new line 1, but I can't figure out how to do that either.

        Brett, I do not see how going to xbasic is going to allow me to change the fields names from what they are in the Alpha Five table. Am I missing something?

        Ray

        Comment


          #5
          Re: Editing txt or csv export files

          How about the easy way...
          Code:
          dim fn as c = <your_filename>
          dim fieldnames as c = <your_field_names>
          file.from_string(fn,fieldnames + crlf() + file.to_string(fn))

          Lenny Forziati
          Vice President, Internet Products and Technical Services
          Alpha Software Corporation

          Comment


            #6
            Re: Editing txt or csv export files

            Originally posted by Lenny Forziati View Post
            How about the easy way...
            Lenny, Lenny, Lenny,....You should know by now that most of us are averse to doing things the easy way.

            Thanks. Works perfectly with the export omitting the A5 field names.

            Ray

            Comment


              #7
              Re: Editing txt or csv export files

              Originally posted by Raymond Lyons View Post
              Stan,

              As usual I suppose I wasn't clear enough in stating what I needed. Your suggestion would work if there were only 1 line in the txt/csv file, as it would preserve it and insert another one above the preserved one. However, if the file contains multiple lines, at the very least the line below the preserved line will either be gone or all out of order. It's almost as if one has to preserve the entire file contents and then insert the new line 1, but I can't figure out how to do that either.
              I think I tested it and it inserted a new line with the appropriate supplied values without overwriting anything.

              I'll have to take a look tomorrow.
              There can be only one.

              Comment


                #8
                Re: Editing txt or csv export files

                Originally posted by Stan Mathews View Post
                I think I tested it and it inserted a new line with the appropriate supplied values without overwriting anything.

                I'll have to take a look tomorrow.
                That's what I get for using a gibberish file for experimentation. I didn't recognize trashed gibberish from the original gibberish.

                If anyone needs the equivalent of Lenny's solution not using post V5 features.....


                Code:
                source_file = "C:\exportedfilename.txt"
                dest_file = "C:\exportedfilename.$$$"
                fil_src = file.open(source_file,FILE_RW_EXCLUSIVE)
                fil_dest = file.create(dest_file,FILE_RW_EXCLUSIVE)
                newhead = "x,y,z"
                fil_dest.write_line(newhead)
                while .not. fil_src.eof()
                	fil_dest.write_line(fil_src.read_line())
                end while
                fil_dest.flush()
                fil_dest.close()
                fil_src.close()
                file.remove(source_file)
                file.rename(dest_file,source_file)
                There can be only one.

                Comment


                  #9
                  Re: Editing txt or csv export files

                  Thanks Stan. Although I will be using Lenny's "easy" way, having a code snippet like yours is a good way to learn something. In fact, code snippets like these (notice I said "like", as these may rarely be useful) are what there should be more of in appropriate places in the documentation--as I believe there was in, say, v4 documentation. In other words, in more places than they currently do, the docs should not just state, for example, what a function does, they should also illustrate with more short code snippets how one might use that function to do a variety of useful things. That would make the docs much more of learning tool than a mere reference for those who already know most everything. Then if the thing has a good book-like flow to it, a good table of contents, a thorough index and have the ability to be searched for anything, including partial words and phrases, then we might finally have a great learning tool and a lot fewer gripes and pleas for help on this forum. [Note my emphasis on the word "more" in the above. Of course there are already some illustrative code snippets. I'm just saying there should be more and in some cases better ones.]

                  Ray

                  Comment


                    #10
                    Re: Editing txt or csv export files

                    Raymond,

                    I've found the technical editors at Alpha very quick to incorporate suggestions, and examples when I've offered them. Without tooting my horn too much take a look at the examples supplied with tablecount(). I sent them in to Ed, he did what he needed to to vouch for them, and they were incorporated in the Help file. If more people did the same thing our Help system could be made much more robust and useful. I hate the thought of re-inventing a wheel someone else has already mastered. Perhaps you do, as well. So, while this particular topic is fresh in your mind, how about writing up an extended example and submitting it for publication in the Help file? Might save someone else some carving on their next "wheel", if you see what I mean. -- tom

                    Comment


                      #11
                      Re: Editing txt or csv export files

                      Originally posted by Tom Cone Jr View Post
                      Raymond,

                      I've found the technical editors at Alpha very quick to incorporate suggestions, and examples when I've offered them. Without tooting my horn too much take a look at the examples supplied with tablecount(). I sent them in to Ed, he did what he needed to to vouch for them, and they were incorporated in the Help file. If more people did the same thing our Help system could be made much more robust and useful. I hate the thought of re-inventing a wheel someone else has already mastered. Perhaps you do, as well. So, while this particular topic is fresh in your mind, how about writing up an extended example and submitting it for publication in the Help file? Might save someone else some carving on their next "wheel", if you see what I mean. -- tom
                      Tom,

                      Although your suggestion is a good one, I have several reservations about following through right now. The main one is that with Ed being gone, I would need some assurance that I was not wasting time that I do not presently have (lack of time right now being a major reservation, even though in this case it would not take long). Then there is the matter that I suspect my need in this case (using non-A5 supported field names in an exported csv file) is so rare that folks are not out there just dying to have it. I searched the forums and I could not find a single similar request. Plus this reminds me of an article I wrote a couple of years ago for Learnalpha.com. Although it was not a great article in my opinion, I did spend considerable time putting it together, and I no evidence at all that anyone except maybe Peter Wayne learned a thing from it.

                      Still, maybe when Ed's replacement is on board, and when I get an extra hour, I'll come back to this and do as you suggested.

                      Ray

                      Comment


                        #12
                        Re: Editing txt or csv export files

                        I think writing snippet examples must be a situation of "where do I stop". There are so many paths one could take in creating a good example. Consider, I could have answered with the following, straying off path, and still not have included some possible error handling that I might if I was creating it for myself.

                        Code:
                        source_file = ui_get_file("Source","Choose existing source file","","X")
                        ext = FILE.FILENAME_PARSE(source_file,"e" )
                        IF alltrim(source_file) = ""
                        	END
                        ELSEIF (ext != ".txt") .and. (ext != ".asc")
                        	rslt = ui_msg_box("Warning","Are you sure this is a text file?",UI_YES_NO)
                        	IF rslt = UI_NO_SELECTED
                        		END
                        	END IF
                        END IF
                        dest_file = stritran(source_file,ext,".$$$")
                        fil_src = file.open(source_file,FILE_RW_EXCLUSIVE)
                        fil_dest = file.create(dest_file,FILE_RW_EXCLUSIVE)
                        new_head = ui_get_text("First line","Enter the text for the new first line","X,Y,Z")
                        fil_dest.write_line(new_head)
                        WHILE .not. fil_src.eof()
                        	fil_dest.write_line(fil_src.read_line())
                        END WHILE
                        fil_dest.flush()
                        fil_dest.close()
                        fil_src.close()
                        file.remove(source_file)
                        file.rename(dest_file,source_file)
                        'usual end message, uncomment out next line to use this
                        'ui_msg_box("File altered","The new line has been written to "+source_file)
                        'silly end message, uncomment out previous line to use it as the message,comment out the next line to see no confirmation message
                        ui_msg_box("File altered","The new line has been written to "+\
                        source_file+crlf()+"You may write another first line, of course"+\
                        crlf()+"As many times as you like.")
                        rslt = ui_msg_box("Just curious","Would you like to view what was done to "+source_file,UI_OK_CANCEL)
                        IF rslt = UI_OK_SELECTED
                        	sys_open(source_file)
                        ELSE
                        	ui_msg_box("Ok, fine","I'm glad you trust me.")
                        END IF
                        END
                        There can be only one.

                        Comment

                        Working...
                        X