Visual Studio - Input string was not in a correct format - visual-studio

I have a part of my code here (file parser program) that gives me an error of: Input string was not in a correct format
For Each h1 As Char In PRIM_BIT.ToCharArray
rawbit = Convert.ToString(Convert.ToInt32(h1, 16), 2)
pribitval = pribitval & StrDup(4 - rawbit.Length, "0") & rawbit
Next
I tried to use int.TryParse, but it doesn't work. Is there a way to parse this?

Check the value of h1 when the error occurred.
h1 has to be a valid digit. Such as 0 ~ 9, a ~ f, A ~ F.
Also, h1 cannot be empty.
Edit:
If you want to bypass this and proceed, you can use Try...Catch... statement
For Each h1 As Char In PRIM_BIT.ToCharArray
Try
rawbit = Convert.ToString(Convert.ToInt32(h1, 16), 2)
pribitval = pribitval & StrDup(4 - rawbit.Length, "0") & rawbit
Catch ex As Exception
'Do something when error occurs. Or simply do nothing.
End Try
Next
I still recommend you to check what went wrong when the error occurred.

Related

`*': negative argument (ArgumentError) Ruby

I keep getting this negative argument error when running this code in the Codewars IDE. It runs fine in terminal but in Codewars it both passes the test and runs this error message simultaneously.
STDERR
main.rb:5:in `*': negative argument (ArgumentError)
from main.rb:5:in `maskify'
from main.rb:9:in `<main>'
The code is
def maskify(cc)
x = cc.to_s
y = "#" * (x.length - 4)
return y + x.slice(-4..-1)
end
I'm new to Ruby but I've not heard anywhere that it has a problem with negative numbers being used in .slice. Am I missing something here? Thanks.
You're not considering cases when cc is shorter than 4 symbols.
And expression "#" * (x.length - 4) raises the error because you can't multiply a string by a negative number.
Try to use Array#max method to handle this:
"#" * [x.length - 4, 0].max

Convert word special characters in VBS

So, some users have decided to paste word documents into the app I work on. As a result we have the likes of this â–¼ in the database, this should be a black downward triangle like this ▼
Now the app uses a .vbs file to get the data and display it to a classic asp page, the problem is, if I do a replace looking for â–¼ the vbs has already converted it to a ▼ and of course it never finds it, so i just end up with â–¼ being displayed asp page.
so even though i wrote this
strRet = replace(strRet, "â–¼", "▼")
when I debug it looks like this
strRet = replace(strRet, "▼", "▼")
Does anyone know how I can get vbs to look for the actual string of characters
Use AscW() and ChrW() to build the target string for the Replace() call:
>> s = "â–¼"
>> WScript.Echo s, AscW(Mid(s, 1, 1)), AscW(Mid(s, 2, 1)), AscW(Mid(s, 3, 1))
>>
â–¼ 226 8211 188
>> WScript.Echo Replace(s, ChrW(226) & ChrW(8211) & ChrW(188), ChrW(9660))
>>
▼
>>

Issue running Classic ASP written in VBScript on Windows 2012 with IIS 8

This is a very peculiar issue. I have a 2012 Server running IIS 8 with support for classic ASP installed. I am building a comma separated string from a form. I then am retrieving this string from a table and want to split on the commas.
First, when I build the string and submit it to the DB (SQL Express 2014), something is adding a space after each comma even though there is no space in the code.
Second, when I return the string and attempt to split on the comma, it doesn't do anything; the ubound method returns -1... For testing purposes, I hand built an array and this has the same behavior.
Code that builds the csv string:
If fieldName = "txt_EnvironmentType" then
strTempEnvCSV = strTempEnvCSV & fieldValue & ","
End If
Test code for split:
txtEnvironmentType = "This,Is,A,Test,String"
If txtEnvironmentType <> "" then
response.write(txtEnvironmentType)
array = split(txtEnvironmentType,",")
l = ubound(array)
response.write("<br>array is " & l & " long")
For i = LBound(array) to UBound(array)
response.write("<br>" & array(i))
Next
End If
The Above test code returns the following to the browser:
This,Is,A,Test,String
array is -1 long
Am I missing something?
Thanks!
For the mysterious spaces, add a TRIM() to make sure you aren't starting with spaces:
If fieldName = "txt_EnvironmentType" then
strTempEnvCSV = strTempEnvCSV & TRIM(fieldValue) & ","
End If
This ran (for your second issue) for me - the only change I made was to dim the array variable and name it something other than "array"
<%
dim arrMine
txtEnvironmentType = "This,Is,A,Test,String"
If txtEnvironmentType <> "" then
response.write(txtEnvironmentType)
arrMine = split(txtEnvironmentType,",")
l = ubound(arrMine)
response.write("<br>arrMine is " & l & " long")
For i = LBound(arrMine) to UBound(arrMine)
response.write("<br>" & arrMine(i))
Next
End If
%>

Term to packet erlang. Constructing a binary

I have the following code:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/integer-unit:8 >>.
However, when I run:
term_to_packet("Hello").
I get an error:
exception error: bad argument in function term_to_packet line 20
where line 20 corresponds to the last line of the term_to_packet function.
I'm not quite sure what's throwing this error.
B is a binary, but in the binary construction on the last line you specify that it is an integer. This seems to work:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/binary-unit:8 >>.

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

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.
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
InStr that returns the numeric position of the first occurrence of ">R$"
Its then added with 3 to get the index after the string"R$"
Now Mid splits the string St00f with start index after "R$" to a length of 8
Then Replace takes the split string and replaces an occurrence of "</b>" with ""
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 :)
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().
CInt can handle betweeen -32,768 and 32,767
Use CLng instead of CInt
Copied from Cint overflow error when value exceeds 100,000+

Resources