Results 1 to 10 of 10

Thread: Executing Vb code from a Vb program [SOLOVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Sweden
    Posts
    132

    Smile Executing Vb code from a Vb program [SOLOVED]

    Um i want to execute a VB code from a vb program... I think it works... Like i want to write in a textbox "Msgbox "Hello"" and i want a msgbox to popup.. heelp
    Last edited by Jonte1989; Oct 30th, 2002 at 04:12 PM.
    /Jonte

  2. #2
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    You can use the MS Scripting control, but it is a bit limited....

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Sweden
    Posts
    132
    Jummy, tell me more!
    /Jonte

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Sweden
    Posts
    132
    Hehe that's easy! thanx for the tip!
    /Jonte

  5. #5
    Addicted Member Renee K's Avatar
    Join Date
    Jun 2002
    Posts
    163
    I have posted this one before, but it may be something you can work with.

    Code:
    'Module  Level
    
    Option Explicit
    
    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 Sub Main()    
        Form1.Show
    End Sub
    
    
    Public Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
    
        ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
        
    End Function
      
    
    'Form Level
    
    Private Sub cmdExecute_Click()     
       Call ExecuteLine(txtCode.Text, False)
    End Sub
    .·*¨) ¸.·*¨) ¸.·*¨*
    (¸.*´ ¸.·´*'~*Renee~* (¸.*´~*



    Funny how the little things can stop you dead in your tracks.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Sweden
    Posts
    132
    Is this code working as it is or do i have to edit it some way? I can not get it to wark... Well its late.. good night and thanx in advance.
    /Jonte

  7. #7
    Addicted Member Renee K's Avatar
    Join Date
    Jun 2002
    Posts
    163
    It works the way it is for very simple tasks. Add a module to your project paste in the module code. Place a textbox and a command button on you form behind the command paste in the code. Run the program in the textbox type in msgbox"HELLO"
    press the command button. I am sure with some work it could do more.
    .·*¨) ¸.·*¨) ¸.·*¨*
    (¸.*´ ¸.·´*'~*Renee~* (¸.*´~*



    Funny how the little things can stop you dead in your tracks.

  8. #8
    Hyperactive Member Knowledge_is_Et's Avatar
    Join Date
    Dec 2001
    Location
    An Oak.
    Posts
    305
    It doesn't work compiled, I think the declare statement is bad because it can't find the DLL when compiled. Otherwise that is VERY cool. Better than callbyname...
    Last edited by Knowledge_is_Et; Oct 30th, 2002 at 04:55 PM.
    Now returning to the world of VB. Please make sure your seatbelts are securely fastened and all trays are in their upright and locked position.

  9. #9
    Hyperactive Member Knowledge_is_Et's Avatar
    Join Date
    Dec 2001
    Location
    An Oak.
    Posts
    305
    Ok, i've also noticed you must call things from the lowest level:
    eg: instead of label1.caption = "hi"
    you use form1.label1.caption = "hi"
    just a note, jonte might want to know???

    Amazing that you found this inside the VB dll, what other functions hide in there?
    Now returning to the world of VB. Please make sure your seatbelts are securely fastened and all trays are in their upright and locked position.

  10. #10
    Addicted Member Renee K's Avatar
    Join Date
    Jun 2002
    Posts
    163
    Actually I found the code somewhere on the net. I haven't really done much with it, it has just been a play toy. Like you said you must call things from the lowest level. You have to type in the code simalar to using the debug window. For example, For i = 1 to 10: msgbox "The value of i is = " & i & ".": next i. It is cool, but not alot of use for me. I guess if I was one of these coding experts I could do more with it.
    .·*¨) ¸.·*¨) ¸.·*¨*
    (¸.*´ ¸.·´*'~*Renee~* (¸.*´~*



    Funny how the little things can stop you dead in your tracks.

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