使用VBA的字符串长度有限制吗? [英] Is there a limitation to the string length with VBA?
问题描述
workbench = Cells(columnNumber,1).Value
myURL =http: //beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=_
& workbench
Dim inet1 As Inet
Dim mypage As String
Set inet1 = New Inet
with inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL,icString)
结束
CAMnum = InStr(mypage,Component Accessory Matrix)
intStart = InStrRev mypage,pkid =,CAMnum)+ 5
newnum = Mid(mypage,intStart,6)
单元格(columnNumber,2).Value = newnum
问题似乎与 mypage = .OpenURL(.URL,icString)
当我运行 len(mypage)
时,它返回一个大约100,000的值,当它应该返回大约一百万的值时。有人可以解释一下吗?
编辑:Gimp,我试过你的解决方案,由于某种原因,ReturnStr仍然是空的。我尝试了1024而不是2048,但没有改变任何东西。我已经复制并粘贴了我的代码到目前为止。
Dim myURL
ActiveSheet.Range(a1)。End(xlDown).Select
lastColumn = Selection.Row
对于columnNumber = 2 To lastColumn
workbench = Cells(columnNumber,1).Value
myURL =http://beams.us.yazaki.com/Beams/ViewDetails.aspx? topic = document& pkid =_
& workbench
Dim inet1 As Inet
Dim mypage As String
Dim ReturnStr As String
设置inet1 = New Inet
with inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL,icString)
ReturnStr = .GetChunk(1024 ,icString)
结束
Do While Len(ReturnStr)<> 0
DoEvents
mypage = mypage& returnStr
ReturnStr = inet1.GetChunk(1024,icString)
循环
CAMnum = InStr(mypage,Component Accessory Matrix)
intStart = InStrRev(mypage, pkid =,CAMnum)+ 5
newnum = Mid(mypage,intStart,6)
单元格(columnNumber,2).Value = newnum
下一列号
我在这里缺少什么?我在网上搜索了GetChunk函数,我不认为我在语法上做错了,但也许是一些根本的错误。
使用iNet,在使用iNet的OpenURL与GetChunk功能时,需要以块为单位读取文件。 / p>
尝试这样的东西:
myString = iNet1.OpenURL(。 url,icString)
ReturnStr = iNet1.GetChunk(2048,icString)
Do While Len(ReturnStr)<> 0
DoEvents
myString = myString& ReturnStr
ReturnStr = iNet1.GetChunk(2048,icString)
循环
将这些块读入ReturnStr,然后将它们追加到myString的末尾。
在这个Do循环之后,你的myString将有整个页面。
I have a large string that comes from an HTML source code (approximately 1,000,000 characters long). I'm using msinet.ocx to view the text from appropriate websites. I've written a small segment of code in order to find a key phrase ("pkid=") that occurs right before a different key phrase ("Component Accessory Matrix"), but it's not working properly. Here's what I have right now:
workbench = Cells(columnNumber, 1).Value
myURL = "http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=" _
& workbench
Dim inet1 As Inet
Dim mypage As String
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
End With
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
The problem seems to be with mypage = .OpenURL(.URL, icString)
; when I run len(mypage)
, it returns a value of approximately 100,000, when it should be returning a value of about a million. Can someone explain this?
EDIT: Gimp, I tried your solution, and for some reason, the ReturnStr is still empty. I tried 1024 instead of 2048 as well, but that didn't change anything. I've copied and pasted my code so far.
Dim myURL
ActiveSheet.Range("a1").End(xlDown).Select lastColumn = Selection.Row
For columnNumber = 2 To lastColumn workbench = Cells(columnNumber, 1).Value myURL = "http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=" _ & workbench Dim inet1 As Inet Dim mypage As String Dim ReturnStr As String
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
ReturnStr = .GetChunk(1024, icString)
End With
Do While Len(ReturnStr) <> 0
DoEvents
mypage = mypage & ReturnStr
ReturnStr = inet1.GetChunk(1024, icString)
Loop
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
Next columnNumber
Am I missing something here? I searched online for the GetChunk function, and I don't think I'm doing anything wrong syntactically, but maybe it's some fundamental error. Help is appreciated.
Using iNet, you need to read the file in chunks when using iNet's OpenURL with the GetChunk function.
Try something like this:
myString = iNet1.OpenURL(.url, icString)
ReturnStr = iNet1.GetChunk(2048, icString)
Do While Len(ReturnStr) <> 0
DoEvents
myString = myString & ReturnStr
ReturnStr = iNet1.GetChunk(2048, icString)
Loop
This will read the chunks into ReturnStr and then append them to the end of myString.
After this Do loop your myString will have the entire page in it.
这篇关于使用VBA的字符串长度有限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!