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 update one array from another array

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

    how to update one array from another array

    If I have two arrays, A and B. I want to end up with the list in array B, but with the second column values provided in array A, matched on the first column. I cannot tell if I should loop through array B and update from array A, or use some method to either select or subtract from array A based on the subset found in array B. Array B is always a subset of array A.

    Array A
    A,1
    B,2
    C,3
    D,4
    E,5

    Array B
    A
    C
    D

    And I want to end up with
    A,1
    C,3
    D,4
    Steve Wood
    See my profile on IADN


    #2
    Re: how to update one array from another array

    I would go with option B. Here is one idea
    Code:
    ArA=<<%txt%
    A,1
    B,2
    C,3
    D,4
    E,5%txt%
    
    ArB=<<%txt%
    A
    C
    D%txt%
    
    dim arrA[0] as P
    arrA.initialize_properties("fld1,fld2",ArA)
    dim arrB[0] as C
    arrB.initialize(arB)
    
    listB = arrB.dump("R")
    ?listB
    = A
    C
    D
    
    ?arrA.dump_properties("fld1,fld2","wordat(fld1,'"+listB+"',crlf())>0")
    = A,1
    C,3
    D,4
    But I don't know if you will hit a limit on the size of the listB variable that gets passed into the wordat function. If so you might need to make it a global variable and pass in the variable instead of its contents. Like....
    ?arrA.dump_properties("fld1,fld2","wordat(fld1,listB,crlf())>0")

    But I don't like doing that so I would probably change to a loop, looping through the first array and grabbing your compare value. Do a find in the second array. If not found then delete that index position in array 1.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

    Comment


      #3
      Re: how to update one array from another array

      Hi Steve,

      It depends on what the exactly array is and what size A or B are. Elaborate a bit.

      Also , if an array of character type, or an a pointer array with 2 properties, or if you really started with a character list. In general, I would use *for_each() and wordat() for a character list, or alternatively, regex for fastest results. Also important is whether you need to maintain the order of list B or not.

      There are also a variety of array functions that could be used, but array.find() is one solution, or array.dump() and array.initialize() can be used to move back and forth for character list processing.
      Regards,

      Ira J. Perlow
      Computer Systems Design


      CSDA A5 Products
      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
      CSDA Barcode Functions

      CSDA Code Utility
      CSDA Screen Capture


      Comment


        #4
        Re: how to update one array from another array

        Hi Tim,

        Originally posted by Tim Kiebert View Post
        But I don't know if you will hit a limit on the size of the listB variable that gets passed into the wordat function.
        I have never run into any limit for a wordat list, using at least several thousand in a list, so I suspect it is just total memory limited.
        Regards,

        Ira J. Perlow
        Computer Systems Design


        CSDA A5 Products
        New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
        CSDA Barcode Functions

        CSDA Code Utility
        CSDA Screen Capture


        Comment


          #5
          Re: how to update one array from another array

          Cool, thanks Ira.
          Tim Kiebert
          Eagle Creek Citrus
          A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

          Comment


            #6
            Re: how to update one array from another array

            Steve, this was my quick attempt at using array functions. (Since you asked about arrays). But as Ira said, if you are starting with a charactar list then there are lots of other possibilities.

            Ira, don't laugh too hard at my attempt.

            Code:
            ArA=<<%txt%
            A,1
            B,2
            C,3
            D,4
            E,5%txt%
            
            ArB=<<%txt%
            A
            C
            D%txt%
            
            dim arrA[0] as P
            arrA.initialize_properties("fld1,fld2",ArA)
            msgbox(arrA.dump_properties("fld1,fld2"))
            
            dim arrB[0] as C
            arrB.initialize(arB)
            
            dim arrAsize as N = arrA.size()
            
            For i = 1 to arrAsize
            	search = arrA[i].fld1
            	If arrB.find(search) = 0 then
            	    arrA.clear(i,i)
            	end if
            Next
            
            msgbox(arrA.dump_properties("fld1,fld2"))
            arrA.sort("AB","fld1")
            msgbox(arrA[2].fld1)
            msgbox(""+arra.size())
            arra.delete(arra.first_empty(),arra.size()-arra.first_empty()+1)
            msgbox(""+arra.size())
            Tim Kiebert
            Eagle Creek Citrus
            A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

            Comment


              #7
              Re: how to update one array from another array

              Thanks everyone, I can build it from here. As far as elaboration it is as simple as my example -- column 1 are Field Names in a web grid ("ID","Name","Account", etc), while column 2 is the column position from left to right in the grid. Array A is generated at run time while array B is provided by the user. The user-provided array B needs to learn the column positions from system generated array A, matched on Field Name. This is related to my post on the web forum http://msgboard.alphasoftware.com/al...d-Grid-Columns.

              You'd have to watch the video in that post to understand - in that model I currently force the user to enter the Field Name and the Column position for each field; effectively building array A above. But I want them to not be concerned about column position, just the field names. Plus this enhancement would ensure that if the grid's column positions changed (but not the field names) that the model would not break.
              Steve Wood
              See my profile on IADN

              Comment


                #8
                Re: how to update one array from another array

                Originally posted by Tim Kiebert View Post
                Ira, don't laugh too hard at my attempt.
                I won't, but it's much too complex. I would for this case just dump the arrays to a list, and do this

                Code:
                ArA=<<%txt%
                A,1
                B,2
                C,3
                D,4
                E,5%txt%
                
                ArB=<<%txt%
                A
                C
                D%txt%
                
                ' Create a temporary list with just the field name in the same order for wordat() usage
                ArA1=*for_each(x,word(x,1,","),ArA)
                
                ' wordat() could be replaced with a regex_merge() or regex_grep(), but may not be best for small list sizes)
                ?*for_each(x,word(ArA,wordat(x,Ara1,crlf()),crlf()),ArB)
                Read my Speed tips here which has a bullet about text (character) strings, arrays, collection and blob types and also stringscanner objects.

                A general rule for speed is (almost) never do a loop where a *for_each() will work. An array find, while good, has the annoying display of a percentage bar when going through an array
                Regards,

                Ira J. Perlow
                Computer Systems Design


                CSDA A5 Products
                New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                CSDA Barcode Functions

                CSDA Code Utility
                CSDA Screen Capture


                Comment


                  #9
                  Re: how to update one array from another array

                  I have not worked heavily with arrays, but the suite of array functions seem pretty limited. Maybe this is a case where some of the functions are not in the Wiki. I would expect to have a function to dump the array to a delimited string without knowing the property names. arr.dump_properties() requires you to know the property names. I would expect to be able to add a property to an existing array without knowing the existing property names and then a function to update each array record.

                  Note - I switched out ArB for a crlf text listB and no longer include the second column. Instead, I (am attempting to use) word_num() to get the record number, since that is what the second column numeric value represented. I want to leave ArA in the array if possible because I don't want to have to know the properties of that array in order to dump it to text.

                  If I could do this my script would be very simple:

                  Pseudo code:

                  'listA - my full list, was ArA
                  listA = <<%txt%
                  Id
                  Field1
                  Field2
                  Field3
                  %txt%

                  ArB.initialize_from_table("[PathAlias.ADB_Path]\mytable")

                  --- function here to add a property to ArB, named "grid_posn"

                  for x = 1 to ArB.size()

                  --- function here to update ArB[x].grid_posn = word_num( listA , ArB[x].my_matching_field )

                  next

                  At this point my original array would have a new property, grid_posn and would contain the record number from the matching value in listA.
                  Steve Wood
                  See my profile on IADN

                  Comment


                    #10
                    Re: how to update one array from another array

                    Originally posted by Steve Wood View Post
                    I have not worked heavily with arrays, but the suite of array functions seem pretty limited. Maybe this is a case where some of the functions are not in the Wiki.
                    Each of the grouped types, Lists, Arrays, Collections, StringScanner and Blobs have advantages. You can always convert from one to another to use it's advantages. I believe all the array functions are documented in the Wiki and other help documents.

                    Originally posted by Steve Wood View Post
                    I would expect to have a function to dump the array to a delimited string without knowing the property names. arr.dump_properties() requires you to know the property names. I would expect to be able to add a property to an existing array without knowing the existing property names
                    It doesn't exist, but would be code like this
                    Code:
                    ' Create Sample array
                    dim arr[5] as p
                    arr.initialize_properties("name,state",<<%str%
                    Ira,MA
                    Steve,CA
                    Tim,??
                    Fred,BR
                    Barney,BR
                    %str%) 
                    
                    ' Assuming all arrays have the same properties, dump all properties of element 1, changing delimiter to "|" or whatever
                    proplist=strtran(trim(properties_enum(arr[1])),crlf(),"|")
                    ?arr.dump_properties(proplist)
                    = Ira|MA
                    Steve|CA
                    Tim|??
                    Fred|BR
                    Barney|BR
                    Originally posted by Steve Wood View Post
                    and then a function to update each array record.
                    Again, it doesn't exist in arrays as simply as you say, but could easily be done with a loop, as in


                    Code:
                    ' Create Sample array
                    dim arr[5] as p
                    arr.initialize_properties("name,state",<<%str%
                    Ira,MA
                    Steve,CA
                    Tim,??
                    Fred,BR
                    Barney,BR
                    %str%) 
                    
                    ' Create Sample List A
                    ListA=<<%text%
                    Barney
                    Tim
                    Steve
                    Fred
                    Sam
                    Ira
                    %text%
                    
                    for each x in arr
                    	x.grid_posn=wordat(x.name,listA,crlf())
                    next
                    
                    proplist=strtran(trim(properties_enum(arr[1])),crlf(),"|")
                    ?arr.dump_properties(proplist)
                    = Ira|MA|6
                    Steve|CA|3
                    Tim|??|2
                    Fred|BR|4
                    Barney|BR|1
                    Originally posted by Steve Wood View Post
                    Note - I switched out ArB for a crlf text listB and no longer include the second column. Instead, I (am attempting to use) word_num() to get the record number, since that is what the second column numeric value represented. I want to leave ArA in the array if possible because I don't want to have to know the properties of that array in order to dump it to text.

                    If I could do this my script would be very simple:

                    Pseudo code:

                    'listA - my full list, was ArA
                    listA = <<%txt%
                    Id
                    Field1
                    Field2
                    Field3
                    %txt%

                    ArB.initialize_from_table("[PathAlias.ADB_Path]\mytable")

                    ' Can't add a property to an entire array, it's to each individual element. Move to inside loop
                    --- function here to add a property to ArB, named "grid_posn"


                    for x = 1 to ArB.size()
                    --- function here to add dim property to ArB, named "grid_posn"
                    dim arB[x].grid_posn as N[/B]
                    --- function here to update ArB[x].grid_posn = word_num( listA , ArB[x].my_matching_field )

                    next

                    At this point my original array would have a new property, grid_posn and would contain the record number from the matching value in listA.
                    Don't use word_num(), this is a wrapper function (i.e. slower), that duplicates a wordat() function that is much faster. See my tips on Good A5 functions to use.

                    Also, it is important to realize you could get the fields from the table as text, process them very easy as *for_each(), then initialize an array with their values. Consider what format the final data MUST be in, or if flexible, consider them all. Then consider the format to get the initial data in, how you must process it (some formats are better than others for processing needs, e.g. array sorts are faster than text sorts), and how you must change the data back to the needed output format. It's not always fun, but for speed, simplicity or adaptability, it's often worth the time to convert to a "best" format
                    Regards,

                    Ira J. Perlow
                    Computer Systems Design


                    CSDA A5 Products
                    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                    CSDA Barcode Functions

                    CSDA Code Utility
                    CSDA Screen Capture


                    Comment


                      #11
                      Re: how to update one array from another array

                      This has been very educational, and I have working code now! I did not know that each element of an array can have a different set of properties. That explains why dump_properties requires you to specify the property list, as it cannot just assume that each element is the same. And why you can only add properties at the element level.

                      Here is my working code (partial). It does not have the same simplicity as my example, but essentially follows examples in Ira's last post. The code is for the web, and so "e.tmpl" used below is a property array from the web environment.

                      ... setup

                      '==get my setup info in an array
                      clst.initialize_from_table("[PathAlias.ADB_Path]\dynamic_cols_setup","grid_name="+quote(grid_name))

                      '==add two properties to the end of my array
                      for x = 1 to clst.size()
                      dim clst[x].grid_posn as N
                      dim clst[x].search_posn as N
                      next

                      '==get all grid fields in order
                      dim all_grid_fields as c = ""
                      for x = 1 to e.tmpl.fields
                      all_grid_fields = all_grid_fields + e.tmpl.field_info[x].Fieldname + crlf()
                      next

                      '==get all search fields in order
                      dim all_search_fields as c = ""
                      for x = 1 to e.tmpl.searchfields
                      all_search_fields = all_search_fields + e.tmpl.searchfield_info[x].Fieldname + crlf()
                      next

                      '==populate my new array fields from the grid and search lists above
                      for each x in clst
                      x.grid_posn = wordat(x.col_name,all_grid_fields,crlf())
                      x.search_posn = wordat(x.col_name,all_search_fields,crlf())
                      next

                      ... do something with this information
                      Steve Wood
                      See my profile on IADN

                      Comment

                      Working...
                      X