一个VB的编程问题

Dim一个String变量dl,然后获取网络上地址为“http://www.xxxx.com/xxxx.txt"的文本文件中的文本内容,如:
xxxxx
然后将这些文本内容赋予变量dl

要建一个intel控件
Dim xx As String, yy As String, url As String
Dim t As Double
url = "http://www.xxxx.com/xxxx.txt"
Inet1.Cancel
Inet1.Execute url, "get"

t = Timer
Do
DoEvents
If Inet1.StillExecuting = False Or Abs(t - Timer) > 20 Then Exit Do
Loop
xx = ""
Do
DoEvents
yy = Inet1.GetChunk(32768)
If yy = "" Or Abs(t - Timer) > 20 Then Exit Do
xx = xx & Uf8ToUf(yy) ‘为了解决中文乱码问题的函数
dl = xx
Loop

Public Function Uf8ToUf(strUf8 As String) As String
'将UF8转为VB内部处理编码UF
'
'
On Error GoTo MyErr
Dim lngStrLen As Long '需转换的字符串长度
Dim byUf8() As Byte '保存源字符串
Dim byUf(1) As Byte '字符串暂存1
Dim strDef As String '字符串暂存2
Dim i As Long '哨兵计数
Dim strUf As String '存放结果字符串

byUf8() = StrConv(strUf8, vbFromUnicode)
'将当前显示为“乱码”Gb2132转换为VB内部处理编码-Unicode码,并保存到Byte数组

lngStrLen = UBound(byUf8) '获得字符串长度

i = 0
Do While i < lngStrLen
If byUf8(i) < 128 Then '非中文..不作处理。
strUf = strUf & Chr(byUf8(i))
i = i + 1
Else '是中文
byUf(1) = ((byUf8(i) And 15) * 16 + (byUf8(i + 1) And 60) / 4)
'取得第一个字节的后4位与第二个字节的中间4位

byUf(0) = (byUf8(i + 1) And 3) * 64 + (byUf8(i + 2) And 63)
'取得第二字节的后2位与第三个字节的后6位

strDef = byUf
strUf = strUf & strDef

i = i + 3
End If
'DoEvents
Loop

'转最后字符时我没有计算出来。。只能用错误处理。。但结果绝对问题
MyErr:
Uf8ToUf = strUf '返回VB内部处理的UF编码
End Function
Public Function getword(aa As String) As String
Dim p As String, s As String
For i = 1 To 20
p = Mid(aa, i, 1)
Select Case p

Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "$"
s = s & p

Case "/"
If Mid(s, i + 1, 1) <> "/" Then s = s & p
End Select
Next

getword = Replace(s, "//", "")
End Function
温馨提示:答案为网友推荐,仅供参考
相似回答