Solved

DHTML Edit control with HTML character references (unicode)

Posted on 2001-09-14
7
257 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
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 76
VBA Word macro - how to get characters after the searched for string 5 84
VB 6.0 printer how to align 6 62
Windows 10 start screen issues 9 55
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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