Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Text To Html

The following code is working proberly. The only problem is that if a string is 20 chars long, this function will only return the 20 first chars of the translated string.

Example:
Input  = "der var en gang"
Output = "der var&nb"


Function TextAsHTML2(TextToConvert As String)
 Dim N, I As Long
 Dim FoundOne As Boolean
 Dim ExtChar, HTML As Variant
 Dim strTextBuffer As String
 '
 'Special
 'Ext Lowercase
 'Ext Uppercase
 HTML = Array("­", " ", "©", "®", "™", "—", "–", "¹", "²", "³", "¶", "·", "«", "»", "¼", "½", "¾", "£", _
              "á", "â", "æ", "à", "å", "ã", "ä", "ç", "é", "ê", "è", "ð", "ë", "í", "î", "ì", "ï", "ñ", "ó", "ô", "ò", "ø", "õ", "ö", "ß", "þ", "ú", "û", "ù", "ü", "ý", "ÿ", _
              "Á", "Â", "Æ", "À", "Å", "Ã", "Ä", "Ç", "Ð", "É", "Ê", "È", "Ë", "Í", "Î", "Ì", "Ï", "Ñ", "Ó", "Ô", "Ò", "Ø", "Õ", "Ö", "Þ", "Ú", "Û", "Ù", "Ü", "Ý")
 '
 ExtChar = Array("shy", "nbsp", "copy", "#174", "#153", "#151", "#150", "#185", "#178", "#179", "#182", "#183", "#171", "#187", "#188", "#189", "#190", "#163", _
                 "aacute", "acirc", "aelig", "agrave", "aring", "atilde", "auml", "ccedil", "eacute", "ecirc", "egrave", "eth", "euml", "iacute", "icirc", "igrave", "iuml", "ntilde", "oacute", "ocirc", "ograve", "oslash", "otilde", "ouml", "szlig", "thorn", "uacute", "ucirc", "ugrave", "uuml", "yacute", "yuml", _
                 "Aacute", "Acirc", "AElig", "Agrave", "Aring", "Atilde", "Auml", "Ccedil", "ETH", "Eacute", "Ecirc", "Egrave", "Euml", "Iacute", "Icirc", "Igrave", "Iuml", "Ntilde", "Oacute", "Ocirc", "Ograve", "Oslash", "Otilde", "Ouml", "THORN", "Uacute", "Ucirc", "Ugrave", "Uuml", "Yacute")
 '
 strTextBuffer = ""
 '
 For I = 1 To Len(TextToConvert)
  FoundOne = False
  For N = 1 To UBound(HTML)
   If Mid(TextToConvert, I, 1) = HTML(N) Then
     strTextBuffer = strTextBuffer & "&" & ExtChar(N) & ";"
     FoundOne = True
     Exit For  'no reason to continue if we find one.
   End If
  Next N
  If Not FoundOne Then strTextBuffer = strTextBuffer & Mid(TextToConvert, I, 1)
 Next I
 '
 TextAsHTML2 = strTextBuffer
 '
End Function
0
jfl
Asked:
jfl
  • 2
  • 2
1 Solution
 
mrmickCommented:
Your function works fine.  Try this, put at the beginning of  the Form_Load event of the main form:

   Debug.Print TextAsHTML2("der var en gang")
   Stop

and test...
0
 
jflAuthor Commented:
I tried that, but I only get "Stop statement encountered" from a message box.
0
 
mrmickCommented:
The answer is in your immeadiate window!

Try this instead then:

MsgBox "The HTML is:" & TextAsHTML2("der var en gang")

0
 
jflAuthor Commented:
Thanks!

I have one comment, if anyone would like to use the code don't make it replace your " " with " ". Your webpage will look very funny!

Are you always online mrmick?

I have posted a new question called "SearchWords".
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now