'-----------------------------------------------
'CHECK IS VALID EMAIL ADDRESS FORMAT
'-----------------------------------------------

Function CheckIsEmail ( strEmailAddress )
   Dim regEx, retVal

   Set regEx = New RegExp

   '#
   '# note the regex below must be on one single line
   '# it is shown wrapped on this web page
   '#
   regEx.Pattern    ="^(([^<>()[\]\\.,;:\s@""]+(\.[^<>()[\]\\.,;:\s@""]+)*)|("".+""))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$"
   regEx.IgnoreCase = true
   blnReturnValue   = regEx.Test ( strEmailAddress )

   CheckIsEmail     = blnReturnValue
End Function

Function vbSplitString ( strString, strDelimiter, numCount )
   dim arrReturn

   arrReturn     = split  ( strString, strDelimiter )
   numCount      = uBound ( arrReturn ) + 1

   vbSplitString = arrReturn
end function

Function vb_Pad_Left ( string, length )
   Dim Local_String
   if TypeName ( string ) <> "String" then
      if IsNull ( string ) then
         Local_String = " "
      else
         Local_String = Cstr( string )
      end if
   else
      Local_String = string
   end if

   Local_String = Trim ( Local_String )

   do while len( Local_String ) < length
      Local_String = " " & Local_String
   loop

   vb_Pad_Left = Local_String
end function

Function vb_Pad_Right ( string, length )
   Dim Local_String
   if TypeName ( string ) <> "String" then
      if IsNull ( string ) then
         Local_String = " "
      else
         Local_String = Cstr( string )
      end if
   else
      Local_String = string
   end if

   Local_String = Trim ( Local_String )

   do while len( Local_String ) < length
      Local_String = Local_String & " "
   loop

   vb_Pad_Right = Local_String
end function

Function vb_numberFormat_COMMAS ( Value, DecPts )
   Dim localString
   if not isNumeric ( Value ) then
      vb_numberFormat_COMMAS = ""
   else
      localString     = FormatNumber ( Value,DecPts,-1,0,-1  )
      if left(localString,1) = "." then localString = "0" & localString

      vb_numberFormat_COMMAS = localString
   end if
end Function

Function vb_currencyFormat ( Value, DecPts )
   Dim localString
   localString       = formatCurrency ( Value, DecPts )

   vb_currencyFormat = localString
end Function

Function vb_numberFormat ( Value, DecPts )
   Dim localString
   if not isNumeric ( Value ) then
      vb_numberFormat = ""
   else
      localString     = FormatNumber ( Value,DecPts,0,0,0 )
      if left(localString,1) = "." then localString = "0" & localString

      vb_numberFormat = localString
   end if
end Function

Function vb_dateFormat  ( Value )
   Dim localString
   localString = FormatDateTime ( Value, 0 )
   vb_dateFormat = localString
end Function

Function vb_trimString ( strString )
   Dim localString
   localString    = trim ( strString )
'   localString    = strString

   vb_trimString = localString
end Function

Function nullTest ( Value )
   Dim localString

   if Value = null or Value = "null" or isNull( Value ) = true or isEmpty ( Value ) then
      localString = " "
   else
      localString = Value
   end if

   nullTest = localString
end Function

Function vbConvertDate ( fmMonth, fmDay, fmYear )
   Dim strDate
   strDate = ""
   strDate = DateSerial( fmYear, fmMonth+1, fmDay )

   strDate = FormatDateTime ( strDate,  vbShortDate )
   vbConvertDate = strDate
end Function

Function vbDateAdd ( strDate, strAddType, numAddAmount )
   dim datDate
       datDate = cDate   ( strDate )

   vbDateAdd = dateAdd ( strAddType, numAddAmount, datDate )
end Function

const dateINVALID = -1
const dateEARLIER =  1
const dateEQUAL   =  2
const dateLATER   =  3

'
'  compareDates() --- Date1 is compared to Date2 and one of 3 possible return codes are:
'       dateEARLIER
'       dateEQUAL
'       dateLATER
'
'       dateINVALID is returned if either of the dates is in invalid format
'
function compareDates ( strDate1, strDate2 )
   dim datDate1, datDate2

   if not isDate ( strDate1 ) or not isDate ( strDate2 ) then
      compareDates = dateINVALID
      exit function
   end if

   datDate1 = cDate ( strDate1 )
   datDate2 = cDate ( strDate2 )

   if datDate1 < datDate2 then compareDates = dateEARLIER
   if datDate1 = datDate2 then compareDates = dateEQUAL
   if datDate1 > datDate2 then compareDates = dateLATER

end function

function Substring_Search ( strSourceString, strLookup )
   Dim Result

   Result = instr ( Lcase(strSourceString), strLookup )
   Substring_Search = Result
end function
