I (new to VB.NET) am doing some code maintenance on a function that sometimes throws an exception “error converting string “False” (or “True”) to type Integer.” What I found was something equivalent to this
someVal is a string, someFun1 returns an Integer and someFun2 takes an Integer as a parameter
...
someVal = someVal = someFun1()
...
someFun2(someVal)
...
What I think might be happening is that it is trying to assign someFun1’s return value into someVal, then perform a bool check as to whether someVal has changed – but I don’t think that is what needs to be done.
My question is – does this double assignment (someVal = someVal = someFun1()) accomplish anything that I don’t know about in VB.NET?
another note: I realize there are implicit casts of integer to string and back to integer, but that shouldn’t be causing any problems, because the values should always hold a numerical value (which can be implicitly cast back and forth from Integer and String, right?) not True or False – as far as I can tell
The confusion here is that the equals operator
=is the same as the assignment operator=in VB.NET. In C#, the code above would be equivalent towhere the boolean equals operator
==is carried out first, and the result is inserted intosomeVal. This fails, becausesomeValisint, notbool.In other words, the runtime is comparing
someValwith the return value ofsomeFun1(), returningTrueorFalse, and failing to cast that to an integer. This isn’t a “double assignment” – it’s just an inline representation ofwhere it is much more obvious that we’re trying to give an
Integervariable a value of typeBoolean.