Solved

Inet.openurl arabic character into db

Posted on 2008-06-17
8
594 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
8 Comments
 
LVL 22

Accepted Solution

by:
danaseaman earned 125 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
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…

856 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