CorelDraw VBA 开发中,为了根据字符串不同而进行不同的处理,用到了Select Case 语句。但是使用 Select Case like “*string*”的时候,总是无法进入目标的处理。代码如下:
<code><span class="kwd">Select</span> <span class="kwd">Case</span><span class="pln"> ActiveCell</span><span class="pun">.</span><span class="pln">Value </span><span class="kwd">Case</span><span class="pln"> ActiveCell</span><span class="pun">.</span><span class="pln">Value </span><span class="kwd">Like</span> <span class="str">"*codebye.com*"</span><span class="pln"> ActiveCell</span><span class="pun">.</span><span class="pln">Value </span><span class="pun">=</span> <span class="str">"https://www.codebye.com"</span> <span class="kwd">End</span> <span class="kwd">Select</span></code>
最终调查发现问题在于 ActiveCell.Value 是字符串 ,而case 语句 ActiveCell.Value Like "*string*" 是 bool 值。相应的解决方案也很简单,如下代码所示:
<code><span class="kwd">Select</span> <span class="kwd">Case</span> <span class="lit" style="color: #ff0000;">True</span> <span class="kwd">Case</span> <span class="pun">(</span><span class="pln">ActiveCell</span><span class="pun">.</span><span class="pln">Value </span><span class="kwd">Like</span> <span class="str">"*codebye.com*"</span><span class="pun">)</span><span class="pln"> ActiveCell</span><span class="pun">.</span><span class="pln">Value </span><span class="pun">=</span> <span class="str">"https://www.codebye.com"</span> <span class="kwd">End</span> <span class="kwd">Select</span></code>
如上所示,只需case后面使用True 即可。以上是今天CorelDraw VBA 插件开发中遇到的一个小问题,分享给大家希望对您有所帮助。感谢您对codebye的支持