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

Date Function to recur for x days

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

    Date Function to recur for x days

    Hi Again,

    I have this function that works great (if my memory serves me correctly, thanks to Jim Chapman)

    function RecurDate as D(BgnDate as D,Interval as N,RefDate as D)
    RecurDate = IF(Interval<2.or.RefDate<BgnDate,{},IF(BgnDate=RefDate,RefDate,RefDate+(Mod((RefDate-BgnDate),Interval))))
    end function

    I use it to test if a Med needs administering on this date. For example

    BgnDate = Start Date
    Interval = 2 (every other day)
    RefDate = Reference date, a variable I supply.

    I use it in this Expression,

    IF(DTOC(RecurDate(Med->Date_Ordered,Med->Recur,var->v_BeginDate+6))=DTOC(var->v_BeginDate+6),"","X")

    I need a new function to allow another input for "Days as N"

    Function RecurDays

    BgnDate = Start Date
    Interval = 2 (every other day)
    Days as N
    RefDate = Reference date, a variable I supply.

    RecurDays = ...???

    For example, if I begin a Med on April 1st, to repeat every 24 days (Interval=24), and continue for the next 7 Days,
    what seven dates in June would include this activity? Would RefDate = 6/1/2013 include the Med?

    I need this expression,
    IF(DTOC(RecurDays(Med->Date_Ordered,Med->Recur,var->v_BeginDate+6))=DTOC(var->v_BeginDate+6),"","X")
    to be true when the RefDate is any of the seven days.

    Confusing... I'm sure confused, and losing sleep!!

    Thanks ~ Tom

    #2
    Re: Date Function to recur for x days

    Thinking more about this, the best solution would be to edit the current Function to include the "Days as N" parameter.

    With a Days = 1 it would work as it does now.

    RecurDate = IF(Interval<2.or.RefDate<BgnDate,{},IF(BgnDate=RefDate,RefDate,RefDate+(Mod((RefDate-BgnDate),Interval)))) 'where to add the Days???

    ~ Tom

    Comment


      #3
      Re: Date Function to recur for x days

      I'm making a little progress.

      My current approach is combine Functions to use RecurDate $ RecurDays

      I developed a new function: RecurDays as follows:

      FUNCTION RecurDays as C(Begin as D, Days as N)

      For i = 1 to Days
      Recurdays = dtoc(Begin)+" "+Alltrim(recurdays)
      begin = begin+1
      'ui_msg_box("Repeating For",DtoC(v_BeginDate))
      next

      RecurDays = chr(34)+alltrim(recurdays)+Chr(34)

      END FUNCTION
      If I put the following in the Interactive Window it seems to work, but it sure is a complex and probably a very Slooooooooow calculation.

      ?DTOC(RecurDate({04/01/2013},7,{05/01/2013})) $ RecurDays({05/01/2013},3)
      Is there a better approach?

      Thanks ~ Tom

      Comment


        #4
        Re: Date Function to recur for x days

        If you don't mind, let's start with a clean page:
        Code:
        FUNCTION Med_dates AS C (start AS D, interval AS N, term AS N ,month as C)
        start=start+interval
        while cmonth(start)<>Month
        	start=start+interval
        end while
        
        end=start+term
        Med_dates=dtoc(start)
        while start<end-1
        	Med_dates=Med_dates+crlf()+dtoc(start+1)
        	start=start+1
        	end while
        END FUNCTION
        It does what you are asking for, though, I think you might mean something else.
        You are asking, what would be the dates in June?
        Code:
        ?Med_dates({4/1/13},24,7,"june")
        = 06/12/2013
        06/13/2013
        06/14/2013
        06/15/2013
        06/16/2013
        06/17/2013
        06/18/2013
        But, if you start at the end of a month, there will be dates in that month and the following one.

        And, of course, you could modify it to give the medicine every other day or however you want to give it.

        Comment


          #5
          Re: Date Function to recur for x days

          This looks good. I won't have time to look at it till tomorrow afternoon. I'll get back to you then.

          I only need it for one month at a time.

          Thank you very VERY much

          Tom

          Comment


            #6
            Re: Date Function to recur for x days

            I had to take a look. I like that it works by the month.

            How would you change it to give a med every-other-day; or Three days every 7 days. It would need to start and stop multiple times per month.

            So close...

            Thanks again - Tom

            Comment


              #7
              Re: Date Function to recur for x days

              I think I could be more clear in what I need. I'm creating a calendar, so I know the date. So for any date, I need to know if the Med should be given.

              I'd like to change the month parameter to a RefDate as D, like in the RecurDate Function above.
              So would the RefDate fall between the dates that Gabriel's Function provides?
              Now it sounds like I need a Logical Function.

              We're getting there. ~ Tom

              Comment


                #8
                Re: Date Function to recur for x days

                From what you are saying, the function should produce a logical result of true or false, i.e. whether you should or should not give the medicine that specific date.
                Here is the function you want with explanation of the parameters and an example.
                Function:
                Code:
                FUNCTION Med_dates AS L (start AS D, interval AS N, term AS N ,Frequency as N, date as D)
                Med_dates=.f.
                start=start+interval
                end=start+term
                while start<end
                	if start=date
                		Med_dates=.t.
                		exit while
                		end 
                		else
                	start=start+frequency
                	end if
                end while
                END FUNCTION
                Explanation of parameters:
                Start : The date the medication treatment will start
                Interval: The interval between the treatment period.
                Term: The length of each treatment cycle
                Frequency: The frequency the treatment is given, e.g. every day, every other day etc.
                Date: The date in question. whether the treatment should or should not be given that date.

                Example:

                A chemotherapy protocol to start 4/1/2013, each cycle is to be repeated every 10 days, each cycle to last for 7 days, the chemo is to be given every other day:
                Code:
                ?Med_dates({4/1/13},10,7,2,{4/10/13})
                = .F.
                ?Med_dates({4/1/13},10,7,2,{4/11/13})
                = .T.
                
                ?Med_dates({4/1/13},10,7,2,{4/12/13})
                = .F.
                
                ?Med_dates({4/1/13},10,7,2,{4/13/13})
                = .T.
                
                ?Med_dates({4/1/13},10,7,2,{4/14/13})
                = .F.
                
                ?Med_dates({4/1/13},10,7,2,{4/15/13})
                = .T.
                
                ?Med_dates({4/1/13},10,7,2,{4/16/13})
                = .F.
                
                ?Med_dates({4/1/13},10,7,2,{4/17/13})
                = .T.
                
                ?Med_dates({4/1/13},10,7,2,{4/18/13})
                = .F.
                ?Med_dates({4/1/13},10,7,2,{4/19/13})
                = .F.

                Comment


                  #9
                  Re: Date Function to recur for x days

                  So close. Example: I want to give a pill every other week for 7 days (one week on, next week off)
                  Whether I make the interval 7 or 14 I can't get it to show .T. every other week.
                  What am I missing? How should this example be entered?

                  Code:
                  ?Med_dates({09/01/2013},14,7,1,{09/01/2013})
                  = .F.
                  
                  ?Med_dates({09/01/2013},14,7,1,{09/08/2013})
                  = .F.
                  
                  ?Med_dates({09/01/2013},14,7,1,{09/15/2013})
                  = .T.
                  
                  ?Med_dates({09/01/2013},14,7,1,{09/22/2013})
                  = .F.
                  
                  ?Med_dates({09/01/2013},14,7,1,{09/29/2013})
                  = .F.
                  The following didn't work either

                  Code:
                  ?Med_dates({09/01/2013},7,7,1,{09/01/2013})
                  = .F.
                  
                  ?Med_dates({09/01/2013},7,7,1,{09/08/2013})
                  = .T.
                  
                  ?Med_dates({09/01/2013},7,7,1,{09/15/2013})
                  = .F.
                  
                  ?Med_dates({09/01/2013},7,7,1,{09/22/2013})
                  = .F.
                  
                  ?Med_dates({09/01/2013},7,7,1,{09/29/2013})
                  = .F.

                  Comment


                    #10
                    Re: Date Function to recur for x days

                    You added a new element: Every Other Week.
                    I could modify it yet again and add one more parameter or you could use it the way it is.
                    The first round will be 1 week away.
                    The second round will be 3 weeks away, or 21 days.
                    Code:
                    'For the first round:?
                    Med_dates({9/1/13},7,7,1,{9/7/13})
                    = .F.
                    ?Med_dates({9/1/13},7,7,1,{9/8/13})
                    = .T.
                    ?Med_dates({9/1/13},7,7,1,{9/9/13})
                    = .T.
                    
                    ..etc
                    
                    'For the second round:
                    ?Med_dates({9/1/13},21,7,1,{9/21/13})
                    = .F.
                    ?Med_dates({9/1/13},21,7,1,{9/22/13})
                    = .T.

                    Comment


                      #11
                      Re: Date Function to recur for x days

                      In your example, the med would need to be entered twice each month?

                      I need the med to be entered once and continue forever!

                      Could you modify the Frequency parameter to define the number of contiguous days from the Start Date?

                      Thanks ~ Tom

                      Comment


                        #12
                        Re: Date Function to recur for x days

                        As you wish.
                        All parameters are as explained prior.
                        I added one more parameter, recurrence, which is how often the cycles recur.
                        Code:
                        FUNCTION Med_dates AS L (start AS D, interval AS N, recurrence as N, term AS N ,Frequency as N, date as D)
                        Med_dates=.f.
                        cycles=round_up((date-start)/(interval*recurrence),0)
                        end_date=start+interval*recurrence*cycles
                        while end_date>=date.and.end_date>=start+(interval*recurrence*(cycles-1))
                        	if end_date=date
                        		Med_dates=.t.
                        		exit while
                        		end
                        		else
                        		end_date=end_date-frequency
                        	end if
                        end while
                        End Function
                        In the following example, the medication is given every other week, for a duration of one week, and during that week, it is given every other day.
                        Code:
                        ?Med_dates({9/1/13},7,2,7,2,{9/22/13})
                        = .F.
                        ?Med_dates({9/1/13},7,2,7,2,{9/23/13})
                        = .T.

                        Comment


                          #13
                          Re: Date Function to recur for x days

                          So the code below I changed to reflect med given every 7 days

                          I changed your code for the med to given daily, not every other day. But it still shows as .T. for every week. Not every other week.

                          What am I doing wrong? I tried making the 14 days, and that didn't work either.

                          How to make it .T. for every other week, to be given every day?

                          Code:
                          ?Med_dates({9/1/13},7,4,7,1,{9/8/13})
                          = .T.
                          
                          ?Med_dates({9/1/13},7,4,7,1,{9/15/13})
                          = .T.
                          
                          ?Med_dates({9/1/13},7,4,7,1,{9/22/13})
                          = .T.
                          
                          ?Med_dates({9/1/13},7,4,7,1,{9/29/13})
                          = .T.

                          Comment


                            #14
                            Re: Date Function to recur for x days

                            Modified:
                            Code:
                            FUNCTION Med_dates AS L (start AS D, interval AS N, recurrence as N, term AS N ,Frequency as N, date as D)
                            Med_dates=.f.
                            start=start+int((date-start)/(interval*recurrence))*(interval*recurrence)
                            end=start+term-1
                            while start<=date.and.start<=end
                            	if  start=date
                            		Med_dates=.t.
                            		exit while
                            		end
                            		else
                            		start=start+frequency
                            	end if
                            end while	
                            END FUNCTION
                            Example:
                            Code:
                            ?Med_dates({9/1/13},7,4,7,1,{9/7/13})
                            = .T.
                            ?Med_dates({9/1/13},7,4,7,1,{9/8/13})
                            = .F.
                            ?Med_dates({9/1/13},7,4,7,1,{9/15/13})
                            = .F.
                            ?Med_dates({9/1/13},7,4,7,1,{9/22/13})
                            = .F.
                            ?Med_dates({9/1/13},7,4,7,1,{9/29/13})
                            = .T.

                            Comment


                              #15
                              Re: Date Function to recur for x days

                              Just looking at your example code: every other week should be .T. and remain so for 7 days.
                              I see the first week and last week as .T.
                              Sorry this is so frustrating. I've been putting it off for years. Your efforts are much appreaciated
                              ~ Tom

                              Comment

                              Working...
                              X