Private Sub Form_Load()
Text1.Text = "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
有没有高手帮忙解释一下,怎么才能生成汉字二维码?
运行英文时,二维码扫描正常。运行中文字符是,二维码扫描时乱码。
跪求高手帮助。
5 个解决方案
#1
帮助手册里怎么说明的,InputDataB 不是应该传 gb2312 编码吗?猜测是
QRmaker1.InputDataB = StrConv(Text1.Text, vbFromUnicode)
#2
它的帮助手册里的示例代码,是直接使用VB的String变量值,没有StrConv( )转换呢。
不知道楼主是用什么扫的码啊,是不是“编码格式不兼容”造成的呢?
#3
乱码最主要是扫描部分,是否支持中文?是否设置了对应的编码(GB2312、UTF-16)?
#4
vb及vb从Excel里取的文本用的Unicode编码 中英文每个字符都占2个字节,直接扔到InputData里的变量疑似用ANSI编码,英文1字节中文2字节,没指定语言的ANSI解析很混乱,测试很多读二维码的应用是按 UTF-8 解码,英文1字节中文3字节,在网上找了个转UTF8字节数组的脚本,传到InputDataB里 问题解决~ 附赠VBA可用的UTF8编码解码脚本,来源不明。
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)
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 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 <> 0 Then
lngResult = lngResult - 1
ReDim Preserve bytUtf8(lngResult)
End If
UTF8_Encode = bytUtf8
End Function
Public Function UTF8_Decode(ByRef bUTF8() As Byte) As String
'UTF-8 解码
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 Exit Function
lBufferSize = lLen * 2
sBuffer = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(bUTF8(0)), lLen, StrPtr(sBuffer), lBufferSize)
If lRet <> 0 Then
sBuffer = Left(sBuffer, lRet)
End If
UTF8_Decode = sBuffer
End Function
#5
对电脑而言没有乱码,只有二进制字节;对人脑才有乱码。啊 GBK:0xB0 0xA1,Unicode-16 LE:0x4A 0x55,Unicode-16 BE:0x55 0x4A,UTF-8:0xE5 0x95 0x8A
#1
帮助手册里怎么说明的,InputDataB 不是应该传 gb2312 编码吗?猜测是
QRmaker1.InputDataB = StrConv(Text1.Text, vbFromUnicode)
#2
它的帮助手册里的示例代码,是直接使用VB的String变量值,没有StrConv( )转换呢。
不知道楼主是用什么扫的码啊,是不是“编码格式不兼容”造成的呢?
#3
乱码最主要是扫描部分,是否支持中文?是否设置了对应的编码(GB2312、UTF-16)?
#4
vb及vb从Excel里取的文本用的Unicode编码 中英文每个字符都占2个字节,直接扔到InputData里的变量疑似用ANSI编码,英文1字节中文2字节,没指定语言的ANSI解析很混乱,测试很多读二维码的应用是按 UTF-8 解码,英文1字节中文3字节,在网上找了个转UTF8字节数组的脚本,传到InputDataB里 问题解决~ 附赠VBA可用的UTF8编码解码脚本,来源不明。
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)
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 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 <> 0 Then
lngResult = lngResult - 1
ReDim Preserve bytUtf8(lngResult)
End If
UTF8_Encode = bytUtf8
End Function
Public Function UTF8_Decode(ByRef bUTF8() As Byte) As String
'UTF-8 解码
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 Exit Function
lBufferSize = lLen * 2
sBuffer = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(bUTF8(0)), lLen, StrPtr(sBuffer), lBufferSize)
If lRet <> 0 Then
sBuffer = Left(sBuffer, lRet)
End If
UTF8_Decode = sBuffer
End Function
#5
对电脑而言没有乱码,只有二进制字节;对人脑才有乱码。啊 GBK:0xB0 0xA1,Unicode-16 LE:0x4A 0x55,Unicode-16 BE:0x55 0x4A,UTF-8:0xE5 0x95 0x8A