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

Search & Replace Operation for Multiple Values

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

    Search & Replace Operation for Multiple Values

    Hi,

    Table: > Pupil
    Field: > Class

    I am using search and replace Genie operation to change value of the field "Class". This "Class" field has different values such as 1F,2F, 3F..... etc. I can easily search and replace one value with one replacement but i will have to go through this procedure one by one for each value. Is there any way to replace multiple values in one go ? for example I want to change all the values of 1F with 1T and at the same time all the values of 2F with 2T? (I wish the values separated with commas would work but they dont)

    Regards

    #2
    Re: Search & Replace Operation for Multiple Values

    You probably should use an update operation and the strtran_multi() function.

    Code:
    ? strtran_multi("ABCDEFG","G"+crlf()+"F"+crlf()+"E"+crlf()+"D"+crlf()+"C"+crlf()+"B"+crlf()+"A","9"+crlf()+"8"+crlf()+"7"+crlf()+"6"+crlf()+"5"+crlf()+"4"+crlf()+"3")
    = "3456789"
    
    ? strtran_multi("1T","7T"+crlf()+"6T"+crlf()+"2T"+crlf()+"8T"+crlf()+"1T","99"+crlf()+"33"+crlf()+"77"+crlf()+"00"+crlf()+"2T")
    = "2T"
    Of course, if you are just changing 1 to 2 you can

    ? strtran("1T","1","2")
    = "2T"

    or T to F

    ? strtran("1T","T","F")
    = "1F"
    There can be only one.

    Comment


      #3
      Re: Search & Replace Operation for Multiple Values

      Update operations are wonderfully powerful and flexible tools. They are difficult to test, though. So make at least two good backups before running a new update operation.
      Last edited by Tom Cone Jr; 06-14-2013, 11:21 AM.

      Comment


        #4
        Re: Search & Replace Operation for Multiple Values

        Thanks Stan.

        Comment


          #5
          Re: Search & Replace Operation for Multiple Values

          Tom, yes I have many backups. Cheers

          Comment


            #6
            Re: Search & Replace Operation for Multiple Values

            If it is not perfectly clear, in an update operation you would specify the field and the expression
            field-------------expression
            fieldname--------strtran(fieldname,"T","F")
            There can be only one.

            Comment


              #7
              Re: Search & Replace Operation for Multiple Values

              Personally, I would add a new field to the table called "NEWCLASS" then run the update to populate that field first. If it works as expected, then you can update the old field with the value of NEWCLASS and delete the field from the table. You can update one field multiple times in the same update operation by setting different conditions.
              Attached Files
              Last edited by MoGrace; 06-14-2013, 11:01 PM.
              Robin

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

              Comment


                #8
                Re: Search & Replace Operation for Multiple Values

                Originally posted by Stdio View Post
                for example I want to change all the values of 1F with 1T and at the same time all the values of 2F with 2T? (I wish the values separated with commas would work but they dont)
                Code:
                fromstr="1F,2F,1G,2I,3K,3L,..."
                replstr="1T,2T,2C,2M,3A,4A,..."
                
                t=table.open("Pupil.dbf",FILE_RW_SHARED)
                while .not. t.eof()
                  t.change_begin
                  t.class = if(t.class$fromstr, substr(replstr, at(t.class,fromstr) , 2) ,t.class)
                  ptmp.fetch_next()
                  t.change_end(.t.)			
                end while
                t.close
                Last edited by Ray in Capetown; 06-16-2013, 04:34 AM.

                Comment


                  #9
                  Re: Search & Replace Operation for Multiple Values

                  An update operation is fast and reliable, and Stan's method should work well. This seems to be related to an education program, and I don't think we are talking about many thousands of records, so maybe a simple script through the table will work too.

                  Ray,
                  I don't believe your code is quite complete. I see what you are going for, and I believe that would work. The only thought I have with it though is that it does appear to evaluate every record in the table. If there are many records and only a few need updating, I would choose to define them, filter the table for those needed updating, and change those records, and not evaluate every record in the table. Just a different approach.

                  Code:
                  ' make an update list with first search value, delineator, and second replace value
                  dim vLupdate as C
                  vLupdate=<<%u%
                  1F^^1T
                  2F^^2T
                  1G^^1V
                  2G^^1V
                  1H^^1W
                  2H^^1W
                  %u%
                  
                  'dim variables for the search and replace values
                     dim u1 as C
                     dim u2 as C
                  
                  'open the table
                     t=table.open("Pupil.dbf")
                  
                  'loop through the update list, filter table to string line search value and update record with replace value
                     for each foo in vLupdate
                          'obtain search and replace values from string
                             u1=word(foo,1,"^^")
                  	   u2=word(foo,2,"^^")
                          'filter the table to the search value, loop through the filtered table and update with replace value
                             xi=t.order("","class="+quote(u1)
                  	   t.fetch_first()
                  	   while .not. t.fetch_eof()
                   		 t.change_begin()
                  	 		t.class =u2
                   		t.change_end(.t.)			
                  	   t.fetch_next()
                  	   end while
                      'acquire the next update line from update list
                     next
                     t.close()
                  
                  msgbox("Update Complete")
                  Mike W
                  __________________________
                  "I rebel in at least small things to express to the world that I have not completely surrendered"

                  Comment


                    #10
                    Re: Search &amp; Replace Operation for Multiple Values

                    The update operation allows you to update as many fields as many times as you want (I am sure there is a limit though not stated anywhere. You might find it by trial and error).

                    When you get to the screen that says: Do you want to update any other field? Choose Yes and update the same field. Alpha won't hold that against you as a moral disrepute and refuses to update the same field because it asked you for another and you said yes then updated the same. In fact alpha won't care and you could run the whole thing in one sweep.

                    That said, if you provide more details on the actual values in the field and what you want to change them to, there could be a simple script or function to do so.

                    Comment


                      #11
                      Re: Search &amp; Replace Operation for Multiple Values

                      Yep Mike, I now see two errors
                      ....ptmp.fetch..
                      should be - t.fetch..
                      and the check ;-
                      ... if(t.class$fromstr ...
                      should be before the t.change_begin.

                      I mainly wanted to introduce an approach using strings.

                      Thanks

                      Comment


                        #12
                        Re: Search &amp; Replace Operation for Multiple Values

                        Originally posted by G Gabriel View Post
                        When you get to the screen that says: Do you want to update any other field? Choose Yes and update the same field. Alpha won't hold that against you as a moral disrepute and refuses to update the same field because it asked you for another and you said yes then updated the same. In fact alpha won't care and you could run the whole thing in one sweep.
                        Yes Gabriel, I am doing it the same way as you mentioned and it works fine Thanks! I used to choose "NO" when it asked to update other field( I thought it would mean any other field instead of "Class" itself). I think this is a clever approach of doing this as we only have 1-8 classes at school and every year pupils go to the next level/Class. I know a simple script could also work but our staff members are more keen to stick with this operation. Thanks!!!!!!!!!

                        Comment

                        Working...
                        X