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

auto increment (AGAIN)

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

  • auto increment (AGAIN)

    I have read Dr. Wayne's article on auto numbering, plus all the others in this forum. I still can not figure out the solution to my problem.
    This database was originally created using dbase iv.(not by me) I am trying to convert it to alpha 5. The db tracks where files are stored in file cabinets. I want the F_num to auto increment. However, if a file is deleted, I want the program to pick up the deleted file number the next time a new record is entered. I have added the table (delrec) with deleted records from the dbase program. I do not know where to begin with this. I would appreciated any help given. Thanks in advance....(Keep in mind, I am very new at this)
    Rose

  • #2
    RE: auto increment (AGAIN)

    Rose, since you will wind up with separate files having the same file number are you sure you want to re-use numbers of files that have been closed?

    -- tom

    Comment


    • #3
      RE: auto increment (AGAIN)

      Rose, I have a similar situation in our one of our apps. You can do this by first: Making sure that your records are indexed A to Z on the file number. Second: Fetch the first record and see if it the first possible file number. If it is not, use the first possible file number for the next new record because the record that used to hold it was obviously deleted. If the first record is using the first possible file number then third: Using a WHILE statement to fetch through the records one at a time get the value of the current record's file number and store it in a variable (lets name it vprev_fileno). Then fetch the next record. On the next line you will add one to vprev_fileno and then compare it to the file number in the current record. If it does not match then use it for the next new file number. If it does match, then continue fetching through the records until the script finds a record that does not match the vprev_fileno + 1. If you script reaches the end of the table then just use the last records file number + 1 for the next new record. This system will go back and fill any skipped file numbers until all have been filled. From that point on it will always use the first available file number in order of A to Z. Iím going to take a quick shot at the script off the top of my head but it will not be tested. You should get the general idea. Iím assuming the table will be the current table and that the first possible file number is Ď1000í. If not, you can modify the first line to open the proper table and set the first possible file number in the third line.

      t=table.current()
      t.fetch_first()
      vprev_fileno = 1000
      if t.F_num vprev_fileno
      goto EndOfLoop
      end if
      t.fetch_next()
      WHILE .not. t.fetch_eof()
      vprev_fileno=vprev_file_no+1
      if t.fetch_eof() = .T. then
      Goto EndOfLoop
      end if
      if t.F_numvprev_fileno
      goto EndOfLoop
      end if
      t.fetch_next()
      END WHILE
      EndOfLoop:
      'vprev_fileno has next usable file number
      'use it for next file number
      end

      Hope this helps?
      Jeff

      Comment


      • #4
        RE: auto increment (AGAIN)

        Thanks Jeff, I will give it a try.
        Rose

        Comment


        • #5
          RE: auto increment (AGAIN)

          This is the way the dbase 4 program was written "They" wan't to continue with this numbering scheme. I orginally made deleted records inactive but they insisted I reuse the numbers...

          Comment


          • #6
            RE: auto increment (AGAIN)

            Jeff, There is a simpler way to get the same result. I use the same concept in one app to resuse deleted values. In this case I am tracking application numbers which is in the field app_num. I have the following attached to an event on the data entry form. (In my app, it is on the OnDepart event for a field, but could be placed on the CanSave event for the form). I have an index for the app_num called app_num and the field name for the app_num is again app_num

            tbl1 = table.current()
            if tbl1.app_num "".or.tbl1.mode_get() = 0 'Skips loop if already entered or not in enter or change mode.
            else
            num = ""
            for i = 1 to 1000000
            num = padl(alltrim(str(i,7)),7,"0")
            if key_exist("app_no",num)
            else
            tbl1.app_num = num
            parentform:App_Num.Refresh()
            exit for
            end if
            next
            end if

            As you can see, I just keep looping until a blank number is found or the loop hits 1000000. You could determine how many records exist in the table and limit the loop to the number of records +1 also. This method also allows the app_num to be a combination of a specified value and an incremented value.

            Jerry

            Comment


            • #7
              RE: auto increment (AGAIN)

              Looks good Jerry, I'll have to give it a whirl!
              Jeff

              Comment


              • #8
                RE: auto increment (AGAIN)

                I am trying to use your auto increment script to assign a file number.
                I am using the following:
                t=table.current()
                t.fetch_first()
                vprev_fileno = 1
                if t.F_num vprev_fileno
                goto EndOfLoop
                end if
                t.fetch_next()
                WHILE .not. t.fetch_eof()
                vprev_fileno=vprev_fileno+1
                if t.fetch_eof() = .T. then
                Goto EndOfLoop
                end if
                if t.F_numvprev_fileno
                goto EndOfLoop
                end if
                t.fetch_next()
                END WHILE
                EndOfLoop:
                'vprev_fileno has next usable file number
                'use it for next file number
                end
                Question: Where do I attach this script?
                I am using a data entry/update form based on a set with a one to many link using f_num, with an embedded browse for the child records.
                I have tried numerous things but cannot get it to work. I would really appreciate any insight. Thanks in advance...Rose

                Comment


                • #9
                  RE: auto increment (AGAIN)

                  Rose,
                  That script you posted seems a complicated way to get an autoincremented number. Since it has to fetch thru every record, I suspect it is slow too. You can place the script I posted on the CanSaveRecord event in field rules for the table. You will have to change the field names to whatever you are using. The only problem you may have is if the table is a child in a set and you are saving a new record. Then table.current() will point to the parent and not the child. I have a work around for that issue if you need it.

                  Jerry

                  Comment


                  • #10
                    RE: auto increment (AGAIN)

                    Thanks for trying to help me. I would like the user to enter new records on a form based on a set called file with a one to many link based on F_Num. The child browse is embedded in the form
                    The Parent is called Mainfile, the fields are:
                    F_Num 5 in length, character field
                    Location
                    File Name
                    The child is called Subfile, the fields are:
                    F_Num 5 in length, character field
                    Subfile
                    Subject
                    Document

                    On the CanSave event for the form I put:
                    tbl1 = table.current()
                    if tbl1.f_num "".or.tbl1.mode_get() = 0 'Skips loop if already entered or not in enter or change mode.
                    else
                    num = ""
                    for i = 1 to 10000
                    num = padl(alltrim(str(i,5)),5,"0")
                    if key_exist("f_num",num)
                    else
                    tbl1.f_num = num
                    parentform:f_Num.Refresh()
                    exit for
                    end if
                    next
                    end if

                    I cannot get this to work. Do you have any idea what I am doing wrong.
                    Problem 1:If I add a parent record it will generate this error
                    trapped error in action command [1]
                    Command Inline Xbasic
                    Error: functioned not recoginized.
                    It will then assign the number correctly
                    Problem 2: I want to be able to add child records at the same time.
                    Sorry this is so long...wanted to explain in detail. Thand you so much for all your help...Rose

                    Comment


                    • #11
                      RE: auto increment (AGAIN)

                      Jerry...I figured out what I did wrong....thanks so much. However when I do a find by key, I have to enter the leading zeros because I changed F_Num to and alpha field. Is there anyway around this...thanks and thanks for solving the numbering problem!!!!

                      Comment


                      • #12
                        RE: auto increment (AGAIN)

                        Rose,

                        From your message, it looks like you want to autoincrement the f_num field in Mainfile, the parent. Rather than putting the script on the CanSave event for the form, try it on the CanSaveRecord event in field rules for the parent table. When you are entering parent and then child records, the parent is saved when you go to enter a child record. You could also put it on the OnEnterRecord event in field rules. The only difference is when the script fires. I prefer the CanSaveRecord event since it saves it only if the parent is actually saved. The CanSave event for the form fires first when the parent is saved and then again when a child is saved. This could cause an error.

                        Also, be sure you have an index for Mainfile named "f_num" which uses "f_num" as the indexing expression.

                        Eliminate or comment out the line (put ' in from of the line)

                        parentform:f_Num.Refresh()

                        This is designed to refresh an object named f_num on the form. If you don't have a object name f_num on the form, this will generate an error.

                        I ran a test file and tried the script on both field rule events and it works without error.

                        Jerry

                        Comment


                        • #13
                          RE: auto increment (AGAIN)

                          Rose,

                          Glad you got it working. Your difficulty with find is exactly the same issue I am facing on an app. Check out the new tips section on the Alpha Software site. Bill Warner posted a neat way to set up a customized find. This should work well for your case with one addition. After the user enters "jobno" (change to f_num on you app) add the following line before the find()

                          jobno = padl(alltrim(jobno),5,"0")

                          This will add the leading zeros to whatever the user entered.

                          Jerry

                          Comment


                          • #14
                            RE: auto increment (AGAIN)

                            Jerry, I looked in field rules for the parent table. The only options are CanEditField, CanWriteField, OnEditField, OnWroteField. There is not a CanSaveRecord event.
                            That is why I put it on the form.

                            Comment


                            • #15
                              RE: auto increment (AGAIN)

                              Rose,

                              They are the events available for a specific field. Scroll up to the name of the table. Thats where the other events are listed.

                              Jerry

                              Comment

                              Working...
                              X