Improve company productivity with a Business Account.Sign Up

x
?
Solved

Inet.openurl arabic character into db

Posted on 2008-06-17
8
Medium Priority
?
644 Views
Last Modified: 2013-12-25
How can i grab arabic character from a UTF-8 pages into VB keeping the right character.
Currently i receive some square using inet.openurl.

Then i need to store them into MsSQL or MySQL.
0
Comment
Question by:mammouth
  • 3
  • 3
6 Comments
 
LVL 22

Accepted Solution

by:
danaseaman earned 375 total points
ID: 21807736
You need to convert the UTF-8 to UTF-16 and use Unicode aware controls such as Forms 2.0 Object Library.

Attached is code to convert UTF-8 to UTF-16 (DecodeUTF8)  and a Unicode aware ShellMsgBox to verify that the conversion is working OK.
Option Explicit
 
Private Const CP_ACP    As Long = 0
Private Const CP_UTF8   As Long = 65001
 
Private Declare Function GetACP Lib "kernel32" () As Long
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, lpUsedDefaultChar As Long) As Long
 
Public Function DecodeUTF8(ByVal cnvUni As String) As String
   If Len(cnvUni) Then
      DecodeUTF8 = A8ToW(WToA(cnvUni))
   End If
End Function
 
Private Function A8ToW(ByVal st As String, Optional lFlags As Long = 0) As String
   Dim stBuffer         As String
   Dim cwch             As Long
   Dim pwz              As Long
   Dim pwzBuffer        As Long
 
   pwz = StrPtr(st)
   cwch = MultiByteToWideChar(CP_UTF8, lFlags, pwz, -1, 0&, 0&)
   stBuffer = String$(cwch + 1, vbNullChar)
   pwzBuffer = StrPtr(stBuffer)
   cwch = MultiByteToWideChar(CP_UTF8, lFlags, pwz, -1, pwzBuffer, Len(stBuffer))
   A8ToW = Left$(stBuffer, cwch - 1)
End Function
 
Private Function WToA(ByVal st As String, Optional ByVal cpg As Long = 1252, Optional lFlags As Long = 0) As String
   Dim stBuffer         As String
   Dim cwch             As Long
   Dim pwz              As Long
   Dim pwzBuffer        As Long
   Dim lpUsedDefaultChar As Long
 
   If cpg = -1 Then cpg = GetACP()
   pwz = StrPtr(st)
   cwch = WideCharToMultiByte(cpg, lFlags, pwz, -1, 0&, 0&, ByVal 0&, ByVal 0&)
   stBuffer = String$(cwch + 1, vbNullChar)
   pwzBuffer = StrPtr(stBuffer)
   cwch = WideCharToMultiByte(cpg, lFlags, pwz, -1, pwzBuffer, Len(stBuffer), ByVal 0&, ByVal 0&)
   WToA = Left$(stBuffer, cwch - 1)
End Function
 
Function ShellMsgBox(ByVal sPrompt As String, _
   Optional ByVal sTitle As String, _
   Optional lFlags As VbMsgBoxStyle = vbOKCancel Or vbInformation, _
   Optional lTimeOut As Long = 0) As VbMsgBoxResult
   
   Dim WshShell As Object
   Set WshShell = CreateObject("WScript.Shell")
   ShellMsgBox = WshShell.Popup(sPrompt, lTimeOut, sTitle, lFlags)
   Set WshShell = Nothing
End Function

Open in new window

0
 
LVL 1

Author Comment

by:mammouth
ID: 21834356
It's work, but when i retrieve them from mssql or mysql (varchar) thet loose all their character.
For example Bdgh+s become Badghis.

0
 
LVL 1

Author Comment

by:mammouth
ID: 21997492
21807736 works for 50% of the problem. When i retrive them from mysql varchar, it loose all special character. As in db it stored like that: Bdgh+s
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
LVL 22

Expert Comment

by:danaseaman
ID: 21998674
Have you set CHARSET correctly in MySQL?
Is it UTF8 or UTF16?
More info:
http://dev.mysql.com/doc/refman/6.0/en/charset-unicode.html
0
 
LVL 1

Author Comment

by:mammouth
ID: 22007524
Will UTF16 only be available in MySQL 6 ?
0
 
LVL 22

Expert Comment

by:danaseaman
ID: 22011588
Yes. MySQL 4.1 only supports UTF8 and UCS2.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
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…
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…

579 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