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聲明,顧名思義,就是執(zhí)行一行
第一個(gè)參數(shù),指向命令行字符串的指針
剩下的參數(shù)不知道作甚么用的......
用的時(shí)候:
封裝一下這樣用起來(lái)方便 function stepline(byval cmd as string) as long 'cmd就是vb6代碼 dim l as long '臨時(shí)變量,意義不大 l = ebexecuteline(strptr(byval cmd), 0, 0, 0) '這就是實(shí)質(zhì),簡(jiǎn)單吧 debug.print cstr(l) + ":" + cmd '調(diào)試用的,無(wú)意義
也可以 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,甚至可以逐行進(jìn)行(當(dāng)然,有興趣你可以自己做調(diào)試器) if list1.listcount = 0 then msgbox "沒(méi)有代碼" else list1.listindex = 0 dim i as long for i = 0 to list1.listcount - 1 stepline list1.list(i) next end if
當(dāng)然,直接執(zhí)行文本也是可以的 假定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