<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: 4gl code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 16:03:57 GMT</pubDate>
    <description>DZone Snippets: 4gl code</description>
    <item>
      <title>work days between two dates without cycling through dates</title>
      <link>http://snippets.dzone.com/posts/show/808</link>
      <description>I was thinking about how to optimize figuring out the work days between two dates and came up with this function.  It doesn't take into account holidays.  You would have to take out the workdays for holidays from the number if you want to take into account holidays, but that should be easy enough.&lt;br /&gt;&lt;br /&gt;4GL Version&lt;br /&gt;&lt;code&gt; &lt;br /&gt;# workdays&lt;br /&gt;# returns the number of working days between two dates&lt;br /&gt;FUNCTION workdays( dt_begin, dt_end )&lt;br /&gt;&lt;br /&gt;DEFINE&lt;br /&gt;   dt_begin             DATE,&lt;br /&gt;   dt_end               DATE,&lt;br /&gt;   dt_first_sunday      DATE,&lt;br /&gt;   dt_last_saturday     DATE,&lt;br /&gt;   int_workdays         INTEGER&lt;br /&gt;&lt;br /&gt;   # get first sunday&lt;br /&gt;   LET dt_first_sunday = dt_begin + ((7 - WEEKDAY(dt_begin)) MOD 7)&lt;br /&gt;&lt;br /&gt;   # get last saturday&lt;br /&gt;   LET dt_last_saturday = dt_end + ((-1 * (WEEKDAY(dt_end) + 1)) MOD 7)&lt;br /&gt;&lt;br /&gt;   # get work weeks between first sunday and last saturday&lt;br /&gt;   LET int_workdays = (((dt_last_saturday - dt_first_sunday) + 1) / 7) * 5&lt;br /&gt;   &lt;br /&gt;   # if first sunday is not begin date&lt;br /&gt;   IF dt_first_sunday &lt;&gt; dt_begin THEN&lt;br /&gt;&lt;br /&gt;      # assume first sunday is after begin date&lt;br /&gt;      # add workdays from begin date to first sunday&lt;br /&gt;      LET int_workdays = int_workdays + (6 - WEEKDAY(dt_begin))&lt;br /&gt;&lt;br /&gt;   END IF&lt;br /&gt;&lt;br /&gt;   # if last saturday is not end date&lt;br /&gt;   IF dt_last_saturday &lt;&gt; dt_end THEN&lt;br /&gt;&lt;br /&gt;      # assume last saturday is before end date&lt;br /&gt;      # add workdays from last saturday to end date&lt;br /&gt;      LET int_workdays = int_workdays + WEEKDAY(dt_end)  &lt;br /&gt;  &lt;br /&gt;   END IF&lt;br /&gt;&lt;br /&gt;   # return working days&lt;br /&gt;   RETURN int_workdays&lt;br /&gt;&lt;br /&gt;END FUNCTION&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;VBA Version&lt;br /&gt;&lt;code&gt;&lt;br /&gt;' WorkDays&lt;br /&gt;' returns the number of working days between two dates&lt;br /&gt;Public Function WorkDays(ByVal dtBegin As Date, ByVal dtEnd As Date) As Long&lt;br /&gt;&lt;br /&gt;   Dim dtFirstSunday As Date&lt;br /&gt;   Dim dtLastSaturday As Date&lt;br /&gt;   Dim lngWorkDays As Long&lt;br /&gt;&lt;br /&gt;   ' get first sunday in range&lt;br /&gt;   dtFirstSunday = dtBegin + ((8 - Weekday(dtBegin)) Mod 7)&lt;br /&gt;&lt;br /&gt;   ' get last saturday in range&lt;br /&gt;   dtLastSaturday = dtEnd - (Weekday(dtEnd) Mod 7)&lt;br /&gt;&lt;br /&gt;   ' get work days between first sunday and last saturday&lt;br /&gt;   lngWorkDays = (((dtLastSaturday - dtFirstSunday) + 1) / 7) * 5&lt;br /&gt;&lt;br /&gt;   ' if first sunday is not begin date&lt;br /&gt;   If dtFirstSunday &lt;&gt; dtBegin Then&lt;br /&gt;&lt;br /&gt;      ' assume first sunday is after begin date&lt;br /&gt;      ' add workdays from begin date to first sunday&lt;br /&gt;      lngWorkDays = lngWorkDays + (7 - Weekday(dtBegin))&lt;br /&gt;&lt;br /&gt;   End If&lt;br /&gt;&lt;br /&gt;   ' if last saturday is not end date&lt;br /&gt;   If dtLastSaturday &lt;&gt; dtEnd Then&lt;br /&gt;&lt;br /&gt;      ' assume last saturday is before end date&lt;br /&gt;      ' add workdays from last saturday to end date&lt;br /&gt;      lngWorkDays = lngWorkDays + (Weekday(dtEnd) - 1)&lt;br /&gt;&lt;br /&gt;   End If&lt;br /&gt;&lt;br /&gt;   ' return working days&lt;br /&gt;   WorkDays = lngWorkDays&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Oct 2005 23:24:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/808</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>replace in Informix 4GL</title>
      <link>http://snippets.dzone.com/posts/show/760</link>
      <description>Replace algorithm in Informix 4GL so I can find it later.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;DEFINE&lt;br /&gt;   str_hitext           CHAR(130),&lt;br /&gt;   str_text             CHAR(130),&lt;br /&gt;   str_escape           CHAR(1)&lt;br /&gt;&lt;br /&gt;   LET str_escape = ASCII 27&lt;br /&gt;&lt;br /&gt;FUNCTION replace_algorithm()&lt;br /&gt;&lt;br /&gt;DEFINE&lt;br /&gt;   int_temp2            INTEGER,&lt;br /&gt;   int_hipos            INTEGER,&lt;br /&gt;   int_hipos_old        INTEGER,&lt;br /&gt;   int_pos              INTEGER&lt;br /&gt;&lt;br /&gt;   # remove highlight characters from text&lt;br /&gt;   LET int_temp2 = LENGTH(str_hitext)&lt;br /&gt;   LET int_pos = 1&lt;br /&gt;   LET str_text = " "&lt;br /&gt;  &lt;br /&gt;   # cycle through highlight string looking for highlight strings&lt;br /&gt;   LET int_hipos = 1&lt;br /&gt;   LET int_hipos_old = 1&lt;br /&gt;   WHILE int_hipos &lt;= int_temp2 - 7&lt;br /&gt;&lt;br /&gt;      # if we found an escape character (start of highlight sequence)&lt;br /&gt;      IF str_hitext[int_hipos, int_hipos] = str_escape THEN&lt;br /&gt;&lt;br /&gt;         # if a highlight sequence&lt;br /&gt;         IF str_hitext[int_hipos + 1, int_hipos + 7] = "[32703m" OR str_hitext[int_hipos + 1, int_hipos + 7] = "[32723m" THEN&lt;br /&gt; &lt;br /&gt;            # if there is previous data to copy over&lt;br /&gt;            IF int_hipos - 1 &gt;= int_hipos_old THEN&lt;br /&gt;&lt;br /&gt;               # copy data over&lt;br /&gt;               LET str_text[int_pos, int_pos + int_hipos - 1 - int_hipos_old] = str_hitext[int_hipos_old, int_hipos - 1]&lt;br /&gt;               LET int_pos = int_pos + int_hipos - int_hipos_old&lt;br /&gt;&lt;br /&gt;            END IF&lt;br /&gt;&lt;br /&gt;            # move source positions - don't copy this over&lt;br /&gt;            LET int_hipos = int_hipos + 8&lt;br /&gt;            LET int_hipos_old = int_hipos&lt;br /&gt;&lt;br /&gt;         # if not a highlight sequence&lt;br /&gt;         ELSE&lt;br /&gt;&lt;br /&gt;            # move source position&lt;br /&gt;            LET int_hipos = int_hipos + 1&lt;br /&gt;&lt;br /&gt;         END IF&lt;br /&gt;&lt;br /&gt;      # if we didn't find an escape character&lt;br /&gt;      ELSE&lt;br /&gt;&lt;br /&gt;         # move source position&lt;br /&gt;         LET int_hipos = int_hipos + 1&lt;br /&gt;&lt;br /&gt;      END IF&lt;br /&gt;&lt;br /&gt;   END WHILE&lt;br /&gt;&lt;br /&gt;   # if there is previous data to copy over&lt;br /&gt;   IF int_temp2 &gt;= int_hipos_old THEN&lt;br /&gt;&lt;br /&gt;      # copy data over&lt;br /&gt;      LET str_text[int_pos, int_pos + int_temp2 - int_hipos_old] = str_hitext[int_hipos_old, int_temp2]&lt;br /&gt;&lt;br /&gt;   END IF &lt;br /&gt;&lt;br /&gt;END FUNCTION&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 23 Sep 2005 01:27:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/760</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
  </channel>
</rss>
