Solved

DHTML Edit control with HTML character references (unicode)

Posted on 2001-09-14
7
251 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 66
Macro which automatically sends attachment to Outlook 14 52
VB 6.0 printer how to align 6 50
using Access 8 53
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now