Inet.openurl arabic character into db

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.
LVL 1
mammouthAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

danaseamanCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mammouthAuthor Commented:
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
mammouthAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

danaseamanCommented:
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
mammouthAuthor Commented:
Will UTF16 only be available in MySQL 6 ?
0
danaseamanCommented:
Yes. MySQL 4.1 only supports UTF8 and UCS2.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.