Results 1 to 7 of 7

Thread: Text to FUnction Name

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,135

    Text to FUnction Name

    I have few columns in a datagridview,out of which one is of type Button and another is of TextBox(which is hidden). When the user clicks on the button in the column , i want to execute the function whose name is written in the corresponding column.

    plz help

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Text to FUnction Name

    You can get the value of the text box. So after that use selct case.
    Code:
     Select Case gridTextBox.text
                Case "ABC"
                    Call ABC()
                Case "XYZ"
                    Call XYZ()
            End Select
    thanks
    amrita

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,135

    Re: Text to FUnction Name

    Sorry, i should have mentioned,
    this(cases) is what i am trying to avoid

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text to FUnction Name

    vb Code:
    1. Imports System.Reflection
    2.  
    3. Public Class Form1
    4.     Sub Say(ByVal Arg1 As String, ByVal arg2 As String)
    5.         MsgBox(Arg1 & arg2)
    6.     End Sub
    7.  
    8.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    9.         Dim MethodName As String = "Say"
    10.         Dim Args() As String = {"Hello, ", "World"}
    11.         Dim thistype As Type = GetType(Form1)
    12.         Dim mi As MethodInfo = thistype.GetMethod(MethodName)
    13.         mi.Invoke(Me, Args)
    14.     End Sub
    15. End Class

  5. #5
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Text to FUnction Name

    Use
    Code:
     CallByName(Me, gridTextBox.text, CallType.Method)
    thanks
    amrita

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,267

    Re: Text to FUnction Name

    Quote Originally Posted by aashish_9601 View Post
    Sorry, i should have mentioned,
    this(cases) is what i am trying to avoid
    Even though cicatrix has given you an answer, why are you trying to avoid Select Case?

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles Button1.Click
            Dim wordsToExecute() As String = New String() {"one", "two", "three"} 'simulate hidden textbox values
            For Each word As String In wordsToExecute
                doWord(word)
            Next
        End Sub
    
        Private Sub doWord(ByVal word As String)
            Select Case word
                Case "one"
                    Stop
                Case "two"
                    Stop
                Case "three"
                    Stop
            End Select
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text to FUnction Name

    Quote Originally Posted by dbasnett View Post
    Even though cicatrix has given you an answer, why are you trying to avoid Select Case?
    I second that. Select case is probably a better solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width