Is there any way that code stored as a variable in vb can be executed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JSLyndon
    New Member
    • Nov 2015
    • 1

    #1

    Is there any way that code stored as a variable in vb can be executed?

    I want to be able to store my code for a program in a text file or store it as a string in a variable and use a function to execute that code. If anyone knows a way to do this or something similar it would be a great help. Thanks
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #2
    If you are talking about something like batch-file code, or perl or PHP code you can write out as necessary and then call it so that an installed interpreter can "run" it - then yes. Just write it out to a file (with appropriate extension then call it like you would any external program.
    Example:
    Code:
    Dim proc As New System.Diagnostics.Process()
    
    proc = Process.Start("d:\windows\mybatfile.bat", "")
    If, however, you are talking about more vb.net code that would be part of your compiled program - then no. I do not know of any way this can be done - and doubt if it would even be possible.
    I would be curious as to your use-case for this unconventional maneuver?

    Comment

    • IronRazer
      New Member
      • Jan 2013
      • 83

      #3
      It is possible to compile VB Code and run the code in memory or compile the code to an exe file and then run it from a string containing the code in your application.

      However, i would also be interested in the use of this a bit more before i explain any further.

      Comment

      Working...