Hiya,
I made a program in Visual studio 2005. Compiles and works OK at home.
At work, i have JUST VB 2005 Express Beta 2 installed.
The code itself ported OK, no errors.
However, during runtime, i get a type conversion error.
It's not that i'm converting anything though either.
I can't convert string to single. For example...
Dim sngSingle as Single
sngSingle = "0.5" ' Doesn't work
sngSingle = cSng("0.5") Doesn't work.
sngSingle = CType("0.5",Single) Doesn't work.
sngSingle = Single.Parse("0.5") Doesn't work.
Even if i make a new project, and try to do any of the above conversions (Which should work), i get a type convertion error.
And again, the only difference, is that i'm using vb 2005 express beta 2, rather then VS 2005 beta 2.
Any ideas

Type conversion errors.
AmitJoshi
Error : InvalidCastExecption
'Conversion from String "0.5" to Type Single is not valid.'
That's it. No other info in the error.
VB Express Edition Version 8.0.50215.44
I have .NET framework 2.0.50215 installed. (Checked in C:\Windows\Microsoft.Net\Framework\)
I have already un-installed and re-installed vb 2005, .net 2.0 (deleted the left-over folders after un-install too), and get the exact same error.
It doesn't seem to be project related either, as i can open the Emmediate window, and type sngSingle = cSng("0.5") and get a invalid cast exception too.
Dustin.
jimmyglo
I just loaded you code into a new project in my Beta II (Team server) and it ran just fine and had no problems with the conversions you had trouble with.
eric_delage
The code worked fine on my copy of team server too. It's the VB 2005 Express edition that's giving me the problem. In theory, there should be no difference how the compiler parses these kinds of conversions. I'll have a more detailed reply when i get back to work at the computer.
Dustin.
JasonStowe
I didn't use your exact sample, but it led me down the correct path.
Thanks for all your help :) Back to coding now :)
Dustin
PaulFnNY
I'm making a scripting engine, and it's loading code from a file.
basically for example, a line of code would look like..
'Create mesh command, file name, x, y ,z
CreateMesh Mesh.x 0.3, 0.5, 0.2
each item is split up using space as a delimiter. I create a string() array
in the above sample, i create a vector3 like so..
Dim V3 as New Vector3(CSng(strArray(2)), CSng(strArray(3)), CSng(strArray(4)))
Now, if on my home computer that's english, this works Ok cause the region is en-us. However, at work, on a french system, the region is canada french, and the demical character becomes a comma ( , )
If i edit my script files, and change the line to CreateMesh Mesh.x 0,3, 0,5, 0,2
then it works great. Only problem is, there's alot of script, and i want to be able to use the same script files on any region.
So, basically, is there a way to specify in the code, to use a default culture when parsing variables I really really don't want to have to go through my entire script engine and change all the conversions to
Dim s1 As Single = Single.Parse("0.5", New System.Globalization.CultureInfo("En-us"))
Although it would work, it's just not practical. I would have to spend a couple weeks doing this.
Dustin.
delantian
The computer at work is a French OS, and the decimal point was setup for , instead of .
So when i used sngSingle = CSng("0,5") it worked just fine.
So instead of re-writing the code with commas, i set the regional options of the computer to english US, and everything worked OK.
Weird error. Is there a way around this other then changing regional settings
JDSS
Do you get it from a database
Do you get it from the user
Do you get it from a configuration file
Best regards,
Johan Stenberg
DFlatGuy
The error is a general exception as typecasting error. Can't convert String "0.5" to Single
I can't give you the exact wording as it's a work development computer with no internet acces Next time i'm at work i'll get it. But generally, there was no useful information in the error, other then it said typecast error from string to single, using every example from my first post..
The weird thing is, there are no errors during compile, even if i set the compiler implicit conversion setting to 'error'. (i write pretty tight code). The error only happens when the code is run, and gets to the point where i'm doing the actual conversion.
I know this should work.... I'm not sure whats going on. I'll post the exact error soon.
Dustin.
johnd2
That's strange! :/
Simeon Antonov
Hi,
Express editions have no problems with type conversions. What specifically is the error I just tried it in my C# express copy and it seems to work just fine. The last two lines of your code should work.. what build is your express
cheers,
Paul June A. Domag
Misch
You can tell Single.Parse what locale you want to use when parsing the single:
s1 As Single = Single.Parse("0.5", New System.Globalization.CultureInfo("En-us"))Dim
Best regards,
Johan Stenberg
amberBC
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture
For more info, see: http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconusingcurrentcultureproperty.asp
Best regards,
Johan Stenberg
Matt ms user
sngSingle = convert.ToSingle("0.5")
If that doesn't work...i suspect its an issue with the express versions....
you may want to post this in the express forum:
http://forums.microsoft.com/msdn/ShowForum.aspx ForumID=24
bogomil
well, that would mean re-writing about 1000 lines just for this conversion. I will use it as a last resort. Is there no way of specifying a default once and not having to retype it
Dustin