Click here to Skip to main content
15,911,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i have a code to call a method is like below
VB
dim r as integer
 r = Add(a,b)

i need to change the method Add instead subtract or multiplication etc.. so that i have store all method names in database and load that method names to Combobox at runtime
then i have form code in string format like below
VB
dim str as string
str="r=" & Combobox1.selectedItem & "(a,b)"
// combobox1.selectedtext is Add 
//and str is Add(a,b)  

now i need execute/evalute the above line
plz give suggestions.....

thanks in advance
Posted
Updated 12-Apr-12 1:30am
v2

hey

try following
VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
       MessageBox.Show(Calculate(ComboBox1.SelectedItem, 10, 5).ToString())
   End Sub

   Private Function Calculate(ByVal functionName As String, ByVal a As Integer, ByVal b As Integer) As Integer

       If functionName = "Add" Then
           Return a + b
       ElseIf functionName = "Minus" Then
           Return a - b
       Else
           Return a / b
       End If

   End Function

Best Luck
 
Share this answer
 
Hi,
One powerful way is to use CodeDOM. Take a look at these post to find out about CodeDOM:
Dynamic Code Generation Using CodeDOM[^]
Compiling with CodeDom[^]

I hope it helps,
Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900