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

How to simply populate an array from a comma delimited text file for individual cell manipulation.

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

    How to simply populate an array from a comma delimited text file for individual cell manipulation.

    Hi,

    I don't know what array function to use to achieve this, so I was hoping someone here could advise me .

    I attach a file with several rows of comma separated data values.

    Could some kind veteran please explain how to get this into an array so that I can then manipulate the contents at will. I.e by row and column.

    Thanks,

    Paultestboard.txt

    #2
    Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

    Seems the easiest would be to import the csv to a table and use

    <ARRAY>.INITIALIZE_FROM_TABLE()
    There can be only one.

    Comment


      #3
      Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

      This works:

      Data = <<%txt%
      Oxbr,14:20,126334315,Stephanie Frances,7306083,82
      Oxbr,14:20,126334315,Milos Georgiou,8651938,45
      etc...
      %txt%
      dim name[6] as P
      name.initialize_properties("Board,Time,CorseID,Candidate,CID,Rating",data)


      ?name[1].board
      = "Oxbr"
      ?name[2].candidate
      = "Milos Georgiou"
      Steve Wood
      See my profile on IADN

      Comment


        #4
        Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

        In Steve's script I would use this to get the data variable populated:

        data = get_from_file("your_file_path\testboard.txt")

        ?data
        = Board,Time,CorseID,Candidate,CID,Rating
        Oxbr,14:20,126334315,Stephanie Frances,7306083,82
        Oxbr,14:20,126334315,Milos Georgiou,8651938,45
        Oxbr,14:20,126334315,Theatre Flame,8943996,102
        Oxbr,14:20,126334315,Nicolas Chauvin,10708295,9
        Oxbr,14:20,126334315,Bella Chandendall,14147852,0
        Oxbr,14:20,126334315,Elaine Porterane,11324681,1000
        Oxbr,15:20,126334325,Gerald Koffman,11620606,45
        Oxbr,15:20,126334325,Myrtle little,11433354,29
        Oxbr,17:20,126334345,Alex Sovinnie,7621066,95
        Oxbr,17:20,126334345,Peter Thae,5730194,26

        Then you could extract the first line for the header into a separate var then subtract it from the rest of the data and initialize your array.
        Robin

        Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

        Comment


          #5
          Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

          Hi Stan,

          The reason I want to do this is because I already import into a table. I use a watch process to run the import (when csv files arrive in a folder) and perform spin-off updates. The trouble is that it works fine 99.99% of the time and then for no apparent reason falls over and because I stop the watch before processing and only restart it after successful outcome, the whole automated application is non-functioning until I notice a problem and restart manually.
          I have not found a way to debug the Alpha import generated xbasic, so I am not able to determine the offending row or cell in the csv file.
          I suspect it is the numerics that are causing the problem, maybe zero values or large values.
          Any way, I thought that if I could get the data into an array and then populate the table, I could circumnavigate the problem.

          Steve, I'll give that a try.

          Thanks to both of you.

          Paul

          Comment


            #6
            Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

            Well, if you want to go the initialize properties route.....

            Code:
            delete arr_ptr
            file_txt = get_from_file("P:\testboard.txt") 'path to your ile
            file_txt = strtran(file_txt,",","|")
            hdr = word(file_txt,1,crlf())
            file_txt = *line_remove(file_txt,1)
            file_txt = remove_blank_lines(file_txt)
            dim_size = w_count(hdr,"|")
            dim arr_ptr[dim_size] as P
            arr_ptr.initialize_properties(hdr,file_txt)
            ? arr_ptr[6].corseid
            = "126334325"
            There can be only one.

            Comment


              #7
              Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

              The most frequent cause of import failures I have found, with name or description fields, is an extra comma.

              Oxbr,14:20,126334315,Stephanie Frances, Jr. ,7306083,82

              is going to cause trouble.

              I often ask for <tab> delimited files for that reason. (or | or ~ delimited)
              There can be only one.

              Comment


                #8
                Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                Thanks again Stan, Steve and Robin.

                I think we have all bases covered now :)

                Paul

                Comment


                  #9
                  Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                  If you want to check the file for "extra" or "missing" commas.....

                  Code:
                  rpt_str = ""
                  lin_place = 0
                  norm = 5
                  fil = file.open("P:\testboard.txt",FILE_RW_EXCLUSIVE)
                  while .not. fil.eof()
                  ln = fil.read_line()
                  lin_place = lin_place+1
                  commas = occurs(",",ln)
                  if commas > norm
                  rpt_str = rpt_str+"Extra comma(s) in line "+alltrim(str(lin_place))
                  else if commas < norm
                  rpt_str = rpt_str+"Missing comma(s) in line "+alltrim(str(lin_place))
                  end if
                  end while
                  fil.close()
                  ui_msg_box("Alert",rpt_str,UI_OK)
                  There can be only one.

                  Comment


                    #10
                    Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                    Originally posted by Stan Mathews View Post
                    Well, if you want to go the initialize properties route.....

                    Code:
                    delete arr_ptr
                    file_txt = get_from_file("P:\testboard.txt") 'path to your ile
                    file_txt = strtran(file_txt,",","|")
                    hdr = word(file_txt,1,crlf())
                    file_txt = *line_remove(file_txt,1)
                    file_txt = remove_blank_lines(file_txt)
                    dim_size = w_count(hdr,"|")
                    dim arr_ptr[dim_size] as P
                    arr_ptr.initialize_properties(hdr,file_txt)
                    ? arr_ptr[6].corseid
                    = "126334325"
                    Originally posted by Stan Mathews View Post
                    Well, if you want to go the initialize properties route.....

                    Code:
                    delete arr_ptr
                    file_txt = get_from_file("P:\testboard.txt") 'path to your ile
                    file_txt = strtran(file_txt,",","|")
                    hdr = word(file_txt,1,crlf())
                    file_txt = *line_remove(file_txt,1)
                    file_txt = remove_blank_lines(file_txt)
                    dim_size = w_count(hdr,"|")
                    dim arr_ptr[dim_size] as P
                    arr_ptr.initialize_properties(hdr,file_txt)
                    ? arr_ptr[6].corseid
                    = "126334325"
                    Hi Stan,

                    What should I use instead of w_count to get the number of text lines/rows for the array dimension?

                    Thanks,

                    Paul

                    Comment


                      #11
                      Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                      Sorry, should be :
                      line_count(file_txt)

                      Paul

                      Comment


                        #12
                        Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                        Hi Stan,

                        How would I sort the array on the "Rating" cell

                        I tried:
                        arr_ptr.sort("", "Rating")
                        but it doesn't seem to work.

                        It would also be handy if I could ? (print) in the interactive window all "Rating" values after sorting to see if it worked
                        Is that possible, or just single cells?

                        Thnks,

                        Paul

                        Comment


                          #13
                          Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                          If you want to specify the second parameter you must supply the first, also you probably want to sort on the numerical value of the rating, not the text of it.

                          arr_ptr.sort("A","val(Rating)")

                          ? arr_ptr.dump_properties("Rating")
                          = 0
                          9
                          26
                          29
                          45
                          45
                          82
                          95
                          102
                          1000
                          There can be only one.

                          Comment


                            #14
                            Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                            Thank you Stan.

                            Perfect :)

                            What if I wanted to ignore zero value rating?

                            I could not find any Alpha explanation of your code line:
                            file_txt = remove_blank_lines(file_txt)
                            but I assume I would need to apply a fix on the text in a similar way.

                            Paul
                            Last edited by chortle; 09-30-2016, 01:23 PM.

                            Comment


                              #15
                              Re: How to simply populate an array from a comma delimited text file for individual cell manipulation.

                              REMOVE_BLANK_LINES() removes all lines in a CR-LF delimited list that have NULL ("") content. Lines that contain invisible characters, such as spaces (" ") will not be removed.
                              Just insurance against having an empty line in the text file.




                              arr_ptr.filter("val(Rating) = 0",.t.) 'this removes entries from the array pointer
                              'so if you want them back later you need to reinitialize the array
                              arr_ptr.sort("A","val(Rating)")
                              ? arr_ptr.dump_properties("Rating")
                              = 9
                              26
                              29
                              45
                              45
                              82
                              95
                              102
                              1000
                              There can be only one.

                              Comment

                              Working...
                              X