'MacroName:300to306 'MacroDescription:add 306 from 300 or 500 Durations. 'written by John Lavalie, July 17, 2006. option explicit '-------------------- function replace(strString as string, strOld as string, strNew as string) as string dim pos as integer pos = instr(strString, strOld) do while pos > 0 strString = left(strString, pos - 1) & strNew & mid(strString, pos + len(strOld)) pos = instr(strString, strOld) loop replace = strString end function '------------------- function MakeNumeric (temp$) as string dim x% temp$ = trim(temp$) for x% = 1 to len(temp$) if not(isnumeric(mid(temp$, x%, 1))) then temp$ = left(temp$, x% - 1) & mid(temp$, x% + 1) next temp$ = trim(temp$) if len(temp$) = 1 then temp$ = "0" & temp$ MakeNumeric = temp$ end function '------------------- Sub Main Dim CS As Object Set CS = CreateObject("Connex.Client") dim x%, y%, bool, pos% dim tag300$, tag306$, tag500$, temp$ dim hours$, mins$, secs$ dim h%, m%, s% dim durs$(30) bool = CS.GetFixedField ("Type", temp$) if temp$ = "g" then exit sub bool = CS.GetField ("300", 1, tag300$) hours$ = "00" : mins$ = "00" : secs$ = "00" 'cleanup 300 if instr(tag300$, "hrs.") then tag300$ = replace(tag300$, "hrs.", "hr.") elseif instr(tag300$, "hrs") then tag300$ = replace(tag300$, "hrs", "hr.") elseif instr(tag300$, "hr)") then tag300$ = replace(tag300$, "hr)", "hr.)") elseif instr(tag300$, "hr ") then tag300$ = replace(tag300$, "hr ", "hr. ") end if if instr(tag300$, "mins.") then tag300$ = replace(tag300$, "mins.", "min.") elseif instr(tag300$, "mins") then tag300$ = replace(tag300$, "mins", "min.") elseif instr(tag300$, "min ") then tag300$ = replace(tag300$, "min ", "min. ") elseif instr(tag300$, "min)") then tag300$ = replace(tag300$, "min)", "min.)") end if if instr(tag300$, "secs.") then tag300$ = replace(tag300$, "secs.", "sec.") elseif instr(tag300$, "secs") then tag300$ = replace(tag300$, "secs", "sec.") elseif instr(tag300$, "sec)") then tag300$ = replace(tag300$, "sec)", "sec.)") end if if instr(tag300$, "hr. ") then tag300$ = replace(tag300$, "hr. ", "hr., ") if instr(tag300$, "min. ") then tag300$ = replace(tag300$, "min. ", "min., ") if instr(tag300$, "ca. ") then tag300$ = replace(tag300$, "ca. ", "") CS.DeleteField 300, 1 CS.AddField 1, tag300$ 'parse 300 h% = instr(tag300$, "hr.") m% = instr(tag300$, "min.") s% = instr(tag300$, "sec.") if h% = 0 and m% = 0 and s% = 0 then '500 Durations: x% = 1 bool = CS.GetField ("500", x%, tag500$) do until not bool if instr(tag500$, "Durations") then tag500$ = mid(tag500$, len("Durations") + 8) bool = 0 else x% = x% + 1 bool = CS.GetField ("500", x%, tag500$) end if loop 'split y% = 0 : pos% = -1 tag500$ = replace(tag500$, ".", "") do until pos% = 0 pos% = instr(tag500$, ";") durs$(y%) = trim(left(tag500$, pos%)) tag500$ = trim(mid(tag500$, pos% + 1)) y% = y% + 1 loop y% = y% - 1 durs$(y%) = tag500$ tag306$ = "306 " for x% = 0 to y% durs$(x%) = replace(durs$(x%), ":", "") durs$(x%) = replace(durs$(x%), ".", "") durs$(x%) = replace(durs$(x%), ";", "") if instr(durs$(x%), "min") then durs$(x%) = "00" & MakeNumeric(trim(replace(durs$(x%), "min", ""))) & "00" else if instr(durs$(x%), "hr") then durs$(x%) = MakeNumeric(trim(replace(durs$(x%), "hr", ""))) & "0000" if durs$(x%) = "010000" then durs$(x%) = "006000" else do until len(durs$(x%)) = 6 durs$(x%) = "0" & durs$(x%) loop end if end if tag306$ = tag306$ & durs$(x%) & chr(223) & "a" next else '300 () if instr(tag300$, "/") and instr(tag300$, "/") < instr(tag300$, ")") then '(nn n/n hr.) dim l%, r% l% = instr(tag300$, "(") r% = instr(tag300$, ")") temp$ = mid(tag300$, l% + 1, r% - l% - 5) hours$ = MakeNumeric(left(temp$, 2)) l% = val(mid(temp$, len(temp$) - 2, 1)) r% = val(right(temp$, 1)) m% = (l% / r%) * 60 mins$ = MakeNumeric(str(m%)) else '(nn hr. ...) dim DecDur$, foundDecDurs foundDecDurs = FALSE 'check for decimals if h% > 0 then DecDur$ = trim(mid(tag300$, h% - 5, 9)) if DecDur$ like "(.#* hr.)" then m% = val(mid(tag300$, instr(tag300$, "(.") + 2, 2)) * .6 mins$ = MakeNumeric(str(m%)) foundDecDurs = TRUE else if DecDur$ like "(#.# hr.)" then hours$ = "0" & mid(DecDur$, 2, 1) mins$ = trim(str(val(mid(DecDur$, 4, 1)) * 6)) foundDecDurs = TRUE else DecDur$ = trim(mid(tag300$, h% - 6, 10)) if DecDur$ like "(#.## hr.)" then hours$ = "0" & mid(DecDur$, 2, 1) mins$ = trim(str(val(mid(DecDur$, 4, 2)) * .6)) foundDecDurs = TRUE else DecDur$ = mid(tag300$, h% - 7, 11) if DecDur$ like "(##.## hr.)" then hours$ = mid(DecDur$, 2, 2) mins$ = trim(str(val(mid(DecDur$, 5, 2)) * .6)) foundDecDurs = TRUE end if end if end if end if end if 'otherwise fractions or whole numbers if not foundDecDurs then if h% <> 0 then hours$ = MakeNumeric(mid(tag300$, h% - 3, 3)) if m% > 0 then mins$ = MakeNumeric(mid(tag300$, m% - 4, 3)) if val(mins$) > 60 then m% = val(mins$) h% = m% / 60 m% = m% mod 60 hours$ = MakeNumeric(str(h%)) mins$ = MakeNumeric(str(m%)) end if end if if s% > 0 then secs$ = MakeNumeric(mid(tag300$, s% - 4, 3)) if val(secs$) > 59 then s% = val(secs$) m% = s% / 60 s% = s% mod 60 secs$ = MakeNumeric(str(s%)) mins$ = MakeNumeric(str(m%)) end if end if end if end if 'make 306 tag306$ = "306 " & hours$ & mins$ & secs$ end if CS.AddField 1, tag306$ CS.Reformat End Sub