Home All Groups Group Topic Archive Search About
Author
15 Sep 2006 2:10 PM
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))

Author
15 Sep 2006 2:18 PM
cj
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 wrote:
Show quoteHide quote
> 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))
Author
15 Sep 2006 2:22 PM
Chris Dunaway
cj wrote:
> 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
Author
15 Sep 2006 3:14 PM
cj
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

Chris Dunaway wrote:
Show quoteHide quote
> cj wrote:
>> 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
>
Author
15 Sep 2006 6:43 PM
Herfried K. Wagner [MVP]
"cj" <cj@nospam.nospam> schrieb:
>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'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>