Use string to call function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kokain
    New Member
    • Aug 2006
    • 3

    #1

    Use string to call function

    I want to use a string to call a function. I will just post the code because I don't really know the terminology or how to program for that matter. I am using Visual Studio express.

    Public Class Form1

    Dim estt As New Test.Unit.Drive r.Probe

    Dim c As Integer 'counter

    Dim x As Integer 'sensor position

    Dim rw As String 'read/write

    Private Sub ReadButton_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ReadButton.Clic k

    rw = "get" 'set variable to read

    doit()

    End Sub

    Private Sub WriteButton_Cli ck(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles WriteButton.Cli ck

    rw = "set" 'set variable to write

    doit()

    End Sub

    Sub doit()

    x = NumericUpDown1. Value

    For c = NumericUpDown2. Value To NumericUpDown3. Value

    Controls("textb ox" & c).Text = :mad: estt.getProbeTy pe(x) :mad:
    Next

    End Sub

    End Class

    The highlighted portion is the root of my problems. As it is written everything works for that one function. I want it to be controlled by two variables. I need the "get" portion to be the rw variable, and the "ProbeType" to be the text of the corrisponding Label (which the first one happens to be "ProbeType" ). I want it to behave like this, but it will not work Controls("textb ox" & c).Text = estt.(rw) + (controls("Labe l" & c)) + (x)
  • kokain
    New Member
    • Aug 2006
    • 3

    #2
    I forgot to subscribe

    Comment

    • kokain
      New Member
      • Aug 2006
      • 3

      #3
      I am now using callbyname. It works fine for the read portion of my form, but the write side returns an error. The error says that my command dosn't accept this number of arguments. I only need one argument to read (probe position = x) but I need two arguments to write (probe possition = x, new value = b). How do I pass both arguments?

      a = "get" + Controls("Label " & c).Text

      Controls("TextB ox" & c).Text = CallByName(MGDr ive, a, CallType.Get, x)

      The above is the read portion. That works fine.



      a = "set" + Controls("Label " & c).Text 'this holds the string "ProbeType"

      b = Controls("textb ox" & (c + 80)).Text 'this holds the new value

      CallByName(estt , a, CallType.Set, x, b)

      This is the write portion that dosn't work.

      Please help, I think I am so close.

      Comment

      Working...