VB6 - IIF (ISNULL(rs),“TRUE”,Replace())

半腔热情 提交于 2019-12-11 14:05:42

问题


why i cannot use :

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

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), "'", "''")

or this :

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

回答1:


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.



来源:https://stackoverflow.com/questions/13357344/vb6-iif-isnullrs-true-replace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!