判断数组为空

来源:百度知道 编辑:UC知道 时间:2024/06/07 23:38:41
while i>0

code=replace(code,"$title$",Application(Application("Z")(2,Z_P))(1,earr(rndNumber(0,ubound(earr)))),1,1)
i=instr(i,code,"$title$")

wend

当Application(Application("Z")(2,Z_P))(1,earr(rndNumber(0,ubound(earr))))为空时,就会提示
类型不匹配: 'ubound'

如何判断他,如果数组为空时,则用"标题"替代(不含引号)

try
catch好了
你试试这个,那个类型不匹配的错误代码不知道,你查下msdn,然后可以具体处理,我现在只是显示出来
while i>0
try
code=replace(code,"$title$",Application(Application("Z")(2,Z_P))(1,earr(rndNumber(0,ubound(earr)))),1,1)
i=instr(i,code,"$title$")
catch obj as exception
msgbox("出错了")
end try

wend

on error resume next

while i>0

code=replace(code,"$title$",Application(Application("Z")(2,Z_P))(1,earr(rndNumber(0,ubound(earr)))),1,1)
if err then
err.clear
code=replace(code,"$title$","你要使用的标题",1,1)
end if
i=instr(i,code,"$title$")

wend

Try

'有可能会出错的语句

Catch LeafError As Exception

'如果出错了执行的语句

End Try

最好的办法,为空之前,REDIM(0) 一下,
或者用VALTYPE这个函数看看

Application是什么?