1

I have made a vb project that works with registry and system management but my code is like this:

CheckAnswer(question_id)

it means that each question has own works with sys registry and sys management and I wanted that the program read each question from file at runtime. my CheckAnswer body function that I made is :

Private Sub CheckAnswer(ByVal id As Integer)
    Dim mark As Integer
    mark = 0
    ''''''''''''''''''''''
    Select Case id

        Case 1

            Dim r As Rectangle = Nothing
            If GetTaskBarPosition(r, Me.Handle) Then
                If r.Y = 0 And r.X = 0 Then mark = 1
            End If


        Case 2

            If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\", "TaskbarSizeMove", 1) = 0 Then mark = 1
end case

but I wanted to do this work at runtime and say to program that read function from a file not from the source code for flexibility and adding new questions without changing the program source and just with changing the function file.


I have searched this site and others for code generation and the other things like this and code provider. I have get a project from "code project" but give me compile errors.

I do not want to generate separate class code because I have implemented imports and libraries in my own class and I want to say the program just which one of them I want to use in my function file.

embert
  • 7,336
  • 10
  • 49
  • 78

1 Answers1

1

It is possible to write VB.Net script files and execute them at runtime using the VBCodeProvider, in the future you will be able to make use of the Roslyn compiler if required.

I have a short code example for compiling and running C# Scripts, to make it work for VB.Net you would simply need to convert the code from C#, and use the VB.Net provider.

Another option would be to use F# which supports script files out-of-the-box (extension .fsx) which can be easily edited and executed.

Community
  • 1
  • 1
Phillip Trelford
  • 6,513
  • 25
  • 40