Home > Software engineering >  VB calls QRmaker controls generated qr code of Chinese characters in the code
VB calls QRmaker controls generated qr code of Chinese characters in the code

Time:09-18

Option Explicit

Private Sub Form_Load ()
Text1. Text="both please input your Text to be converted"
End Sub

Private Sub Text1_click ()
Text1. Text=""
End Sub


Private Sub Text1_change ()
QRmaker1. InputDataB=Text1. Text
End Sub
Have expert help explain how to generate qr code of Chinese characters?
Run run English, qr code scanning is normal, is Chinese characters, the qr code scanning gibberish,
Expert help, genuflect is begged

CodePudding user response:

How to explain, in the help manual InputDataB should not preach gb2312 encoding? Speculation is
 QRmaker1. InputDataB=StrConv (Text1. Text, vbFromUnicode) 

CodePudding user response:

reference 1st floor Tiger_Zhao response:
how help manual, instructions, InputDataB should not preach gb2312 encoding? Speculation is
 QRmaker1. InputDataB=StrConv (Text1. Text, vbFromUnicode) 

It help the sample code in the manual, it is directly using the VB String variable values, no StrConv () conversion,
Don't know what the original poster is sweep of code, whether caused by "coding format is not compatible"?

CodePudding user response:

The most important part is to scan the statement, whether to support Chinese? Whether to set up the corresponding coding (UTF, GB2312-16)?

CodePudding user response:

Vb and vb from Excel in text with Unicode in both Chinese and English accounts for each character is 2 bytes, directly into the variables in the InputData suspected with ANSI code, English 1 byte Chinese 2 bytes, didn't specify the language of ANSI parsing is chaotic, test a lot of what the application of qr code is according to utf-8 decoding, English 1 byte Chinese 3 bytes, turn on the Internet to find a UTF8 byte array script, to problem solving in InputDataB ~ with VBA UTF8 encoding decoding scripts are available, and source,
 
Option Explicit

Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) 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 Const CP_UTF8=65001
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any Source, As Any, ByVal Length As Long)



The Public Function UTF8_Encode (ByVal strUnicode As String) As Byte ()
'utf-8

Dim TLen As Long
Dim lngBufferSize As Long
Dim lngResult As Long
Dim bytUtf8 () As Byte

TLen=Len (strUnicode)
If TLen=0 Then the Exit Function

LngBufferSize=TLen * 3 + 1
ReDim bytUtf8 (lngBufferSize - 1)

LngResult=WideCharToMultiByte (CP_UTF8, 0, StrPtr (strUnicode), TLen, bytUtf8 (0), lngBufferSize, vbNullString, 0)

If lngResult & lt;> 0 Then
LngResult=lngResult - 1
ReDim Preserve bytUtf8 (lngResult)
End the If

UTF8_Encode=bytUtf8
End the Function

The Public Function UTF8_Decode (ByRef bUTF8 () As Byte) As String
'utf-8 decoding
Dim lRet As Long
Dim lLen As Long
Dim lBufferSize As Long
Dim sBuffer As String
Dim bBuffer () As Byte

LLen=UBound (bUTF8) + 1

If lLen=0 Then the Exit Function

LBufferSize lLen * 2=

SBuffer=String $(lBufferSize, CRH (0))

LRet=MultiByteToWideChar (CP_UTF8, 0, VarPtr (bUTF8 (0)), lLen, StrPtr (sBuffer), lBufferSize)

If lRet & lt;> 0 Then
SBuffer=Left (sBuffer lRet)
End the If

UTF8_Decode=sBuffer
End the Function

CodePudding user response:

For computer no noise, only the binary bytes; To the human brain is gibberish, GBK: 0 xb0 0 xa1, Unicode - 16 LE: 0 x4a 0 x55, Unicode - 16 BE: 0 x55 0 x4a, utf-8 8-0 x95 xE5 0 0 x8a
  • Related