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
Solved

DHTML Edit control with HTML character references (unicode)

Posted on 2001-09-14
7
260 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

860 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