【文件属性】:
文件名称:VB6 执行String语句
文件大小:2KB
文件格式:TXT
更新时间:2017-01-04 09:52:07
VB6 String
首先:Imports System.Runtime.InteropServices
然后:
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
' Public Shared Function EbExecuteLine(ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
' Public Shared Function EbExecuteLine(ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
'End Function
'
'Public Shared Function EbExecuteLine(ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
'End Function
'定义StrPtr函数,实现获取字符串地址功能
Private Function StrPtr(ByVal e As Object) As Int32
Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(e, System.Runtime.InteropServices.GCHandleType.Pinned)
Dim GC2 As Int32 = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return GC2
End Function
Function ExecuteLine(ByVal sCode As String, Optional ByVal fCheckOnly As Boolean = True) As Boolean
ExecuteLine = EbExecuteLine(StrPtr(sCode), 0, 0, 0)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dm() As String
Dim i As Long
dm = Split(TextBox.Text, ";")
For i = 0 To UBound(dm)
If Len(dm(i)) <> 0 Then
Dim Result As Boolean
Result = ExecuteLine(dm(i))
If Result = False Then Debug.Print(i + 1 & vbTab & "行执行错误")
Else
Debug.Print(i + 1 & vbTab & "行代码错误")
End If
Next
End Sub