Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this VBS code fail with a "Type mismatch: 'CInt'" error?

Tags:

vbscript

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.

like image 598
John Doe Avatar asked Feb 17 '12 06:02

John Doe


People also ask

What is type mismatch error in VBScript?

These error messages occur because VBScript cannot properly convert adNumeric values to a valid numeric type. This behavior is by design.

What is Microsoft VBScript runtime error?

VBScript run-time errors are errors that result when your VBScript script attempts to perform an action that the system cannot execute. VBScript run-time errors occur while your script is being executed; when variable expressions are being evaluated, and memory is being dynamic allocated.


2 Answers

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

like image 63
naveen Avatar answered Jan 03 '23 01:01

naveen


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().

like image 37
Ekkehard.Horner Avatar answered Jan 03 '23 00:01

Ekkehard.Horner