tags:

views:

95

answers:

3

If Double.Parse(list_numbers.Item(i), possibledouble)

list_numbers is a list of strings

list_numbers.Item(i) = "0.000"

possibledouble is a double

debugger returns "input string was not in a correct format"

i thought that the double parse would convert the string into a double format of "0.0" but it gives me an error. please help

+1  A: 

for you question;

what is list_numbers? (array? control? something else?)

a small improvement, you should change

    Select Case CDbl(list_numbers.Item(i))

with

    Select Case possibledouble

and for you title question;

isnumeric function should be enough in your case I think

and you already got how to do it from here

Fredou
+1  A: 

... and you got a better answer on the case statement here. see jvanderh's answer.

DaveE
+1  A: 

Your code should probably look like this (See below for explanation)

If Double.TryParse(list_numbers.Item(i), possibledouble) Then

                        Select Case possibledouble
                            Case 0 To 49.99
                                list_numbers.Item(i) = ""
                            Case 59 To 99.99
                                list_numbers.Item(i) = "1"
                            Case 100 To 199.99
                                list_numbers.Item(i) = "2"
                            Case Is > 200
                                list_numbers.Item(i) = "3"
                            Case Else
                                list_numbers.Item(i) = "n/a"
                         End Select

End If

Well there are a few problems with your code as far as I can see, which I'm sure explain the behavior your seeing.

First of all the Double.Parse method is actually already returning you a double for that item, so no need to convert it again with Cdbl later on.

Another more major problem with this line is that if the method cannot convert the string to a double it throws an exception. I'm guessing some where in your code you're catching that exception without realizing it.

Last problem with this is that I don't actually find any overloads for Double.Parse that except string and double which lead me to beleive that you were actually meaning to use the Double.TryParse method and not the Parse method. TryParse will return true or false if the parsing succeeded and put the value in the double you specified if it did.

Ron Srebro