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

':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
':::                                                             :::
':::  Functions to convert two bytes to a numeric value (long)   :::
':::  (both little-endian and big-endian)                        :::
':::                                                             :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Function lngConvert  ( strTemp )
   lngConvert  = cLng (  asc ( left (strTemp, 1))        + _
                      ( (asc ( right(strTemp, 1)) * 256) ) )
End Function

Function lngConvert2 ( strTemp )
   lngConvert2 = cLng (  asc(right(strTemp, 1))          + _
                      ( (asc(left (strTemp, 1)) * 256) ) )
End Function

Function VB_Determine_JPG_Properties ( flnm )
   dim strBuff

   VB_Determine_JPG_Properties = False

   numGR_w = 0
   numGR_h = 0

   strBuff   = JS_GetBytes(flnm, 0, -1)		' Get all bytes from file
   lngSize   = len(strBuff)
   flgFound  = 0

   strTarget = chr(255) & chr(216) & chr(255)
   flgFound  = instr(strBuff, strTarget)

   if flgFound = 0 then
      exit function
   end if

   strImageType = "JPG"
   lngPos       = flgFound + 2
   ExitLoop     = false

   do while ExitLoop = False and lngPos < lngSize
      do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize
         lngPos = lngPos + 1
      loop

      if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then
         lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))
         lngPos        = lngPos + lngMarkerSize  + 1
      else
         ExitLoop = True
      end if

   loop

   if ExitLoop = False then
      numGR_w = -1
      numGR_h = -1
   else
      numGR_w = lngConvert2 ( mid ( strBuff, lngPos + 6, 2 ) )
      numGR_h = lngConvert2 ( mid ( strBuff, lngPos + 4, 2 ) )

      VB_Determine_JPG_Properties = True
   end if

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
   if not isNull ( Value ) and not Value = "" then
      localString = FormatDateTime ( Value, 0 )
   else
      localString = ""
   end if

   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

function vbZero_Fill ( strString, numLength )
   dim strResult

   strResult = strString

   do while ( len( strResult ) < numLength )
      strResult = "0" & strResult
   loop

   vbZero_Fill = strResult
end function

function vbStringDateFormat ( strDate )
   dim strResults
   dim datDate
   dim numMonth
   dim numDay
   dim numYear

   datDate = cDate ( strDate )
   if not isDate ( datDate ) then
      vbStringDateFormat = ""
      exit function
   end if

   numMonth = month( datDate )
   numDay   = day  ( datDate )
   numYear  = year ( datDate )

   strResults = vbZero_Fill ( numMonth, 2 ) & "/" & vbZero_Fill ( numDay, 2 ) & "/" & numYear

   vbStringDateFormat = strResults
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
