Connecting Tech Pros Worldwide Forums | Help | Site Map

CDec("")

cj
Guest
 
Posts: n/a
#1: Sep 15 '06
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))

cj
Guest
 
Posts: n/a
#2: Sep 15 '06

re: CDec("")


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:
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))
Chris Dunaway
Guest
 
Posts: n/a
#3: Sep 15 '06

re: CDec("")


cj wrote:
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))
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

cj
Guest
 
Posts: n/a
#4: Sep 15 '06

re: CDec("")


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:
Quote:
cj wrote:
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))
>
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
>
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#5: Sep 15 '06

re: CDec("")


"cj" <cj@nospam.nospamschrieb:
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))
Check out 'Decimal.TryParse'.

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