Solved

Inet.openurl arabic character into db

Posted on 2008-06-17
8
561 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 22

Expert Comment

by:danaseaman
Comment Utility
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
Comment Utility
Will UTF16 only be available in MySQL 6 ?
0
 
LVL 22

Expert Comment

by:danaseaman
Comment Utility
Yes. MySQL 4.1 only supports UTF8 and UCS2.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

728 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

9 Experts available now in Live!

Get 1:1 Help Now