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

Writing to table that is already open

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

    Writing to table that is already open

    Hi all,

    I have a script that creates a new record from dialog boxes, as follows:

    Code:
    dim tbl as P
    tbl = table.open("activities")
    tbl.enter_begin()
    
    tbl.Custid = var->currClient
    tbl.Funder_id =var->currFunder
    
    dim filtContact as c
    filtContact = "Contactid = " + quote(var->currContact)
    tbl.Contact = lookup("Funder_Contacts",filtContact,"Contact")
    tbl.Position = lookup("Funder_Contacts",filtContact,"Position")
    tbl.Telephone = lookup("Funder_Contacts",filtContact,"Telephone")
    tbl.Address1 = lookup("Funder_Contacts",filtContact,"Address1")
    tbl.Address2 = lookup("Funder_Contacts",filtContact,"Address2")
    tbl.Address3 = lookup("Funder_Contacts",filtContact,"Address3")
    tbl.Address4 = lookup("Funder_Contacts",filtContact,"Address4")
    tbl.Town_city = lookup("Funder_Contacts",filtContact,"Town_City")
    tbl.County = lookup("Funder_Contacts",filtContact,"County")
    tbl.Postcode = lookup("Funder_Contacts",filtContact,"Postcode")
    
    dim filtFunder as c
    filtFunder = "Funder_Id = " + quote(var->currFunder)
    tbl.Organisation = lookup("funders_new",filtFunder,"Funder_Name")
    tbl.Charity_no = lookup("funders_new",filtFunder,"Charity_No")
    
    tbl.Created_by = user_name()
    tbl.Created_date = date()
    
    tbl.enter_end(.t.)
    tbl.close()
    This is fine if the "Activities" table is not in use by another form, but the table.open() line causes an error if the table is open.

    How do I get around this, please?
    If computers are so clever how come someone as dumb as me has to tell them what to do?

    #2
    Re: Writing to table that is already open

    TABLE.GET()
    There can be only one.

    Comment


      #3
      Re: Writing to table that is already open

      Just a quick comment.

      It would be much quicker if you opened up the table you are doing lookups to and just use tbl.<filedname> instead of lookups. There is significant overhead with a lookup.

      Open the table at the beginning of the script, do a fetch_find(), populate your new table, close the table.

      Code:
      dim tbl as P
      dim tbl1 as P
      
      tbl = table.open("activities")
      tbl1 = table.open("Funder_Contacts")
      
      tbl.enter_begin()
      
      tbl.Custid = var->currClient
      tbl.Funder_id =var->currFunder
      
      dim filtContact as c
      filtContact = "Contactid = " + quote(var->currContact)
      tbl1.index_primary_put("Contactid")  '<-whatever your Key is
      tbl1.fetch_find(filtContact)
      tbl.Contact = tbl1.Contact
      tbl.Position = tbl1.Position
      tbl.Telephone = tbl1.Telephone
      tbl.Address1 = tbl1.Address1
      tbl.Address2 = tbl1.Address2
      tbl.Address3 = tbl1.Address3
      tbl.Address4 = tbl1.Address4
      tbl.Town_city = tbl1.Town_City
      tbl.County = tbl1.County
      tbl.Postcode = tbl1.Postcode
      tbl1.close()

      Comment


        #4
        Re: Writing to table that is already open

        Thanks for your help guys
        If computers are so clever how come someone as dumb as me has to tell them what to do?

        Comment


          #5
          Re: Writing to table that is already open

          Good Morning, Tom

          I still confuse to use (or apply) the Index and Query Fetch method.

          In this case,
          Do I need any loop scripts (Fetch_first, fetch_eof , While ...end)?

          Comment


            #6
            Re: Writing to table that is already open

            John,
            If your query filter will produce more than one record and your process will be addressing more than one record, yes you will need to loop.
            Mike W
            __________________________
            "I rebel in at least small things to express to the world that I have not completely surrendered"

            Comment


              #7
              Re: Writing to table that is already open

              Hi Mike,

              The above script(Tom's) found ONE record and save it on another table without loop method.

              Comment


                #8
                Re: Writing to table that is already open

                Paul,

                To add to Tom's changes I would move the code to do the fetch to outside of the enter_begin() / enter_end() block of code. The less code you have in the enter_begin or change_begin block the less time you have a file lock established.

                Code:
                dim tbl as P
                dim tbl1 as P
                
                tbl = table.open("activities")
                tbl1 = table.open("Funder_Contacts")
                
                [COLOR="red"]dim filtContact as c
                filtContact = "Contactid = " + quote(var->currContact)
                tbl1.index_primary_put("Contactid")  '<-whatever your Key is
                tbl1.fetch_find(filtContact)
                [/COLOR]
                tbl.enter_begin()
                
                tbl.Custid = var->currClient
                tbl.Funder_id =var->currFunder
                
                tbl.Contact = tbl1.Contact
                tbl.Position = tbl1.Position
                tbl.Telephone = tbl1.Telephone
                tbl.Address1 = tbl1.Address1
                tbl.Address2 = tbl1.Address2
                tbl.Address3 = tbl1.Address3
                tbl.Address4 = tbl1.Address4
                tbl.Town_city = tbl1.Town_City
                tbl.County = tbl1.County
                tbl.Postcode = tbl1.Postcode
                [COLOR="Red"]tbl.enter_end(.T.)  ' got lost in Tom's Changes[/COLOR]
                tbl1.close()
                Jeff Ryder

                Comment


                  #9
                  Re: Writing to table that is already open

                  Originally posted by johnkoh View Post
                  Hi Mike,

                  The above script(Tom's) found ONE record and save it on another table without loop method.
                  Good point Jeff. John, so no in this instance no fetch_first-while-fetch_next-end while loop is needed.
                  Mike W
                  __________________________
                  "I rebel in at least small things to express to the world that I have not completely surrendered"

                  Comment


                    #10
                    Re: Writing to table that is already open

                    How about without the Index_primary_put()?
                    Code:
                    filtContact = "Contactid = " + quote(var->currContact)
                    tbl1.index_primary_put("Contactid")  '[COLOR="DarkRed"]<--- Without this[/COLOR]
                    tbl1.fetch_find(filtContact)
                    and in this script, the variable("currContact") was called in the form layout?
                    or
                    Should / Can I address it(" currContact=tbl.contactd") on somewhere here?

                    Comment


                      #11
                      Re: Writing to table that is already open

                      The theread started with this:
                      I have a script that creates a new record from dialog boxes
                      I believe you can assume the variables are generated from the values entered in the dialog boxes.

                      Can I address it(" currContact=tbl.contactd") on somewhere here
                      No. The table pointer tbl is pointing to the table where you are entering a new record (receiving table). The field contactid which the variable currContact is related to is in the source table pointed to by the pointer variable tbl1. I don't see that the receiving table pointed to with tbl has a field contactid. It has custid but I don't see contactid.
                      Mike W
                      __________________________
                      "I rebel in at least small things to express to the world that I have not completely surrendered"

                      Comment


                        #12
                        Re: Writing to table that is already open

                        Originally posted by Mike Wilson View Post
                        The theread started with this:

                        I believe you can assume the variables are generated from the values entered in the dialog boxes.

                        Correct
                        If computers are so clever how come someone as dumb as me has to tell them what to do?

                        Comment


                          #13
                          Re: Writing to table that is already open

                          Thanks to everyone for their help. I had to modify script as follows (changes from Jayrider's post in green), and all is working great now.

                          Originally posted by jaryder View Post

                          Code:
                          dim tbl as P
                          dim tbl1 as P
                          
                          tbl = table.open("activities")
                          tbl1 = table.open("Funder_Contacts")
                          
                          [COLOR="SeaGreen"]tbl1.index_primary_put("Contactid")  '<-whatever your Key is
                          tbl1.fetch_find(var->currContact)[/COLOR]
                          
                          tbl.enter_begin()
                          
                          tbl.Custid = var->currClient
                          tbl.Funder_id =var->currFunder
                          
                          tbl.Contact = tbl1.Contact
                          tbl.Position = tbl1.Position
                          tbl.Telephone = tbl1.Telephone
                          tbl.Address1 = tbl1.Address1
                          tbl.Address2 = tbl1.Address2
                          tbl.Address3 = tbl1.Address3
                          tbl.Address4 = tbl1.Address4
                          tbl.Town_city = tbl1.Town_City
                          tbl.County = tbl1.County
                          tbl.Postcode = tbl1.Postcode
                          [COLOR="Red"]tbl.enter_end(.T.)  ' got lost in Tom's Changes[/COLOR]
                          tbl1.close()
                          If computers are so clever how come someone as dumb as me has to tell them what to do?

                          Comment


                            #14
                            Re: Writing to table that is already open

                            I minor FYI that many people don't understand:

                            The ".T." in
                            tbl.enter_end(.T.)
                            does not to be specified since it is the default. So, 99% of my commands are simply
                            tbl.enter_end()

                            The argument simply determines whether or not the "enter" action is actually completed. However, I can't think of a situation in xbasic where I couldn't determine whether or not the new record should be created even before starting the tbl.enter_begin(). And, if it shouldn't be created then there's no reason to start it.

                            The only time I use this argument is during development when I want to run through the script but not save the new record (or save changes when using change_begin/end) because I just want to test other things in the script and run the same thing over and over until everything else works.

                            In the case of that situation during development testing I do something like this:
                            Code:
                            IF api_getmachinename() = <MyComputerName>
                                commit_flag = .F.   'Change to .T. when ready to test actual results.
                            ELSE
                                commit_flag = .T.
                            END IF
                            ....
                            tbl.enter_begin()
                            ...
                            tbl.enter_end( commit_flag )
                            There were too many times where I forgot to change the commit flag before sending it to the customer. Therefore I added the IF statement so the commit_flag would always be true on any computer except my development computer. (For those of you who have read my many rants about using a keyboard macro program, this IF statement is another of my macros - I type jjcommit and the macro program replaces it with the complete IF/END IF statement.)
                            Last edited by CALocklin; 12-17-2009, 12:50 AM.

                            Comment

                            Working...
                            X