473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

String to Single

A user of my software is getting this exception:

Conversion from string "0.5" to type 'Single' is not valid.

I have about 30 other users who do not get this exception when running
the same code and I have never seen it on my development PCs. As far
as I can see there is nothing wrong with converting "0.5" to a number.
Does anyone have any idea why he might experience this problem and no
one else?

He is running Windows in English with the keyboard settings, set to
Swedish.

Dec 4 '07 #1
13 1417
"Olie" <ow****@gmail.comschrieb
A user of my software is getting this exception:

Conversion from string "0.5" to type 'Single' is not valid.

I have about 30 other users who do not get this exception when
running the same code and I have never seen it on my development
PCs. As far as I can see there is nothing wrong with converting
"0.5" to a number. Does anyone have any idea why he might experience
this problem and no one else?

He is running Windows in English with the keyboard settings, set to
Swedish.
The OS language and the keyboard settings is not important. More important
are the regional settings.

What's the source of the string "0.5"? From a file? User input?
Armin

Dec 4 '07 #2
He tells me the regional settings are set to English. The string is
being read from an Xml file using the code:

Dim zoom As Single

zoom = XmlNode.Attributes("Zoom").Value

I do not think I used Single.Parse() but maybe I need to. I do not
have the code in front of me so this is from memory.

Does it matter where the source comes from. Surely a string is a
string wherever it came from.

Dec 4 '07 #3
He can not have the regional settings set to English. I just tried
running the software with the regional settings set to Finnish and it
gives you exactly the error he mentions.

Thanks for the hint! Do you know how to fix this? Will Single.Parse()
deal with this?

Dec 4 '07 #4
The project was exported from an older version of Visual Studio when
the Option Strict was set to Off by default. I agree it is a good idea
to turn it on.

Am I right in thinking that

Single.Parse("0.5")

would still fail on a computer with different language settings. I am
reading the value in from a config file where the number is set to
"0.5" so do I have to call Parse and specifically say to use the UK
number format.

Thanks so much for all your help!

Dec 4 '07 #5
"Olie" <ow****@gmail.comschrieb
The project was exported from an older version of Visual Studio when
the Option Strict was set to Off by default. I agree it is a good
idea to turn it on.

Am I right in thinking that

Single.Parse("0.5")

would still fail on a computer with different language settings. I
am reading the value in from a config file where the number is set
to "0.5" so do I have to call Parse and specifically say to use the
UK number format.
Yes, the InvariantCulture ensures that it can be converted independent from
the current culture setting that is used by default.
Armin

Dec 4 '07 #6
Armin,
>
Yes, the InvariantCulture ensures that it can be converted independent
from the current culture setting that is used by default.
Are you sure of that, I have read somewhere that the InvariantCulture is for
the differences in the English language, however not for Dutch and German.

Cor

Dec 4 '07 #7
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
Armin,

Yes, the InvariantCulture ensures that it can be converted
independent from the current culture setting that is used by
default.
Are you sure of that, I have read somewhere that the
InvariantCulture is for the differences in the English language,
however not for Dutch and German.
Which differences? I don't understand.
Armin


Dec 4 '07 #8
English has some differences between the majority of its users and the
official language.

AFAIK is the way the Americans are using the date is the classic way as used
in 18/19 century (I assume before the time that dates were written only in
figurs). The other English speakers do it now the same like we do. (You know
this of course however for the message)

I thought that this was the InvariantCulture. In other words december 5
(th) and 5 (th of) december.

Cor
"Armin Zingler" <az*******@freenet.deschreef in bericht
news:eS****************@TK2MSFTNGP05.phx.gbl...
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
>Armin,
>
Yes, the InvariantCulture ensures that it can be converted
independent from the current culture setting that is used by
default.
Are you sure of that, I have read somewhere that the
InvariantCulture is for the differences in the English language,
however not for Dutch and German.

Which differences? I don't understand.
Armin

Dec 5 '07 #9
"Cor Ligthert[MVP]" <no************@planet.nlschrieb:
>Yes, the InvariantCulture ensures that it can be converted independent
from the current culture setting that is used by default.
Are you sure of that, I have read somewhere that the InvariantCulture is
for the differences in the English language, however not for Dutch and
German.
The invariant culture is intended for exchange of data between multiple
machines regardless of their culture settings (it is based on US
conventions, but it is in no way semantically related to the 'en-US'
culture). Thus it is very suitable for protocols and writing data to files
and streams.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Dec 5 '07 #10
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
English has some differences between the majority of its users and
the official language.

AFAIK is the way the Americans are using the date is the classic way
as used in 18/19 century (I assume before the time that dates were
written only in figurs). The other English speakers do it now the
same like we do. (You know this of course however for the message)

I thought that this was the InvariantCulture. In other words
december 5 (th) and 5 (th of) december.

Ok. Well, I could only add what Herfried wrote in his latest post.
Armin
Dec 5 '07 #11
I have made the changes discussed and it does appear to fix the
problem.

Dec 5 '07 #12
The invariant culture is intended for exchange of data between multiple
machines regardless of their culture settings (it is based on US
conventions, but it is in no way semantically related to the 'en-US'
culture). Thus it is very suitable for protocols and writing data to
files and streams.
Did I write that, I had the idea that I was writing about the English
language, not about the English culture of American culture. In all
cultures where English is spoken is the dot the dot the decimal seperator.

I have searched again for that text

The invariant culture is culture-insensitive. You can specify the invariant
culture by name using an empty string ("") or by its language identifier.
InvariantCulture retrieves an instance of the invariant culture. It is
associated with the English language but not with any country/region. It can
be used in almost any method in the Globalization namespace that requires a
culture.

Cor

Dec 5 '07 #13
Olie,

Is that strange as AFAIK the InvariantCulture is an English language non
specific Culture, I would be more supprised as it was the other way around ?

Probably it works with nothing as well.

Cor

"Olie" <ow****@gmail.comschreef in bericht
news:d0**********************************@j20g2000 hsi.googlegroups.com...
>I have made the changes discussed and it does appear to fix the
problem.
Dec 5 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bengt Richter | last post by:
Why wouldn't quote-stuffing solve the problem, and let you treat \ as an ordinary character? In a raw string, it's no good for preventing end-of-quoting anyway, unless you want the literal \ in...
1
by: Markus Ernst | last post by:
Sorry for the multipost - I forgot to crosspost and alt.php gets less attention than comp.lang.php... And I hope this will work with UTF-8. In order to make strings suitable for URLs in a UTF-8...
3
by: Stefania Scott | last post by:
How do I resolve the problem of passing a string that has quotes within in a SQL statement? Sometimes the string contains a single quote (') and some others it contains the double quote (")? Any...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
8
by: Carlos | last post by:
I have a strinf with comma separated field. Is is possible to convert it to a Structure ? Thanks
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
3
by: Rob | last post by:
I've searched for info on how to drag and drop a group of strings (or any other object) from one control to another. Looked through articles by Dino Esposito, checked the Forms books by Sells and...
3
by: Jim in Arizona | last post by:
Is there an easy way to just get a single value from a database and put it into a string? This is as far as I can get: Dim TKEY As String TKEY = dlShowRequests.DataKeys(e.Item.ItemIndex) ...
3
by: psbasha | last post by:
Hi , When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ). ...
3
by: JH-PRO | last post by:
Please help! How to convert string to single Here my start values: Dim My_string as string = "29.02" Dim My_single as single = 0.0
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.