Results 1 to 5 of 5

Thread: [RESOLVED] Executing VB Code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Resolved [RESOLVED] Executing VB Code

    How can i run VB6 code from a textbox like i have a text box on form that textbox contains "msgbox "Hello" and on clicling ok button vb6 should run that code. how can i do this?

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Executing VB Code

    This one
    vb Code:
    1. Option Explicit
    2. Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Foo1 As Long, ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long 'Api Declartion to Execute the VBCode
    3. Function FExecuteCode(stCode As String, Optional fCheckOnly As Boolean) As Boolean
    4.     FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
    5. End Function
    6.  
    7.  
    8. Private Sub Command1_Click()
    9.      FExecuteCode Text1.Text, False
    10. End Sub
    11. 'Make sure that you are giving the right command.Otherwise you wont get 'any output
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Executing VB Code

    Thank you

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: [RESOLVED] Executing VB Code

    EbExecuteLine works only in IDE. In compiled exe, you'll get an error.

    You can use Microsoft Script Control for this:

    vb Code:
    1. ' Add Microsoft Script Control in the form
    2. Option Explicit
    3. Private Sub ExecuteScript(strScript As String)
    4.    
    5.     On Error GoTo ExecuteScript_Err
    6.    
    7.     ScriptControl1.ExecuteStatement Text1.Text
    8.     Exit Sub
    9.    
    10. ExecuteScript_Err:
    11.     If Err.Number = 13 Then
    12.         MsgBox "Syntax Error", vbCritical
    13.     End If
    14.    
    15. End Sub
    16.  
    17. Private Sub Command1_Click()
    18.     ExecuteScript Text1.Text
    19. End Sub
    20.  
    21. Private Sub Form_Load()
    22.     Text1.Text = "MsgBox " & """" & "Hello World" & """"
    23. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: [RESOLVED] Executing VB Code

    thnaks iPrank

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width