[API]
RtlMoveMemory

[CODE]
Public Function HTMLEncode(ByVal OrigText As String) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  
  For xLong1 = 1& To Len(OrigText)
    xChar1 = Mid(OrigText, xLong1, 1&)
    Call RtlMoveMemory(ByVal VarPtr(xLong2), ByVal StrPtr(xChar1), 2&)
    Select Case xLong2
      'Case 96&, 92& ' `\
      '  IsValidForMySQLRow = False
      '  Exit For
      'Case 9&
      '  HTMLEncode = HTMLEncode + "&#09;"
      Case 10&
        HTMLEncode = HTMLEncode + "<br>"
      Case 13&
        If Not Mid(OrigText, xLong1 + 1&, 1&) = Chr(10&) Then
          HTMLEncode = HTMLEncode + "<br>"
          End If
      Case 34&
        HTMLEncode = HTMLEncode + "&quot;"
      Case 38&
        If Mid(OrigText, xLong1 + 1&, 1&) = "#" Then 'And Not IsUnicode Then
          HTMLEncode = HTMLEncode + "&"
          Else
          HTMLEncode = HTMLEncode + "&amp;"
          End If
      'Case 39&: HTMLEncode = HTMLEncode + "''" ''
      'Case 47&: HTMLEncode = HTMLEncode + "&frasl;" '/
      Case 60&: HTMLEncode = HTMLEncode + "&lt;" '<
      Case 62&: HTMLEncode = HTMLEncode + "&gt;" '>
      'Case 92&: HTMLEncode = HTMLEncode + "\\" '\
      
      Case 32 To 126
        HTMLEncode = HTMLEncode + Mid(OrigText, xLong1, 1&)
      
      Case 150&: HTMLEncode = HTMLEncode + "&ndash;"
      Case 151&: HTMLEncode = HTMLEncode + "&mdash;"
      Case 160&: HTMLEncode = HTMLEncode + "&nbsp;"
      Case 161&: HTMLEncode = HTMLEncode + "&iexcl;"
      Case 162&: HTMLEncode = HTMLEncode + "&cent;"
      Case 163&: HTMLEncode = HTMLEncode + "&pound;"
      Case 164&: HTMLEncode = HTMLEncode + "&curren;"
      Case 165&: HTMLEncode = HTMLEncode + "&yen;"
      Case 166&: HTMLEncode = HTMLEncode + "&brvbar;"
      Case 167&: HTMLEncode = HTMLEncode + "&sect;"
      Case 168&: HTMLEncode = HTMLEncode + "&uml;"
      Case 169&: HTMLEncode = HTMLEncode + "&copy;"
      Case 170&: HTMLEncode = HTMLEncode + "&ordf;"
      Case 171&: HTMLEncode = HTMLEncode + "&laquo;"
      Case 172&: HTMLEncode = HTMLEncode + "&not;"
      Case 173&: HTMLEncode = HTMLEncode + "&shy;"
      Case 174&: HTMLEncode = HTMLEncode + "&reg;"
      Case 175&: HTMLEncode = HTMLEncode + "&macr;"
      Case 176&: HTMLEncode = HTMLEncode + "&deg;"
      Case 177&: HTMLEncode = HTMLEncode + "&plusmn;"
      Case 178&: HTMLEncode = HTMLEncode + "&sup2;"
      Case 179&: HTMLEncode = HTMLEncode + "&sup3;"
      Case 180&: HTMLEncode = HTMLEncode + "&acute;"
      Case 181&: HTMLEncode = HTMLEncode + "&micro;"
      Case 182&: HTMLEncode = HTMLEncode + "&para;"
      Case 183&: HTMLEncode = HTMLEncode + "&middot;"
      Case 184&: HTMLEncode = HTMLEncode + "&cedil;"
      Case 185&: HTMLEncode = HTMLEncode + "&sup1;"
      Case 186&: HTMLEncode = HTMLEncode + "&ordm;"
      Case 187&: HTMLEncode = HTMLEncode + "&raquo;"
      Case 188&: HTMLEncode = HTMLEncode + "&frac14;"
      Case 189&: HTMLEncode = HTMLEncode + "&frac12;"
      Case 190&: HTMLEncode = HTMLEncode + "&frac34;"
      Case 191&: HTMLEncode = HTMLEncode + "&iquest;"
      Case 192&: HTMLEncode = HTMLEncode + "&Agrave;"
      Case 193&: HTMLEncode = HTMLEncode + "&Aacute;"
      Case 194&: HTMLEncode = HTMLEncode + "&Acirc;"
      Case 195&: HTMLEncode = HTMLEncode + "&Atilde;"
      Case 196&: HTMLEncode = HTMLEncode + "&Auml;" 'Ä
      Case 197&: HTMLEncode = HTMLEncode + "&Aring;"
      Case 198&: HTMLEncode = HTMLEncode + "&AElig;"
      Case 199&: HTMLEncode = HTMLEncode + "&Ccedil;"
      Case 200&: HTMLEncode = HTMLEncode + "&Egrave;"
      Case 201&: HTMLEncode = HTMLEncode + "&Eacute;"
      Case 202&: HTMLEncode = HTMLEncode + "&Ecirc;"
      Case 203&: HTMLEncode = HTMLEncode + "&Euml;"
      Case 204&: HTMLEncode = HTMLEncode + "&Igrave;"
      Case 205&: HTMLEncode = HTMLEncode + "&Iacute;"
      Case 206&: HTMLEncode = HTMLEncode + "&Icirc;"
      Case 207&: HTMLEncode = HTMLEncode + "&Iuml;"
      Case 208&: HTMLEncode = HTMLEncode + "&ETH;"
      Case 209&: HTMLEncode = HTMLEncode + "&Ntilde;"
      Case 210&: HTMLEncode = HTMLEncode + "&Ograve;"
      Case 211&: HTMLEncode = HTMLEncode + "&Oacute;"
      Case 212&: HTMLEncode = HTMLEncode + "&Ocirc;"
      Case 213&: HTMLEncode = HTMLEncode + "&Otilde;"
      Case 214&: HTMLEncode = HTMLEncode + "&Ouml;" 'Ö
      Case 215&: HTMLEncode = HTMLEncode + "&times;"
      Case 216&: HTMLEncode = HTMLEncode + "&Oslash;"
      Case 217&: HTMLEncode = HTMLEncode + "&Ugrave;"
      Case 218&: HTMLEncode = HTMLEncode + "&Uacute;"
      Case 219&: HTMLEncode = HTMLEncode + "&Ucirc;"
      Case 220&: HTMLEncode = HTMLEncode + "&Uuml;" 'Ü
      Case 221&: HTMLEncode = HTMLEncode + "&Yacute;"
      Case 222&: HTMLEncode = HTMLEncode + "&THORN;"
      Case 223&: HTMLEncode = HTMLEncode + "&szlig;" 'ß
      Case 224&: HTMLEncode = HTMLEncode + "&agrave;"
      Case 225&: HTMLEncode = HTMLEncode + "&aacute;"
      Case 226&: HTMLEncode = HTMLEncode + "&acirc;"
      Case 227&: HTMLEncode = HTMLEncode + "&atilde;"
      Case 228&: HTMLEncode = HTMLEncode + "&auml;" 'ä
      Case 229&: HTMLEncode = HTMLEncode + "&aring;"
      Case 230&: HTMLEncode = HTMLEncode + "&aelig;"
      Case 231&: HTMLEncode = HTMLEncode + "&ccedil;"
      Case 232&: HTMLEncode = HTMLEncode + "&egrave;"
      Case 233&: HTMLEncode = HTMLEncode + "&eacute;"
      Case 234&: HTMLEncode = HTMLEncode + "&ecirc;"
      Case 235&: HTMLEncode = HTMLEncode + "&euml;"
      Case 236&: HTMLEncode = HTMLEncode + "&igrave;"
      Case 237&: HTMLEncode = HTMLEncode + "&iacute;"
      Case 238&: HTMLEncode = HTMLEncode + "&icirc;"
      Case 239&: HTMLEncode = HTMLEncode + "&iuml;"
      Case 240&: HTMLEncode = HTMLEncode + "&eth;"
      Case 241&: HTMLEncode = HTMLEncode + "&ntilde;"
      Case 242&: HTMLEncode = HTMLEncode + "&ograve;"
      Case 243&: HTMLEncode = HTMLEncode + "&oacute;"
      Case 244&: HTMLEncode = HTMLEncode + "&ocirc;"
      Case 245&: HTMLEncode = HTMLEncode + "&otilde;"
      Case 246&: HTMLEncode = HTMLEncode + "&ouml;" 'ö
      Case 247&: HTMLEncode = HTMLEncode + "&divide;"
      Case 248&: HTMLEncode = HTMLEncode + "&oslash;"
      Case 249&: HTMLEncode = HTMLEncode + "&ugrave;"
      Case 250&: HTMLEncode = HTMLEncode + "&uacute;"
      Case 251&: HTMLEncode = HTMLEncode + "&ucirc;"
      Case 252&: HTMLEncode = HTMLEncode + "&uuml;" 'ü
      Case 253&: HTMLEncode = HTMLEncode + "&yacute;"
      Case 254&: HTMLEncode = HTMLEncode + "&thorn;"
      Case 255&: HTMLEncode = HTMLEncode + "&yuml;"
      
      Case 402&: HTMLEncode = HTMLEncode + "&fnof;"
      Case 913&: HTMLEncode = HTMLEncode + "&Alpha;"
      Case 914&: HTMLEncode = HTMLEncode + "&Beta;"
      Case 915&: HTMLEncode = HTMLEncode + "&Gamma;"
      Case 916&: HTMLEncode = HTMLEncode + "&Delta;"
      Case 917&: HTMLEncode = HTMLEncode + "&Epsilon;"
      Case 918&: HTMLEncode = HTMLEncode + "&Zeta;"
      Case 919&: HTMLEncode = HTMLEncode + "&Eta;"
      Case 920&: HTMLEncode = HTMLEncode + "&Theta;"
      Case 921&: HTMLEncode = HTMLEncode + "&Iota;"
      Case 922&: HTMLEncode = HTMLEncode + "&Kappa;"
      Case 923&: HTMLEncode = HTMLEncode + "&Lambda;"
      Case 924&: HTMLEncode = HTMLEncode + "&Mu;"
      Case 925&: HTMLEncode = HTMLEncode + "&Nu;"
      Case 926&: HTMLEncode = HTMLEncode + "&Xi;"
      Case 927&: HTMLEncode = HTMLEncode + "&Omicron;"
      Case 928&: HTMLEncode = HTMLEncode + "&Pi;"
      Case 929&: HTMLEncode = HTMLEncode + "&Rho;"
      Case 931&: HTMLEncode = HTMLEncode + "&Sigma;"
      Case 932&: HTMLEncode = HTMLEncode + "&Tau;"
      Case 933&: HTMLEncode = HTMLEncode + "&Upsilon;"
      Case 934&: HTMLEncode = HTMLEncode + "&Phi;"
      Case 935&: HTMLEncode = HTMLEncode + "&Chi;"
      Case 936&: HTMLEncode = HTMLEncode + "&Psi;"
      Case 937&: HTMLEncode = HTMLEncode + "&Omega;"
      Case 945&: HTMLEncode = HTMLEncode + "&alpha;"
      Case 946&: HTMLEncode = HTMLEncode + "&beta;"
      Case 947&: HTMLEncode = HTMLEncode + "&gamma;"
      Case 948&: HTMLEncode = HTMLEncode + "&delta;"
      Case 949&: HTMLEncode = HTMLEncode + "&epsilon;"
      Case 950&: HTMLEncode = HTMLEncode + "&zeta;"
      Case 951&: HTMLEncode = HTMLEncode + "&eta;"
      Case 952&: HTMLEncode = HTMLEncode + "&theta;"
      Case 953&: HTMLEncode = HTMLEncode + "&iota;"
      Case 954&: HTMLEncode = HTMLEncode + "&kappa;"
      Case 955&: HTMLEncode = HTMLEncode + "&lambda;"
      Case 956&: HTMLEncode = HTMLEncode + "&mu;"
      Case 957&: HTMLEncode = HTMLEncode + "&nu;"
      Case 958&: HTMLEncode = HTMLEncode + "&xi;"
      Case 959&: HTMLEncode = HTMLEncode + "&omicron;"
      Case 960&: HTMLEncode = HTMLEncode + "&pi;"
      Case 961&: HTMLEncode = HTMLEncode + "&rho;"
      Case 962&: HTMLEncode = HTMLEncode + "&sigmaf;"
      Case 963&: HTMLEncode = HTMLEncode + "&sigma;"
      Case 964&: HTMLEncode = HTMLEncode + "&tau;"
      Case 965&: HTMLEncode = HTMLEncode + "&upsilon;"
      Case 966&: HTMLEncode = HTMLEncode + "&phi;"
      Case 967&: HTMLEncode = HTMLEncode + "&chi;"
      Case 968&: HTMLEncode = HTMLEncode + "&psi;"
      Case 969&: HTMLEncode = HTMLEncode + "&omega;"
      Case 977&: HTMLEncode = HTMLEncode + "&thetasym;"
      Case 978&: HTMLEncode = HTMLEncode + "&upsih;"
      Case 982&: HTMLEncode = HTMLEncode + "&piv;"
      
      Case 8194&: HTMLEncode = HTMLEncode + "&ensp;"
      Case 8195&: HTMLEncode = HTMLEncode + "&emsp;"
      Case 8201&: HTMLEncode = HTMLEncode + "&thinsp;"
      Case 8204&: HTMLEncode = HTMLEncode + "&zwnj;"
      Case 8205&: HTMLEncode = HTMLEncode + "&zwj;"
      Case 8206&: HTMLEncode = HTMLEncode + "&lrm;"
      Case 8207&: HTMLEncode = HTMLEncode + "&rlm;"

      Case 8211&: HTMLEncode = HTMLEncode + "&ndash;"
      Case 8212&: HTMLEncode = HTMLEncode + "&mdash;"
      
      Case 8216&: HTMLEncode = HTMLEncode + "&lsquo;"
      Case 8217&: HTMLEncode = HTMLEncode + "&rsquo;"
      Case 8218&: HTMLEncode = HTMLEncode + "&sbquo;"
      
      Case 8220&: HTMLEncode = HTMLEncode + "&ldquo;" ' special ""s
      Case 8221&: HTMLEncode = HTMLEncode + "&rdquo;" ' special ""s
      Case 8222&: HTMLEncode = HTMLEncode + "&bdquo;"
      Case 8224&: HTMLEncode = HTMLEncode + "&dagger;"
      Case 8225&: HTMLEncode = HTMLEncode + "&Dagger;"
      Case 8226&: HTMLEncode = HTMLEncode + "&bull;"
      Case 8230&: HTMLEncode = HTMLEncode + "&hellip;"
      Case 8240&: HTMLEncode = HTMLEncode + "&permil;"
      Case 8242&: HTMLEncode = HTMLEncode + "&prime;"
      Case 8243&: HTMLEncode = HTMLEncode + "&Prime;"
      Case 8249&: HTMLEncode = HTMLEncode + "&lsaquo;"
      Case 8250&: HTMLEncode = HTMLEncode + "&rsaquo;"
      Case 8254&: HTMLEncode = HTMLEncode + "&oline;"
      Case 8260&: HTMLEncode = HTMLEncode + "&frasl;"
      Case 8364&: HTMLEncode = HTMLEncode + "&euro;"
      Case 8465&: HTMLEncode = HTMLEncode + "&image;"
      Case 8472&: HTMLEncode = HTMLEncode + "&weierp;"
      Case 8476&: HTMLEncode = HTMLEncode + "&real;"
      Case 8482&: HTMLEncode = HTMLEncode + "&trade;"
      Case 8501&: HTMLEncode = HTMLEncode + "&alefsym;"
      Case 8592&: HTMLEncode = HTMLEncode + "&larr;"
      Case 8593&: HTMLEncode = HTMLEncode + "&uarr;"
      Case 8594&: HTMLEncode = HTMLEncode + "&rarr;"
      Case 8595&: HTMLEncode = HTMLEncode + "&darr;"
      Case 8596&: HTMLEncode = HTMLEncode + "&harr;"
      Case 8629&: HTMLEncode = HTMLEncode + "&carr;"
      Case 8656&: HTMLEncode = HTMLEncode + "&lArr;"
      Case 8657&: HTMLEncode = HTMLEncode + "&uArr;"
      Case 8658&: HTMLEncode = HTMLEncode + "&rArr;"
      Case 8659&: HTMLEncode = HTMLEncode + "&dArr;"
      Case 8660&: HTMLEncode = HTMLEncode + "&hArr;"
      
      Case 8704&: HTMLEncode = HTMLEncode + "&forall;"
      Case 8706&: HTMLEncode = HTMLEncode + "&part;"
      Case 8707&: HTMLEncode = HTMLEncode + "&exist;"
      Case 8709&: HTMLEncode = HTMLEncode + "&empty;"
      Case 8711&: HTMLEncode = HTMLEncode + "&nabla;"
      Case 8712&: HTMLEncode = HTMLEncode + "&isin;"
      Case 8713&: HTMLEncode = HTMLEncode + "&notin;"
      Case 8715&: HTMLEncode = HTMLEncode + "&ni;"
      Case 8719&: HTMLEncode = HTMLEncode + "&prod;"
      Case 8721&: HTMLEncode = HTMLEncode + "&sum;"
      Case 8722&: HTMLEncode = HTMLEncode + "&minus;"
      Case 8727&: HTMLEncode = HTMLEncode + "&lowast;"
      Case 8730&: HTMLEncode = HTMLEncode + "&radic;"
      Case 8733&: HTMLEncode = HTMLEncode + "&prop;"
      Case 8734&: HTMLEncode = HTMLEncode + "&infin;"
      Case 8736&: HTMLEncode = HTMLEncode + "&ang;"
      Case 8743&: HTMLEncode = HTMLEncode + "&and;"
      Case 8744&: HTMLEncode = HTMLEncode + "&or;"
      Case 8745&: HTMLEncode = HTMLEncode + "&cap;"
      Case 8746&: HTMLEncode = HTMLEncode + "&cup;"
      Case 8747&: HTMLEncode = HTMLEncode + "&int;"
      Case 8756&: HTMLEncode = HTMLEncode + "&there4;"
      Case 8764&: HTMLEncode = HTMLEncode + "&sim;"
      Case 8773&: HTMLEncode = HTMLEncode + "&cong;"
      Case 8776&: HTMLEncode = HTMLEncode + "&asymp;"
      Case 8800&: HTMLEncode = HTMLEncode + "&ne;"
      Case 8801&: HTMLEncode = HTMLEncode + "&equiv;"
      Case 8804&: HTMLEncode = HTMLEncode + "&le;"
      Case 8805&: HTMLEncode = HTMLEncode + "&ge;"
      Case 8834&: HTMLEncode = HTMLEncode + "&sub;"
      Case 8835&: HTMLEncode = HTMLEncode + "&sup;"
      Case 8836&: HTMLEncode = HTMLEncode + "&nsub;"
      Case 8838&: HTMLEncode = HTMLEncode + "&sube;"
      Case 8839&: HTMLEncode = HTMLEncode + "&supe;"
      Case 8853&: HTMLEncode = HTMLEncode + "&oplus;"
      Case 8855&: HTMLEncode = HTMLEncode + "&otimes;"
      Case 8869&: HTMLEncode = HTMLEncode + "&perp;"
      ''' wrong / reused! Case 8870&: HTMLEncode = HTMLEncode + "&or;"
      
      Case 8901&: HTMLEncode = HTMLEncode + "&sdot;"
      Case 8968&: HTMLEncode = HTMLEncode + "&lceil;"
      Case 8969&: HTMLEncode = HTMLEncode + "&rceil;"
      Case 8970&: HTMLEncode = HTMLEncode + "&lfloor;"
      Case 8971&: HTMLEncode = HTMLEncode + "&rfloor;"
      Case 9001&: HTMLEncode = HTMLEncode + "&lang;"
      Case 9002&: HTMLEncode = HTMLEncode + "&rang;"
      Case 9674&: HTMLEncode = HTMLEncode + "&loz;"
      Case 9824&: HTMLEncode = HTMLEncode + "&spades;"
      Case 9827&: HTMLEncode = HTMLEncode + "&clubs;"
      Case 9829&: HTMLEncode = HTMLEncode + "&hearts;"
      Case 9830&: HTMLEncode = HTMLEncode + "&diams;"
      Case 0& To 9&
        HTMLEncode = HTMLEncode + "&#0" + CStr(xLong2) + ";"
      Case Else
        HTMLEncode = HTMLEncode + "&#" + CStr(xLong2) + ";"
      End Select
    Next
  End Function
