Solved

DHTML Edit control with HTML character references (unicode)

Posted on 2001-09-14
7
267 Views
Last Modified: 2008-02-20
I have a database with strings in (Oracle VARCHAR2), which include HTML character references to Unicode characters (e.g. "Γ" for a capital Gamma). (Note, that means the string contains the ASCII sequence mentioned above, not any Unicode characters.)

I can assign this string to DHTMLEditControl1.DocumentHTML, and it displays correctly in the edit control.

The problem is, I want the user to edit the text (not necessarily the Greek bit), so later on I assign the DocumentHTML property back to the string in order to save it to the database again. At that point, the non-ASCII characters are replaced with ?, even though the control has helpfully prepended a META statement indicating that the charset is unicode.

I get the same thing if I use DocumentSave & write it to a file.

Any suggestions? Is there a flag I can set, or another property I can examine? Should I switch to handling the whole string as Unicode? If so, I'd like some pointers about that, because my VB help seems rather ambivalent about the subject!

Using Visual Basic/Studio 6, I can try inspect the DocumentHTML property, and the characters appear to already be ?s before the assignment. I'm not sure how the edit control manages to display them correctly?
0
Comment
Question by:peterp
[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
7 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6483289
You may try using the StrConv function, e.g.,

'editing...
strHTML = StrConv(DHTMLEditControl1.DocumentHTML, vbUnicode)
0
 

Author Comment

by:peterp
ID: 6487517
Thanks for that, AzraSound. I can now get "real Unicode" in my strings (i.e not HTML character references).

My problem then moves on: how to display these Unicode strings? Neither a text box nor the DHTML edit control display them correctly. This is presumably because VB "helpfully" converts the strings to ASCCI before passing them to the DLL. (This is inspite of the fact that both VB & WinNT use Unicode for their internal strings). Is there any way I can turn this conversion off - for the project, for a target DLL, or even just for a particular call?

(Note: my last paragraph in the question is a red herring; the characters appear as ?s because the watch & immediate windows in Visual Studio are subject to the same conversions)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6488008
Well, if the text box or DHTML edit control want Ascii, go ahead and give it to them.  You can use the StrConv function to go to and from Ascii and Unicode using the vbUnicode and vbFromUnicode constants in the function call.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:peterp
ID: 6489830
Tried that - the problem is that vbFromUnicode function works as I mentioned above. Alternate bytes are simply stripped off, leaving a mixture of some bytes which are displayed as ASCII characters, with others as question marks.

What I want is to display the actual characters. Unicode is supposed to be the native character set of NT, and is an acceptable character set & encoding for SGML & therefore HTML documents. So, I assumed it would be straight forward to use it.

So, thanks, but I really don't want to convert my string from Unicode to ASCII. If I directly call Windows API functions, I can go for the "wide" character ones. I was just hoping there was a way to use the Unicode with the controls, otherwise I may as well drop this experiment in VB & return to a language which gives me closer control (& requires me to increase my effort estimates!)
0
 

Author Comment

by:peterp
ID: 6493502
For anyone interested, I have worked around this by storing HTML Character References in an ASCII character set, instead of real Unicode.

The VB internal strings are Unicode, even though you don't normally see them as such. The following fragment translates a string S$ to another string Out$ which contains ASCII & HTML Character Refs:

Out$ = ""
For i% = 1 To Len(S$)
  c$ = Mid$(S$, i%, 1)
  u% = AscW(c$)
  If (u% <= 255) Then
    out$ = out$ & c$
  Else ' these are the two bytes ones, to be encoded
    out$ = out$ & "&#" & CStr(u%) & ";"
  End If
Next i%

I'm sure experts could write it better, but it works. Out$ can be displayed properly in the DHTMLEdit control.

Peter
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7208423
peterp@devx, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7241233
Per recommendation, points refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

724 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