iif() function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi guys
hi Bob
i have a following code
dim t_string
t_string= target.value
target.clearcontents
target.value=iif(isnumeric(t_string),cdbl(t_string)/100000,t_string)
i am doing this to avoid circular reference
but i am getting error "type mismatch"
please help
 
hi guys
hi Bob
i have a following code
dim t_string
t_string= target.value
target.clearcontents
target.value=iif(isnumeric(t_string),cdbl(t_string)/100000,t_string)
i am doing this to avoid circular reference
but i am getting error "type mismatch"
please help

From HELP for IIF

IIf always evaluates both truepart and falsepart, even though it returns only
one of them. Because of this, you should watch for undesirable side effects.

So you will get your error if t_string is not numeric, since truepart gets
evaluated anyway.

One way around this would be to use an IF statement. For example:

If (IsNumeric(t_string)) Then
target.value = CDbl(t_string) / 100000
Else
target.value = t_string
End If
--ron
 
thanks ron

--
hemu


Ron Rosenfeld said:
From HELP for IIF

IIf always evaluates both truepart and falsepart, even though it returns only
one of them. Because of this, you should watch for undesirable side effects.

So you will get your error if t_string is not numeric, since truepart gets
evaluated anyway.

One way around this would be to use an IF statement. For example:

If (IsNumeric(t_string)) Then
target.value = CDbl(t_string) / 100000
Else
target.value = t_string
End If
--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top