String to Single

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Olie

    #1

    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.

  • Armin Zingler

    #2
    Re: String to Single

    "Olie" <owaits@gmail.c omschrieb
    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

    Comment

    • Olie

      #3
      Re: String to Single

      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.Attribu tes("Zoom").Val ue

      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.



      Comment

      • Olie

        #4
        Re: String to Single

        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?

        Comment

        • Olie

          #5
          Re: String to Single

          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!

          Comment

          • Armin Zingler

            #6
            Re: String to Single

            "Olie" <owaits@gmail.c omschrieb
            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 InvariantCultur e ensures that it can be converted independent from
            the current culture setting that is used by default.


            Armin

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: String to Single

              Armin,
              >
              Yes, the InvariantCultur e 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 InvariantCultur e is for
              the differences in the English language, however not for Dutch and German.

              Cor

              Comment

              • Armin Zingler

                #8
                Re: String to Single

                "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschri eb
                Armin,
                >

                Yes, the InvariantCultur e 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
                InvariantCultur e is for the differences in the English language,
                however not for Dutch and German.
                Which differences? I don't understand.


                Armin




                Comment

                • Cor Ligthert[MVP]

                  #9
                  Re: String to Single

                  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 InvariantCultur e. In other words december 5
                  (th) and 5 (th of) december.

                  Cor


                  "Armin Zingler" <az.nospam@free net.deschreef in bericht
                  news:eS6%230uqN IHA.2000@TK2MSF TNGP05.phx.gbl. ..
                  "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschri eb
                  >Armin,
                  >>
                  >
                  Yes, the InvariantCultur e 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
                  >InvariantCultu re is for the differences in the English language,
                  >however not for Dutch and German.
                  >
                  Which differences? I don't understand.
                  >
                  >
                  Armin
                  >
                  >
                  >
                  >

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: String to Single

                    "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschri eb:
                    >Yes, the InvariantCultur e 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 InvariantCultur e 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/>

                    Comment

                    • Armin Zingler

                      #11
                      Re: String to Single

                      "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschri eb
                      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 InvariantCultur e. 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

                      Comment

                      • Olie

                        #12
                        Re: String to Single

                        I have made the changes discussed and it does appear to fix the
                        problem.

                        Comment

                        • Cor Ligthert[MVP]

                          #13
                          Re: String to Single

                          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.
                          InvariantCultur e 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

                          Comment

                          • Cor Ligthert[MVP]

                            #14
                            Re: String to Single

                            Olie,

                            Is that strange as AFAIK the InvariantCultur e 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" <owaits@gmail.c omschreef in bericht
                            news:d065640a-c78e-4de8-a881-dd7958daa5fd@j2 0g2000hsi.googl egroups.com...
                            >I have made the changes discussed and it does appear to fix the
                            problem.
                            >

                            Comment

                            Working...