#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    12
    Rep Power
    0

    VB.NET 2008: Importing Code From a Text File


    Hey everyone,

    I know I'm probably up the creek without a paddle here, but is it at all possible in VB.NET 2008 to import code from a text file? I know it doesn't sound practical, but for a project I'm experimenting with, the code that gets executed all depends on particular options being chosen, and there will be a lot of options to choose from, and the code won't be the same for each.

    If worse comes to worse, I have a couple backup plans to try, but I was just wondering if it's at all possible to write some code in a text file (or other file type if need be), then import that into VB.NET, similar to how it's done when working with HTML and Javascript. I know I'm looking at a long shot here.

    UPDATE: Never mind, I'm pretty sure now this can't be done, at least not easily.
  2. #2
  3. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1511
    It's possible, but not recommended. What you're asking about is an Eval() function, and those are not a good idea for general purpose languages like VB. It's really intended for for sandboxed languages like javascript. In dynamic languages like Ruby or Python, if you use Eval() it's probably a security hole.

    .Net offers two alternatives:

    One is to load a class library (dll) at runtime using Assembly.LoadFile()
    The other is to use a domain specific language.

    Both allow you to load arbitrary code at runtime in safer context.
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    9
    Rep Power
    0

    Smile


    Hello NeoScyther,

    Its possible but not recommended.Actually the main thing is SREAMREADER AND STREAMWRITER which basically helps you to read and write the file.

    then,

    Imports System.IO
    Dim FileReader As StreamReader

    then put

    Dim results As DialogResult

    results = OpenFileDialog1.ShowDialog

    If results = DialogResult.OK Then

    'Code to be executed if OK button was clicked

    Else

    'Code to be executed if Cancel button was clicked

    End If

    End Sub



    I think it will help you

IMN logo majestic logo threadwatch logo seochat tools logo