Instr()中的溢出错误

我仍然试图从网页获取一些数据,我得到了一个解决scheme如何“grep”的HTML文本,但现在我试图从这个文本中的string中分离出一些部分。

我想取出variablesA和variablesB之间的部分,并使用下面的代码。

我总是得到一个Runtime error 6 Overflow ,有人有一个想法为什么以及如何解决这个问题?

 Sub Button1_Click() Const HTTPREQUEST_PROXYSETTING_PROXY = 2 Dim oRequest As Object, pagetext, third As String, first, second As Integer Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1") oRequest.Open "GET", "http://www.vodafone.de/privat/handys-tablets-tarife/smartphone-tarife.html" oRequest.Send pagetext = oRequest.ResponseText first = InStr(pagetext, "window.phones") second = InStr(first + 1, pagetext, "window.propositions") third = Mid(pagetext, first + 1, second - first - 1) MsgBox (third) End Sub 

secondvariables的声明从Integer更改为Long

Integertypes最多可以包含32,767个数字,expression式( 154031 )返回的值大于该值。 Long数据types可以保存数字高达2,147,483,647,所以它更适合您的具体情况。

通常,VBA现在将所有Integers转换为Long ,因此默认情况下将variables变暗为Long是更好的做法。

另外,当在一行中调暗多个variables时,你也应该小心,因为

  Dim oRequest As Object, pagetext, third As String, first, second As Integer 

firstVariantsecondInteger

它应该是

 Dim oRequest As Object, pagetext, third As String, first as Long, second As Long