我在使用以下 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。说的很清楚了,这是我 friend 帮我写的。
最佳答案
正如您现在可能已经知道的,这就是错误发生的地方
St00f = CInt(Replace(Mid(St00f, (InStr(St00f, ">R$")+3), 8), "</b>", ""))
那条线做了这些事情
-
InStr
返回第一次出现“">R$”的数字位置 - 然后加3得到字符串
"R$"
后面的索引 - 现在
Mid
分割字符串St00f
起始索引位于"R$"
之后长度为 8 - 然后
Replace
获取分割字符串并替换"</b>"
的出现与""
- 终于
CInt
将字符串转换为整数或更准确地说 * 将任何数字转换为子类型 Integer 的变体*
并且您在 CInt 转换时收到错误。
如果我在你的位置,我会逐行分割这一行,每行只保留一个函数,然后在每行之后尝试像 MsgBox 这样的输出,并找出问题所在。
关键是变量 St00f
以及该变量保存的内容。
快乐编码:)
关于vbscript - 为什么此 VBS 代码会失败并出现 "Type mismatch: ' CInt'"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9323676/