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

Problems writing to a file

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

    Problems writing to a file

    Firstly Seasonal Greetings to all!

    Trying to automate a weekly data extraction task.
    I want to concatenate data from Five daily emails I receive into a single file with some data formatting (code for this is removed as I know it works). I appear to have two errors that I cannot solve.

    1)
    Code:
    text = *for_each(tag,stritran_multi(tag,"[COLOR="#0000FF"]<space><space>[/COLOR]","[COLOR="#0000FF"]<space>[/COLOR]"),text)
    I assumed that this would be applied to ALL occurrances in the list entry, but only does the first one, thereby having to put this code in a small loop to get ALL occurences done. "<SPACE>" used to clarify the spaces in the *stritran_multi* command.

    2) each WRITE_LINE is writing 1 CRLF() to the beginning and end of each record so I have a blank line after each line of data.

    anyone got a work around for this?

    Code:
    dim defdir as c = "c:\my databases\aviation\g-info\\"
    dim write_to_file as c = "g_info_updates.txt"
    dim header_text as c = "ModeS	Reg	MSN	Type	Action	Date	Notes"
    dim filelist as c
    filelist = filefind.get(defdir-"g-info changes*.txt",0,"PN")
    fpw = file.open(defdir-write_to_file,FILE_RW_SHARED)
    fpw.write_line(header_text)
    FOR each tag in filelist
    	fp = file.open(tag,file_ro_shared)
    	WHILE .not. fp.eof()
    		text = fp.read_line()
    		IF ut(text) <> "" THEN
    			[COLOR="#FF0000"]FOR x = 1 TO 4
    				text = *for_each(tag,stritran_multi(tag,"  "," "),text)
    			NEXT x[/COLOR]
    			IF regex_match(left(text,6),"[[:xdigit:]]{6}","egi") THEN 
                            ' data formatting code removed
    [COLOR="#FF0000"]				fpw.write_line(text)
    [/COLOR]			END IF
    		END IF
    	END WHILE
    	fp.close()
    next
    fpw.flush()
    fpw.close()
    Last edited by Graham Wickens; 12-23-2011, 10:55 AM. Reason: addition information
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

    #2
    Re: Problems writing to a file

    For issue #2
    The write_line() function adds a CR and LF to each line you may want to try the <file>.write() function instead or build a string with your data then at the end of the script write all the data in one pass.

    <file>.Write_line()
    http://support.alphasoftware.com/alp...LINE%28%29.htm
    The <FILE>.WRITE_LINE() method writes a line of text data ( Text_Line ) to the location of the current file pointer in an open file referenced by the object pointer, <FILE>. The <CR> (Carriage Return) and <LF> (Line Feed) codes are appended to the end of the output.
    For issue #1
    I am not sure what is going on, If I had some sample data to test with I could help figure out the issue. My initial thought is that you are using a nested for...each and in both instances you declaring your arbitrary placeholder as "tag". Without seeing the input data and being able to test this is the thing that I see that might cause an issue.
    Andrew

    Comment


      #3
      Re: Problems writing to a file

      Issue #1. I would do a loop. The stritran_multi() is designed to replace multiple found words with multiple replacement words - multiple search and replace operations on the Input_String, one for each row in Find_Strings. Since you only have one find string you only get one replacement.
      There can be only one.

      Comment


        #4
        Re: Problems writing to a file

        Hi Stan and Andrew,

        had a rethink on how to get what I require and it now works thus:

        Code:
        dim search_list as c = " CANX "+crlf()+" NEW "+crlf()+" REREG "+crlf()+" REST "+crlf()+" G-"+crlf()+" EI-"+crlf()+" M-"+crlf()
        dim replace_list as c = "	CANX	"+crlf()+"	NEW	"+crlf()+"	REREG	"+crlf()+"	REST	"+crlf()+"	G-"+crlf()+"	EI-"+crlf()+"	M-"+crlf()
        dim def_dir as c  = "c:\my databases\aviation\g-info\\"
        dim output_file as c  = "g_info_updates.txt"
        dim header_text as c  = "modes	reg	msn	type	action	date	notes"
        filelist = filefind.get(def_dir-"g-info changes*.txt",0,"pn")
        save_to_file(ut(header_text)+crlf(),def_dir-output_file,.f.)
        FOR each tag in filelist
        	fp = file.open(tag,FILE_RW_SHARED)
        	WHILE .not. fp.eof()
        		text = fp.read_line()
        		IF isnotblank("var->text") THEN
        			IF regex_match(left(text,6),"[[:xdigit:]]{6}","egi") THEN
        				FOR x = 1 TO 4
        					text = *for_each(tag,stritran(tag,"  "," "),text)
        				NEXT x
        				text = *for_each(tag,stritran_multi(tag,search_list,replace_list),text)
        				text  = *for_each(tag,stuff(tag,14,1,"	"),text)
        				text = *for_each(tag,stuff(tag,at("/",tag)+3,1,"	"),text)
        				save_to_file(ut(text)+crlf(),def_dir-output_file,.t.)
        			END IF
        		END IF
        		statusbar.Set_Text("Processing  "+left(text,6))
        	END WHILE
        	fp.close()
        next
        statusbar.clear()
        p.s.

        Stan, glad to see you are still sleeping with a manual under your pillow
        Last edited by Graham Wickens; 12-24-2011, 09:40 AM. Reason: correct names
        --
        Support your local Search and Rescue Unit, Get Lost!

        www.westrowops.co.uk

        Comment

        Working...
        X