今天终于看到样书,很高兴。 技巧235中提供了一个使用MultiByteToWideChar函数来转换网页中文编码的代码(第431页),原以为httpRequest对象的responseBody属性是一个Variant类型的数组,便使用了一个非常笨的循环来转换该属性表示的数组为Byte数组。 For l=0 To UBound(httpRequest.responseBody) arrByte(l)=httpRequest.responseBody(l) Next l 多谢狼版的帖子,发现responseBody实际上就是一个Byte类型数组。这样其实很简单的赋值就可以了。 Public Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long Sub TestIt() Dim httpRequest As MSXML2.XMLHTTP30 Dim txtContent As String Dim ReturnByte() As Byte Dim lngBufferSize As Long Dim strBuffer As String Dim lngResult As Long strQuery = "http://www.ec2win.com/sc/fixture_today_1.shtml" Set httpRequest = New MSXML2.XMLHTTP30 httpRequest.Open "GET", strQuery, False httpRequest.setRequestHeader "Content-Type", "text/html" httpRequest.send "" If httpRequest.Status = 200 Then ReturnByte = httpRequest.responseBody lngBufferSize = (UBound(ReturnByte) + 1) * 2 strBuffer = String$(lngBufferSize, vbNullChar) lngResult = MultiByteToWideChar(936, 0, ReturnByte(0), lngBufferSize / 2, StrPtr(strBuffer), lngBufferSize) txtContent = Left(strBuffer, lngResult) End If End Sub 狼版的帖子如下:http://club.excelhome.net/viewthread.php?tid=338026&replyID=&skin=0 |