6

I am experiencing difficulty with the following VBS code. It works only sometimes, and even then it fails quickly. Why?

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

Error:

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

Please help me, I'm not that great with VBS. That much is clear, my friend helped me write this.

John Doe
  • 63
  • 1
  • 1
  • 5
  • 2
    I won't be any help, but "Butt" has to be the most painful name possible. I would just giggle the whole time I was trying to call methods on it. "Do While Butt.Busy"? Heeheeheehee. – Interrobang Feb 17 '12 at 06:07
  • Please choose a proper title for your question to get people interested in it. "Could you walk me through this" says nothing about your question. – deceze Feb 17 '12 at 06:08
  • @Inter That paired with the name "Interrobang" makes it pretty suggestive, doesn't it‽ ;-P – deceze Feb 17 '12 at 06:09
  • @deceze: we have interesting variable names though. :) – naveen Feb 17 '12 at 06:11
  • Loving the variable name "Butt." I think I'll use that sometime. Thanks! – Darth Egregious Oct 22 '13 at 13:51

3 Answers3

5

As you might have known by now, this is where the error occurs

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

And that line does these things

  1. InStr that returns the numeric position of the first occurrence of ">R$"
  2. Its then added with 3 to get the index after the string"R$"
  3. Now Mid splits the string St00f with start index after "R$" to a length of 8
  4. Then Replace takes the split string and replaces an occurrence of "</b>" with ""
  5. At last CInt converts the string to an integer or more correctly * converts any number to the variant of subtype Integer*

And you are getting the error at the CInt conversion.

If I were at your place, I will split this line by line by keeping only one function per line and then try something like MsgBox for the output after each line and find what's wrong with that.

The key is the variable St00f and what that variable holds.
Happy Coding :)

naveen
  • 53,448
  • 46
  • 161
  • 251
2

The "Type mismatch" error indicates that your Replace(...) did not return a valid numerical string:

>> 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

Consider using IsNumeric() before you apply CInt().

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
1

CInt can handle betweeen -32,768 and 32,767

Use CLng instead of CInt

Copied from Cint overflow error when value exceeds 100,000+

Community
  • 1
  • 1
David F Mayer
  • 107
  • 1
  • 1