Results 1 to 2 of 2

Thread: Run this code?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Up State NY
    Posts
    525

    Run this code?

    I have a VB2008 application that can run an Exe from a string of data from a database. I use the Process.start(*location*) command.
    But what if I want to run a line of code with in the same exe?

    For example: "me.panel1.clear" or "Call LoadDocs". I need the line executed on command.

    <vb.net2008>
    Private Sub CMD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim RunWhat As String = CType(sender.tag, String)

    </code>

    RunWhat is the string containing the vb.net command I need to run.

    Any ideas guys?
    Last edited by juliemac; May 12th, 2011 at 10:11 AM.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Run this code?

    You will need to use Refection.

    A simple example (not what you asked for but shows an example of using reflection) where a form use created from the name of the form from a string, pass in the name of a known button, text to change the button text.

    The code will show the form, change the button text and call the click event of the button.


    Non-forgiving code
    Code:
    Private Sub Button1_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles Button1.Click
    
       Demo1("frmReports", "cmdExecute", "Done")
    
    End Sub
    Private Sub Demo1( _
       ByVal FormName As String, _
       ByVal ControlName As String, _
       ByVal ControlText As String)
    
       Dim FormInstance As Form = CType( _
          Activator.CreateInstance( _
             Type.GetType( _
                Reflection.Assembly.GetExecutingAssembly _
                   .GetName.Name & "." & FormName)), Form)
    
       Dim Button1 As Button = _
          DirectCast(FormInstance.Controls.Find(ControlName, False)(0), Button)
       Button1.Text = ControlText
    
       FormInstance.Show()
       Button1.PerformClick()
    End Sub
    Check out the following for invoking a method
    http://www.java2s.com/Code/VB/Develo...lectionAPI.htm

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