CDec("")

  • Thread starter Thread starter cj
  • Start date Start date
C

cj

I thought, apparently incorrectly, CDec("") would result in 0D.

Unless someone here can tell me something better it seems in reading my
report file I'll have to say something like

amount = IIf(line.Substring(20, 11).Trim = Nothing, 0D,
CDec(line.Substring(20, 11)))

instead of

amount = CDec(line.Substring(20, 11))
 
Ooops, just rudely reminded that iif evaluates both cases before using
one so that gives errors too so I guess it'll be an old fashioned if
else statement.
 
cj said:
I thought, apparently incorrectly, CDec("") would result in 0D.

Unless someone here can tell me something better it seems in reading my
report file I'll have to say something like

amount = IIf(line.Substring(20, 11).Trim = Nothing, 0D,
CDec(line.Substring(20, 11)))

instead of

amount = CDec(line.Substring(20, 11))

That will fail too since the IIf function will evaluate the CDec(...)
part even if it is empty. You need to use this instead:

strAmt = line.Substring(20,11).Trim()
If strAmt <> String.Empty Then
amount = CDec(strAmt)
Else
amount = 0D
End If
 
Yea IIf doesn't help, as you probably noted in my email just moments
before you replied was again reminded of that.

Due to some testing lines in the report some of my otherwise fields that
should be blank or a number come up like "0 0" so I went with

If IsNumeric(tempString) Then amount = CDec(tempString) Else amount = 0D
 
cj said:
I thought, apparently incorrectly, CDec("") would result in 0D.

Unless someone here can tell me something better it seems in reading my
report file I'll have to say something like

amount = IIf(line.Substring(20, 11).Trim = Nothing, 0D,
CDec(line.Substring(20, 11)))

instead of

amount = CDec(line.Substring(20, 11))

Check out 'Decimal.TryParse'.
 
Back
Top