Question How to run this code?

juliemac

New member
Joined
Apr 19, 2005
Messages
4
Programming Experience
10+
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 application?

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?
 
I am not sure if this possible in some other way but the best way that I could think of would be to use command line arguments and then code your application to do only certain things and exit based on the argument you specify:

VB.NET:
'Returns an array of strings (your arguments)(space delimited)
Environment.GetCommandLineArgs()

You can specify your arguments in MyProject for testing purposes.
 
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 application?

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?
I'm not sure exactly how you'll need to go about it, but I think you can marshal strings into actual runnable code.

Here's a link I did find via Google search that may be of some use to you: Build A Custom .NET "Eval" Provider
Also: Runtime Compilation (A .NET eval statement) - CodeProject
 
I can be a real twit some times.

2 options stored in the database.
1- Clear Panels
2- Fill Panels.

Select case the string, do either function dependant on which string found.

Sheesh. But. It would be interesting to see if a command, stored and pulled from a database could be executed with in the pulling app.
 
juliemac said:
But. It would be interesting to see if a command, stored and pulled from a database could be executed with in the pulling app.

Below would work for if you are talking about only upon startup of the process, for an application that is already running what Juggalo said would work, and would be interesting to see how it would get implemented, but anyways below is to open an application with command arguments passed to it and then do something based on the command specified:

assuming strCmd as what is in your database in format xxx.exe cmd1 or xxx.exe cmd2
add this code into the your form load
Sub Form_Load(......)
   Dim blFirstPass As Boolean = True
   For each str as string in Environment.GetCommandLineArgs()
      'first pass will be the executable name always so this function never returns nothing
      If not blFirstPass Then
         Select str.ToLower()
           Case "cmd1"
              ClearPanels()
           Case "cmd2"
              FillPanels()
         End Select
      End If
      blFirstPass = false
   Next str
End Sub
 
Back
Top