Execute the VB code in the VB Program (convert the string into the VB code in the VB Program)

Source: Internet
Author: User
'  Add a command and text  

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

Function Executeline (scode As String , Optional Fcheckonly As Boolean ) As Boolean
Executeline = ebexecuteline (strptr (scode ), 0 &, 0 &, ABS (Fcheckonly) = 0
End Function

Private Sub Commandmediaclick ()
Dim DM () As String
Dim I As Long
Dm = Split (Text1, vbcrlf)
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 & " Row execution error "
Else
Debug. Print I + 1 & Vbtab & " LineCodeError "
End If
Next
End sub

 

AboveProgramAfter execution, enter the VB Code (for example, msgbox "VB") in text1 and click command1 to execute the VB code in text1. If a line of code is empty, a line of code error is prompted, if a syntax error occurs in the line code, the system will prompt the line execution error. (ALL prompts are displayed in the prompt window)

The above code has room for improvement (such as prompting why the error occurs, changing the syntax color, and so on)

girls do not cry (QQ: 191035066) @ 2011-12-23 22:08:41
http://www.cnblogs.com/nbsofer/archive/2011/12/23/2298788.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.