为什么此VBS代码因“类型不匹配:'CInt'”错误而失败?

时间:2012-02-17 06:05:01

标签: vbscript

我遇到以下VBS代码时出现问题。它有时只能工作,即使这样它也很快失败。为什么呢?

Dim Butt
Set Butt = CreateObject("InternetExplorer.application")
Butt.visible = True
Butt2 = InputBox("Put the link to one hat you would like to snipe.", "Hat Selection")
Butt3 = InputBox("Enter the maximum amount of Robux you will spend on this hat.", "Maximum Payment")
Dim Proace
Set Proace = CreateObject("Microsoft.XMLHTTP")
Proace.Open "GET", "http://www.roblox.com", False
Proace.Send
Do
Do While Butt.Busy
WScript.sleep 200
Loop
St00f = CInt(Replace(Mid(St00f, (InStr(St00f, ">R$")+3), 8), "</b>", ""))
If St00f <= CInt(Butt3) Then
Butt.Navigate "javascript:WebForm_DoPostBackWithOptions(new%20WebForm_PostBackOptions(""ctl00$cphRoblox$TabbedInfo$UserSalesTab$lstItemsForResale$ctrl0$lnkBuyNow"",%20"""",%20true,%20"""",%20"""",%20false,%20true))"
Exit Do
End If
Loop
Do While Butt.Busy
WScript.sleep 200
Loop
MsgBox("Congratulations! Your snipe was successful! You sniped "&Butt2&" for "&Butt3&" Robux!")
Butt.Quit
Set Butt = Nothing
Set Proace = Nothing
WScript.Quit

错误:

Script:   C:\Users\John\Downloads\SingleHatSniper.vbs  
Line:     14
Char:     1
Error:    Type mismatch: 'CInt'
Code:     800A000D
Source:   Microsoft VBScript runtime error

请帮助我,我对VBS不太好。很明显,我的朋友帮我写了这个。

3 个答案:

答案 0 :(得分:5)

正如您现在所知,这是发生错误的地方

St00f = CInt(Replace(Mid(St00f, (InStr(St00f, ">R$")+3), 8), "</b>", ""))

那条线做了这些事

  1. InStr返回第一次出现的“&gt; R $”
  2. 的数字位置
  3. 然后添加3以获取字符串"R$"
  4. 之后的索引
  5. 现在MidSt00f之后的起始索引的字符串"R$"拆分为长度为8
  6. 然后Replace获取拆分字符串并将"</b>"替换为""
  7. 最后CInt将字符串转换为整数或更正确*将任何数字转换为子类型Integer的变体*
  8. 您在CInt转换时遇到错误。

    如果我在你的位置,我将逐行分割这一行,每行只保留一个函数,然后在每一行之后尝试使用MsgBox作为输出,并找出它的错误。

    关键是变量St00f以及该变量的含义 快乐编码:)

答案 1 :(得分:2)

“类型不匹配”错误表示您的替换(...)未返回有效的数字字符串:

>> i = CInt("4711")
>>
>> i = CInt("999999999999")
>>
Error Number:       6
Error Description:  Overflow
>> i = CInt("no number")
>>
Error Number:       13
Error Description:  Type mismatch
>> i = CInt("")
>>
Error Number:       13
Error Description:  Type mismatch

在应用CInt()之前,请考虑使用IsNumeric()。

答案 2 :(得分:1)

CInt可以处理-32,768和32,767之间的

使用CLng代替CInt

Cint overflow error when value exceeds 100,000+

复制
相关问题