string to double

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dandalero
    New Member
    • Aug 2009
    • 11

    string to double

    I created an application in vb.net 2005. It works fine on my machine. I tested several different test machines and all were working fine. As for the client, it's generating an error. My application reads from an excel sheet and imports the values to an oracle database. the error being generated is: "conversion from type string to type double is not valid". Why is it generating only on the client's computer and not mine?
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Originally posted by dandalero
    My application reads from an excel sheet and imports the values to an oracle database.
    Can you post the code that does this?

    Steven

    Comment

    • dandalero
      New Member
      • Aug 2009
      • 11

      #3
      Dim deci As Decimal = 0
      deci = CDec(dt.Rows(i) .Item(13))

      If Not IsDBNull(dt.Row s(i).Item(13)) AndAlso deci > 0 Then
      .price = CDec(dt.Rows(i) .Item(13))
      End If

      POITEM.price = .price

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        Could it have something to do with the regional settings on the machines? This often creates a difference between e.g. 0,13 and 0.13.

        Steven

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Are you testing with the same test materials?
          Spreadsheet Alpha works just fine on your machine and your other test machines but spreadsheet Bravo fails at the client. Could indicate that spreadsheet Bravo is not set up the same as the test subject they gave you and that you are not checking for the possibility that a value might not be right.
          deci = CDec(dt.Rows(i) .Item(13))
          This can only work if the cell actually has a number. What if it doesn't? When coding you have to account for the possibility that the world is not perfect. Wrap it in a try/catch for starters and work your way out from there. MessageBox with error statement in the catch construct might help.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            When this type of error pops up, its almost always a regional thing. Differences between , and . and whatnot. Need to specify the correct region/culture for the data being parsed, and not just the default region/culture

            I also recomend using the .NET conversions instead of the old VB conversions:
            Double.Parse() or Double.TryParse ()

            Comment

            • dandalero
              New Member
              • Aug 2009
              • 11

              #7
              Regarding the regional settings, I checked both regional settings and they are exactly the same. As for the cell having a number, i checked the excel sheet and didn't find any null or empty values.

              Comment

              • MrMancunian
                Recognized Expert Contributor
                • Jul 2008
                • 569

                #8
                Did you also check for non-numerical values? When there is a letter or a special character in the cell it also cannot be converted to double.

                Steven

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  Perhaps you should be checking the object type first:
                  dt.Rows(i).Item (13).GetType(). ToString()
                  Make sure its what you think it should be (every time)
                  Then check that:
                  dt.Rows(i).Item (13).ToString()
                  is always something that can be parsed into a double?

                  Comment

                  • MrMancunian
                    Recognized Expert Contributor
                    • Jul 2008
                    • 569

                    #10
                    Or just check if it is numeric. If not, it can't be parsed into a double:

                    Code:
                    If IsNumeric(dt.Rows(i).Item(13).ToString())
                    Steven
                    Last edited by MrMancunian; Aug 14 '09, 01:56 PM. Reason: Typo

                    Comment

                    • tlhintoq
                      Recognized Expert Specialist
                      • Mar 2008
                      • 3532

                      #11
                      Originally posted by dandalero
                      Regarding the regional settings, I checked both regional settings and they are exactly the same. As for the cell having a number, i checked the excel sheet and didn't find any null or empty values.
                      But did you actually take anyone's advice? Put in some try/catch blocks in case something is not as it appears? Put in some 'if' conditionals to only do what you want 'if' the values were as expected? Put up some messageboxs or log files to report problems?

                      Comment

                      • dandalero
                        New Member
                        • Aug 2009
                        • 11

                        #12
                        I placed some Try/Catch blocks and managed to find out in which column in the excel sheet the error was being generated. I checked the whole column but i saw no letters or special characters there. But once again, if the column contained letters or empty value, shouldn't it generate an error on any computer??? This error is only being generated on one computer.

                        Comment

                        • tlhintoq
                          Recognized Expert Specialist
                          • Mar 2008
                          • 3532

                          #13
                          Just because you don't see it, doesn't mean its not there. There are a lot of characters that are not displayable. Control codes for example.

                          This error is only being generated on one computer.
                          So far.

                          But once again, if the column contained letters or empty value, shouldn't it generate an error on any computer???
                          There is a setting on that machine that is different than the other machines.
                          Format of a date... country regionalization ... time format... thousands seperator character... Version of Excel on that one machine... something

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #14
                            Originally posted by tlhintoq
                            Version of Excel on that one machine... something
                            Ooo that's a good one, a different version of office would also have different versions of Jet. I would go so far as to say a difference in office updates on one vs the other could cause troubles.

                            Comment

                            Working...