Solved

Text To Html

Posted on 1998-01-04
4
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 9 hours left to enroll

636 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