private declare function ebexecuteline lib "vba6.dll" ( _ byval pstringtoexec as long, _ byval unknownn1 as long, _ byval unknownn2 as long, _ byval fcheckonly as long) as long
dll声明,顾名思义,就是执行一行
第一个参数,指向命令行字符串的指针
剩下的参数不知道作甚么用的......
用的时候:
封装一下这样用起来方便 function stepline(byval cmd as string) as long 'cmd就是vb6代码 dim l as long '临时变量,意义不大 l = ebexecuteline(strptr(byval cmd), 0, 0, 0) '这就是实质,简单吧 debug.print cstr(l) + ":" + cmd '调试用的,无意义
也可以 stepline "dim a as long,b as long,c as long" stepline "a=" & 3 stepline "b=" & 5 stepline "c=" & 2 stepline "clipboard.settext (a+b)/c" stepline "msgbox clipboard.gettext"
或者将文本放入listbox,甚至可以逐行进行(当然,有兴趣你可以自己做调试器) if list1.listcount = 0 then msgbox "没有代码" else list1.listindex = 0 dim i as long for i = 0 to list1.listcount - 1 stepline list1.list(i) next end if
当然,直接执行文本也是可以的 假定text1.text是全部的代码
list1.clear dim arr() as string dim i as long dim s as string arr = split(text1.text, chr(13) + chr(10)) for i = 0 to ubound(arr()) stepline arr(i) next