VB6 - IIF (ISNULL(rs),“TRUE",Replace()) [英] VB6 - IIF (ISNULL(rs),"TRUE",Replace())

查看:68
本文介绍了VB6 - IIF (ISNULL(rs),“TRUE",Replace())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能使用:

     rep8_bc = IIf(IsNull(rs(8)), "null", Replace(rs(8), "'", "''"))

它说无效使用 Null"

it say " Invalid use of Null"

但如果我删除替换,它的工作.然后得到错误,因为记录有一个撇号字符,所以我把代码改成这样:

but if i remove replace, it's work. And then get error because record have an apostrophe character, so i change the code into this :

 rep8_bc = "null"
 If IsNull(rs(8)) = False Then rep8_bc = Replace(rs(8), "'", "''")

或者这个:

 If IsNull(rs(8)) = False Then
     rep8_bc = Replace(rs(8), "'", "''")
 else
     rep8_bc = "null"
 end if

推荐答案

很可能编译器没有在 IIF() 语句中短路.编译器在返回一个之前将它作为一个完整的语句(两个值).这就是你得到错误的地方.因此,分解成适当的条件语句将是这里的关键.所以你的答案已经实现了.进一步补充说,IIF() 在执行上比 IF-ELSE 语句.

Mostly likely compiler doesn't short circuit within IIF() statement. Compiler takes it as a whole statment (both values) before returning one. That's where you get the error. So breaking into pieces of proper conditional statemetns would be the key here. So you have any achieved that with your answer. To further add, IIF() is much slower in execution than the IF-ELSE statments.

这篇关于VB6 - IIF (ISNULL(rs),“TRUE",Replace())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆