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

CTRL Insert and Delete in embedded browse

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

    CTRL Insert and Delete in embedded browse

    Following is some code I am trying to perfect to insert and delete lines in an embedded browse. It runs from the OnKey event of the form.

    The browse table has a 'line' field that is indexed and the browse is sorted by the line field.

    The insert portion works the first time but then it adds duplicate lines numbers after the first insert. I think it has something to do with the indexes, because if I insert one line and then look at the table the new line is at the bottom. I tried tbl.index_primary_put("Line") after table.open, but it locks up. I probably need to update the indexes, but not sure how. Or is there a better way to do this?

    The delete portion works down to deleting the record, but it doesn't renumber the lines like I want it to.

    Any ideas?

    Code:
    if this.Active() = "Browse1" then
    	if a_user.key.value = "{^INSERT}"
    		a_user.key.handled = .T.
    	    if parentform.mode_get()<> "View"
    	    	topparent.commit()
    	    end if
    		if a_user.key.event = "down"
    			if this.Table_Get().Mode_Get() > 0 then
    				this.Commit()
    			end if
    			'First get the current line number and then
    			'renumber the lines starting with the current line
    			dim vLine1 as C
    			dim vLine2 as C
    			vLine1 = parentform:browse1.line.value
    			vLine2 = vLine1
    			dim tbl as P
    			tbl = table.open("salesdetails2")
    '			tbl.index_primary_put("Line")
    			tbl.fetch_first()
    			while .not. tbl.fetch_eof()
    				if tbl.Line = vLine1 then
    					vLine1 = val(vLine1) + 1
    					vLine1 = padl(vLine1,2,"0")				    
    					tbl.change_begin()
    					tbl.line = vLine1
    					tbl.change_end(.t.)
    				end if
    				tbl.fetch_next()
    			end while
    			tbl.close()
    			'Then insert the new line
    			parentform:browse1.new_record()
    			parentform:browse1.line.value = vLine2
    			parentform:browse1.commit()
    		end if
    	end if
    end if
    
    if this.Active() = "Browse1" then
    	if a_user.key.value = "{^DELETE}"
    		a_user.key.handled = .T.
    	    if parentform.mode_get()<> "View"
    	    	topparent.commit()
    	    end if
    		if a_user.key.event = "down"
    			if this.Table_Get().Mode_Get() > 0 then
    				this.Commit()
    			end if
    			parentform:browse1.delete_record()
    			'Renumber lines
    			dim tbl as P
    			dim vLine as C
    			vLine = "0"
    			tbl = table.open("salesdetails2")
    			tbl.fetch_first()
    			while .not. tbl.fetch_eof()
    				vLine = val(vLine) + 1
    				vLine = padl(vLine,2,"0")
    				tbl.change_begin()
    				tbl.line = vLine
    				tbl.change_end(.t.)
    				tbl.fetch_next()
    			end while
    			tbl.close()
    		end if
    	end if
    end if
    Dan
    - Dan Hooley
    - Custom Desktop or Web database development -

    #2
    Re: CTRL Insert and Delete in embedded browse

    Hi Dan,
    Without a sample I think it may be a bit hard for others to help you out--would be a lot of guessing I think.

    But this line seems to be commented out and even if intentional I wanted to point it out for others so it was not considered in trouble shooting.
    ' tbl.index_primary_put("Line")


    I may very well learn something if incorrect here as there are various ways to address things, but it sure looks like in the following you are treating the field line as an object as you have a period instead of a colon before it.
    vLine1 = parentform:browse1.line.value

    In addition: this type of thing (renumbering of rows) has been covered before and may be another reason noone has answered your thread.
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________



    Comment


      #3
      Re: CTRL Insert and Delete in embedded browse

      I suspect that Mike's points will get it working, but you may have a resynch issue, as you are opening a 2nd instance of the browse table, and making changes there. While the changes will stick, you may have to resynch the browse and/or even fetch to a different parent and back.

      You could use this

      t=parentform:tables.browsetablename
      or
      t=table.current(2) '1st child table

      now you are working with the current table

      also, if you open a 2nd instance, it appears that your code will renumber all line items for all parents if this is being done in a set, where the browse is a 1 to many child, while my suggested pointer will only reference child records for the current parent.

      another question - how are they getting numbered in the first place? and will that interfere with the insert code?

      as Mike suggested, post a sample that will demonstrate the issue.
      Cole Custom Programming - Terrell, Texas
      972 524 8714
      [email protected]

      ____________________
      "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

      Comment


        #4
        Re: CTRL Insert and Delete in embedded browse

        Hi Dan,

        Here is some code I use to set the row numbers automatically from the OnSaveRecord event of the child table.
        'Date Created: 20-Nov-2006 02:41:46 PM
        'Last Updated: 02-Aug-2008 12:33:09 PM
        'Created By : User
        'Updated By : Keith Hubert
        line_number=0
        on error goto not_in_set
        head=table.get("enquiry_2") 'the parent table in the set - if you ran this outside of the set
        'it would renumber all invoice line items
        on error goto errors
        items=table.get("order_items")
        if items.records_get() = 0 'there are no line items for that invoice
        end
        end if
        items.fetch_first()
        while .not. items.fetch_eof()
        line_number=line_number+1
        items.change_begin()
        items.line_number=padl(ltrim(str(line_number,2,0)),2,"0")
        'linenumber is a new 2 digit character field in order_items - you are limited to 99 items for one invoice
        'if you want more increase the width of the field and the padl() syntax
        items.change_end(.t.)
        items.fetch_next()
        end while
        end
        not_in_set:
        on error goto errors
        end
        errors:
        err_msg = error_text_get(error_code_get())
        line = error_line_number_get()
        script = error_script_get()
        ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
        end
        Because it runs from the onsaverecord event any additions or deletions are handled without the user touching any keys.

        Hope this is what you wanted.
        Regards
        Keith Hubert
        Alpha Guild Member
        London.
        KHDB Management Systems
        Skype = keith.hubert


        For your day-to-day Needs, you Need an Alpha Database!

        Comment


          #5
          Re: CTRL Insert and Delete in embedded browse

          Thanks Kieth for the sample code. It's close to what I am looking for, but not quite. I had come up with something similar, but mine needs to control which line number to add, not just add one to the end.

          I still have not been able to get it to work.

          I have attached a database that shows what I am trying to do and what is happening. The code is in the OnKey event of the form. The idea is, with the cursor in any field in the browse and pressing ctrl + Insert, or ctrl + Delete, it's supposed to insert a blank line above the current one or delete the current line respectively, and then renumber the rest of the rows. I have a debug command in the code so you can step through the code and watch what is happening.

          If I run it without debugging, it does nothing, but if I debug and watch the variables and tbl.line, it will work down to changing the first record of the loop, and then quits as if it's to eof(). The fetch_prev() and fetch_next() do not seem to work. If I comment out the tbl.change_begin() to change_end(), it loops through the records the way it should, but doesn't update the records, obviously. Have tried fetch_first and then last, regeting the table after delete, etc. but to no avail. It's driving me crazy, but I think there is a lesson here for me and I want to get to the bottom of this.

          Thanks to all for your time.
          Dan
          - Dan Hooley
          - Custom Desktop or Web database development -

          Comment


            #6
            Re: CTRL Insert and Delete in embedded browse

            Hi Dan,

            I have tried ctrl + Insert on the Alphasports Invoice browse and that does not work the way you might expect Insert to work. I opened a table as default browse and tried Ctrl+Insert. I have checked the help file and can see no method for inserting a row. There is no way that you can insert a record into a table, except with a lot of operations and temp tables. What you can do is add a record and then sort it.

            I have looked at your app just to see if the browse was a child table. Which it is. Each child record has a link to a parent, as a new record is added to a table it is always added to the end of the file. If you go to the first Invoice and add a new child record it will be added to the end of the child table. Not inserting it where you can see it. This can be seen when you view the table as a default browse.

            The power of the software and computer links the child records to the parent when you view them on the Invoice form. So now, I hope you can understand that you cannot insert a record into a table the same way as a spreadsheet.

            On the code I supplied, Ctrl + Delete does work and then re-numbers the remaining rows.

            Sorry I cant help you further.
            Regards
            Keith Hubert
            Alpha Guild Member
            London.
            KHDB Management Systems
            Skype = keith.hubert


            For your day-to-day Needs, you Need an Alpha Database!

            Comment


              #7
              Re: CTRL Insert and Delete in embedded browse

              What you can do is add a record and then sort it.
              That is exactly what the code in the OnKey event is supposed to do. I understand that in database terms, new records are always added to the end. But, if you add a record (in my case, with the correct line number in the line field) it acts like it was inserted, because the child link is sorted by the line field. I can do it manually, so I should be able to do with code.

              What I would like is if someone could look at the code in the OnKey event of the form and tell me why the code doesn't work. It's supposed to add or delete records and control the line numbers. You should be able to figure out what it's supposed to do when you look at it, but if not, it's like this:

              crtl + Insert:
              Save the parent and/or child records if they are not.
              get pointer to the child table (of the browse)
              get the current line number into a variable
              go to the last line
              and loop up through each record (line in the browse) to the current record and increase the line number by 1. (This is what doesn't work)
              then insert the new record with the correct line number.
              activate and refresh the browse (which should resort the lines)

              crtl + Delete:
              Save the parent and/or child records if they are not.
              get pointer to the child table (of the browse)
              get the current line number into a variable
              delete the current record (line)
              renumber the remaining records (lines) (This is what doesn't work)
              activate and refresh the browse

              The looping through the records in both cases is what doesn't seem to work. I cannot tell if the fetch_prev() and fetch_next() aren't working or if it has something to do with the change_begin()/change_end() because if I comment the latter out, it loops through the records fine. But with it in, it makes one pass through the loop, then ends.

              Hope I have explained it clear enough that someone can help. Feel free to ask any questions.
              Dan
              - Dan Hooley
              - Custom Desktop or Web database development -

              Comment


                #8
                Re: CTRL Insert and Delete in embedded browse

                IT WORKS!!!! Thanks to Al Buchholz for pointing me in the right direction. Thanks Al for the phone call this morning!

                I had to use table.open instead of table.get, and run a query to get just the child records for the current parent record. Evidently, the table.get pointer has some limitations that I wasn't aware of.

                I would like to get the cursor to land on the first field of the browse on the current record instead of the top. If anybody has any ideas, let me know.

                Attached is the updated/zipped database.
                Thanks, Dan
                - Dan Hooley
                - Custom Desktop or Web database development -

                Comment


                  #9
                  Re: CTRL Insert and Delete in embedded browse

                  Dan

                  Here is a revised zip file - is this what you want

                  When you insert a line, the line opens up and the cursor goes to that line so that the user can enter the record.

                  It a down and dirty solution and I am sure it can be improved, but it seems to work.

                  Tom Baker

                  Comment


                    #10
                    Re: CTRL Insert and Delete in embedded browse

                    Yes Tom, something like that. I don't like the screen flashing around like that, but like you said it probably can be improved on. I tried ui_freeze, but still can see the action. Will keep trying.

                    leaving for the night.
                    Thanks again,
                    Dan
                    - Dan Hooley
                    - Custom Desktop or Web database development -

                    Comment


                      #11
                      Re: CTRL Insert and Delete in embedded browse

                      Dan

                      Here is another zip - found the solution - just change brs.resynch() to brs.refresh() - your don't need any other change to your code just that and it works fine.

                      Tom

                      Comment


                        #12
                        Re: CTRL Insert and Delete in embedded browse

                        Dan

                        This morning when I opened your table again to look at the code and try it one more time, noticed that when you tried to insert a row in the number one slot, the browse did not refresh up to the blank that was inserted.

                        If you change the code in the onKey event from



                        Code:
                        'refresh the browse
                        	brs.activate()
                        	brs.refresh()
                        to

                        Code:
                        'refresh the browse
                        	brs.activate()
                        	       if vLineN="01" then
                        	             sys_send_keys("{up}")
                        	       end if
                        	brs.refresh()
                        That takes care of inserting a line as the first line.

                        Tom

                        Edit. Dan I did more testing, and found that when you first start the test app the process for insertion at line 01 works. After two insertions at line 01 in test app, it stops working. Maybe you or someone else will come up with the final solution.
                        I will certainly keep trying. Sorry
                        Last edited by Tbaker; 08-07-2008, 08:31 AM. Reason: did more testing

                        Comment


                          #13
                          Re: CTRL Insert and Delete in embedded browse

                          Hi Tom, Dan.

                          Tom,
                          Although I'm using version 8 it works for me when inserting from row 01 multiple times without fail.

                          Dan,
                          You will also need to trap the deletion when using either just the keyboards delete button and also when right clicking and choosing delete as these two actions will cause a row number to not be used afterwards.
                          Mike
                          __________________________________________
                          It is only when we forget all our learning that we begin to know.
                          It's not what you look at that matters, it's what you see.
                          Henry David Thoreau
                          __________________________________________



                          Comment


                            #14
                            Re: CTRL Insert and Delete in embedded browse

                            Very interesting Tom. Thanks for your help!

                            Tested it just a little this morning, and it seems to work after about three insertions at line 01, if that is any clue.

                            I am going to be busy with other things, so not sure how much time I will have to devote to this, but certainly am interested in perfecting it, and will keep trying as I have time. Thanks to all for your help!

                            Also, Mike, maybe there is a better solution to the issue you posted, but for my purposes, I will just disable the row selector and right mouse click menu.

                            Dan
                            - Dan Hooley
                            - Custom Desktop or Web database development -

                            Comment


                              #15
                              Re: CTRL Insert and Delete in embedded browse

                              Just found another small (well, serious!) problem.

                              When you insert a new line, and then, without moving off that line, delete it (ctrl-delete), it deletes the wrong line! I think the one below. Haven't debugged, or anything so don't know what is going on.

                              Thanks, Dan
                              - Dan Hooley
                              - Custom Desktop or Web database development -

                              Comment

                              Working...
                              X