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

Script help

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

    Script help

    Hi all,

    The following script fetches through parent records and gets values from the last child, then adds a new child filled with values from the previous. (It will eventaually increment the month)
    The script runs fine unless it hits a parent with no child records, then it fails. I have tried using Scanning() function without success.

    Would appreciate any advice. File attached.

    Michael

    tbl=table.current()
    outline_level=1
    tbl.fetch_first(Outline_level)
    While .NOT.tbl.fetch_eof()
    tbl=table.current()
    tbl2=table.current(2)
    outline_level=1
    Am_due_pointer=tbl.get("Amount_due")
    Am_due_pointer.fetch_last(outline_level)
    v_month=tbl2.month
    v_weeks=tbl2.no_weeks
    v_year=tbl2.year
    v_roll=tbl2.Roll_no
    trace.writeln(v_month+str(v_weeks)+str(v_roll))
    tbl2.enter_begin()
    tbl2.month=v_month
    tbl2.year=v_year
    tbl2.Roll_no=v_roll
    tbl2.enter_end(.t.)
    tbl.fetch_next(Outline_level)
    End while

    #2
    RE: Script help

    My file has not been attache. Second try

    Michael

    Comment


      #3
      RE: Script help

      Assuming this is running from a form based on the set, and the name of the child is "Amount_Due", I "think" I simplified this as follows:

      '=====
      tbl=table.current()
      tbl2=table.current(2)
      outline_level=1
      tbl.fetch_first(Outline_level)
      While .NOT. tbl.fetch_eof()
      if scanning("Amount_Due") then 'process else goto next record
      Am_due_pointer=table.get("Amount_Due")
      Am_due_pointer.fetch_last()
      v_month=tbl2.month
      v_weeks=tbl2.no_weeks
      v_year=tbl2.year
      v_roll=tbl2.Roll_no
      trace.writeln(v_month+str(v_weeks)+str(v_roll))
      tbl2.enter_begin()
      tbl2.month=v_month
      tbl2.year=v_year
      tbl2.Roll_no=v_roll
      tbl2.enter_end(.t.)
      tbl.fetch_next(Outline_level)
      goto next
      end if
      tbl.fetch_next(Outline_level)
      next
      End while
      end
      '=====

      Finian
      Finian

      Comment


        #4
        RE: Script help

        Michael,

        "hits a parent with no child records"

        I know what you mean, but this situation is really

        "hits a parent with one child record, with no values in the fields". All parent records in the parent table will have at least one "composite" record in the set, the fields in the child table are just blank.

        All you need do is decide how to handle these, as you obviously can't fill them in with previous values. Maybe you have some defaults? You would want to test for the blank values in the set record before you enter the while loop.

        Hope this helps, have a good weekend.

        Stan
        There can be only one.

        Comment


          #5
          RE: Script help

          Oops I dropped the : in the goto it should be next:
          and you should probably not use the word next, nextrecord: maybe.

          Finian
          Finian

          Comment


            #6
            RE: Script help

            Third attempt to upload file

            Michael

            Comment


              #7
              RE: Script help

              Finnian,

              Thanks I tried your version and when I compile I get a 'Missing end while' error.

              I have managed to upload my demo file if you could take a look.

              Michael

              Comment


                #8
                RE: Script help

                Stan,

                If you see my attachment file, it finally uploade, I was too impatient.

                The script runs OK, but if I select a Parent and then delete all child linked to that parent the script fails. Is'nt this a 'Parent with No Child' situation?

                The first child entry will always be entered manually with mainly default values, but there will be occasions when no child record has been added.

                Michael

                Comment


                  #9
                  RE: Script help

                  Michael:
                  I'll take a look in a little while but...
                  it may be the "next" that is causing the problem.

                  Change the line to
                  goto nextrecord

                  and the next should be

                  nextrecord:

                  Finian
                  Finian

                  Comment


                    #10
                    RE: Script help

                    I probably misspoke, I was thinking in terms of composite set records.

                    You could use the key_exist() function to see if there were child records in the table, and use your script if there were, otherwise skip the record.
                    There can be only one.

                    Comment


                      #11
                      RE: Script help

                      Michael,

                      I downloaded your file, deleted 1086, the second child in amount_due, opened the form, pushed the button, and had no script failure. when I re-opened the amount_due table, there was a record for 1086 with the rest of the fields blank.

                      Is this what you mean by the script failing?
                      There can be only one.

                      Comment


                        #12
                        RE: Script help

                        If you go to the button, actions, code, click "Convert to Xbasic" and insert the following code it will fetch through the parent records duplicating the last child record as it goes. If it encounters a parent with no children it skips the record. You never did specify what should happen so I assume this is what you want. If not, you would need additional code in an "else" or after the "end if".

                        '============
                        tbl=table.current()
                        idx=tbl.index_primary_put()
                        tbl2=table.current(2)
                        tbl.fetch_first()

                        While .NOT. tbl.fetch_eof()
                        v_roll=tbl.roll_no
                        Am_due_pointer=table.open("Amount_Due")
                        query.filter="roll_no=v_roll"
                        idx=Am_due_pointer.query_create()
                        recs=idx.records_get()
                        if recs>0 then
                        Am_due_pointer.fetch_last()
                        v_month=Am_due_pointer.month
                        v_weeks=Am_due_pointer.no_weeks
                        v_year=Am_due_pointer.year
                        v_roll=Am_due_pointer.Roll_no

                        trace.writeln(v_month+str(v_weeks)+str(v_roll))

                        tbl2.enter_begin()
                        tbl2.month=v_month
                        tbl2.year=v_year
                        tbl2.Roll_no=v_roll
                        tbl2.no_weeks=v_weeks
                        tbl2.enter_end(.t.)
                        tbl.fetch_next(1)
                        goto nextrecord
                        end if
                        tbl.fetch_next(1)

                        nextrecord:
                        End while

                        Am_due_pointer.close()
                        parentform.resynch()
                        end
                        '============

                        Finian
                        Finian

                        Comment


                          #13
                          RE: Script help

                          Michael:

                          The other works but this one ties up loose ends. BTW, the scanning function does work, but in this case, setting the outline level stops it from working, and without setting the outline level the fetch doesn't advance the table pointer. This opens the child table pointer prior to the while/end while and closes it after as well as dropping the query, good practices to follw.


                          '======
                          tbl=table.current()
                          idx=tbl.index_primary_put()
                          tbl2=table.current(2)
                          tbl.fetch_first()

                          Am_due_pointer=table.open("Amount_Due")
                          outline_level=1
                          While .NOT. tbl.fetch_eof()
                          v_roll=tbl.roll_no
                          query.filter="roll_no=v_roll"
                          idx=Am_due_pointer.query_create()
                          recs=idx.records_get()
                          if recs>0 then
                          Am_due_pointer.fetch_last()
                          v_month=Am_due_pointer.month
                          v_weeks=Am_due_pointer.no_weeks
                          v_year=Am_due_pointer.year
                          v_roll=Am_due_pointer.Roll_no

                          trace.writeln(v_month+str(v_weeks)+str(v_roll))

                          tbl2.enter_begin()
                          tbl2.month=v_month
                          tbl2.year=v_year
                          tbl2.Roll_no=v_roll
                          tbl2.no_weeks=v_weeks
                          tbl2.enter_end(.t.)
                          tbl.fetch_next(outline_level)
                          goto nextrecord
                          end if
                          tbl.fetch_next(outline_level)

                          nextrecord:
                          idx.drop()
                          End while

                          Am_due_pointer.close()
                          parentform.resynch()
                          end
                          '======

                          Finian
                          Finian

                          Comment


                            #14
                            RE: Script help

                            Finnian,

                            Thanks for your script help. Both of your versions run beautiful but I prefer your second version. I shall be posting this into the Code Archives as I think it will be invaluable to others.

                            Just think, all those invoice apps could have a button to add a free gift item to all of their customers accounts.

                            Michael

                            Comment


                              #15
                              RE: Script help

                              MIchael:

                              As a rule I would not run a global update script like that one from a form based on the set. It requires only a few minor code changes to enable the script to run from any menu form, independent of the set. If you really want to do it from the form, you should add a few lines at the start that will check to see if the form in in change or enter mode first and commit the record if necessary.

                              Finian
                              Finian

                              Comment

                              Working...
                              X