Solved

Text To Html

Posted on 1998-01-04
4
211 Views
Last Modified: 2012-06-27
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
Comment
Question by:jfl
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:mrmick
ID: 1449165
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
 

Author Comment

by:jfl
ID: 1449166
I tried that, but I only get "Stop statement encountered" from a message box.
0
 
LVL 8

Accepted Solution

by:
mrmick earned 20 total points
ID: 1449167
The answer is in your immeadiate window!

Try this instead then:

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

0
 

Author Comment

by:jfl
ID: 1449168
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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now