1

Is it possible to convert, say, a textbox input to working code?

For example, user types 'if x<10 then y=2 else y=5' into textbox1, it gets used directly as code something like ...

dim x as integer = 5
dim y as integer = 0
include processed textbox1.text
resultbox.text = (y*20).tostring

It's not important why this would be needed - just whether there is any straight-forward method that parses a string to code.

Many thanks.

3
  • stackoverflow.com/questions/23325180/… Commented Feb 24, 2015 at 11:37
  • Does it have to run as code as it is, or can you parse the input text to get the required parts and act on them as appropriate? Commented Feb 24, 2015 at 11:40
  • yes the code has to run as if it were written as code Commented Feb 24, 2015 at 17:45

2 Answers 2

0

Maybe this is what you are looking for:

http://www.codeproject.com/Articles/12852/Compile-and-Run-VB-NET-Code-using-the-CodeDom

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Alu. As with Matt's suggestion below I'll have to work through the demo for this to see exactly what it does. I was keeping fingers crossed for a simple 'compileThis' kinda class but looks like will be a significant amount of investigating :)
I'm currently working through this and looking at implementing it within my form. Hopefully all goes smoothly. Many thanks again.
0

yes you can do this using the VBCodeProvider class. Although the amount of code required is quite significant:

http://www.codeproject.com/Articles/5472/Compiling-NET-code-on-the-fly

2 Comments

Thanks Matt - this looks a bit over my head at the moment but could well be what I need. I'll try to run through the demo tomorrow to see if it becomes clearer when running an actual test.
I've had a look at this and the VBCodeProvider does indeed seem to be what I need. This link will help others with similar issues though I think Alu's link is more suitable for my personal abilities and needs. Many thanks again for confirming the feasibility of this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.