Variable Scope
The variable Concentration
exists only in the Try block. Therefore, whenever you leave this block, the variable no longer exists.
To solve this, you must declare Concentration
before the Try.
Finally Block
Another problem you will encounter is that Concentration
will always be -1, because you said so in the Finally
block, this block is not necessary here.
Dim inputstr As String = .Item("conc")
Dim concentration As Double
Try
concentration = CDbl(inputstr)
Catch ex As Exception
concentration = -1.0
End Try
If concentration > 0.0 Then
err = 1
End If
A bit of reading about Variable scope in VB .Net
And another bit of reading about Try/Catch blocks
Don't use Try/Catch to do that
However, as stated by Fabio, you can use Double.TryParse() to do that, it is easier to read and more important, it is a performance increase.
So, in the end, it is better coding practice to do:
Dim inputstr As String = .Item("conc")
Dim concentration As Double
If Not Double.TryParse(inputstr, concentration) Then
concentration = -1.0
End If
If concentration > 0.0 Then
err = 1
End If