Cumbersome Solution

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Garth

    #1

    Cumbersome Solution

    I ran into a small issue and I found a solution however it is cumbersome to use.

    The problem and solution is describe within the MSDN article http://msdn2.microsoft.com/en-us/lib...28(d=ide).aspx

    I would like to create one subroutine for all my textboxes and not one for each textbox, given the sample subroutine below, how can I add the textbox name into this subroutine?

    Cumbersome Solution

    Private Sub SetText(ByVal [text] As String)

    ' InvokeRequired required compares the thread ID of the

    ' calling thread to the thread ID of the creating thread.

    ' If these threads are different, it returns true.

    If Me.tb_Netbios.I nvokeRequired Then

    Dim d As New SetTextCallback (AddressOf SetText)

    Me.Invoke(d, New Object() {[text]})

    Else

    Me.tb_Netbios.T ext = [text]

    End If

    End Sub

  • Branco Medeiros

    #2
    Re: Cumbersome Solution

    Garth wrote:
    <snip>
    I would like to create one subroutine for all my textboxes and not
    one for each textbox, given the sample subroutine below, how can I
    add the textbox name into this subroutine?
    <snip>
    Private Sub SetText(ByVal [text] As String)
    <snip>
    If Me.tb_Netbios.I nvokeRequired Then
    Dim d As New SetTextCallback (AddressOf SetText)
    Me.Invoke(d, New Object() {[text]})
    Else
    Me.tb_Netbios.T ext = [text]
    End If
    End Sub
    One approach is to add the target TextBox as parameter:

    Private Delegate Sub SetTextCallback (T As TextBox, V As String)
    '...
    Private Sub SetText(ByVal Target As TextBox, _
    ByVal NewValue As String)
    If Target.InvokeRe quired Then
    Dim D As New SetTextCallback (AddressOf SetText)
    Target.Invoke(D , New Object() {Target, NewValue})
    Else
    Target.Text = NewValue
    End If
    End Sub
    '...
    Sub BtnClick(...)
    SetText(Me.Some TextBox, NewValue)
    '....
    End Sub

    HTH.

    Regards,

    Branco.

    Comment

    • Garth

      #3
      Re: Cumbersome Solution

      Thanks Branco as i'm sure you already know, I'm still very green with
      VB.Net.


      "Branco Medeiros" <branco.medeiro s@gmail.comwrot e in message
      news:1152675508 .678031.271670@ i42g2000cwa.goo glegroups.com.. .
      Garth wrote:
      <snip>
      > I would like to create one subroutine for all my textboxes and not
      > one for each textbox, given the sample subroutine below, how can I
      > add the textbox name into this subroutine?
      <snip>
      > Private Sub SetText(ByVal [text] As String)
      <snip>
      > If Me.tb_Netbios.I nvokeRequired Then
      > Dim d As New SetTextCallback (AddressOf SetText)
      > Me.Invoke(d, New Object() {[text]})
      > Else
      > Me.tb_Netbios.T ext = [text]
      > End If
      >End Sub
      >
      One approach is to add the target TextBox as parameter:
      >
      Private Delegate Sub SetTextCallback (T As TextBox, V As String)
      '...
      Private Sub SetText(ByVal Target As TextBox, _
      ByVal NewValue As String)
      If Target.InvokeRe quired Then
      Dim D As New SetTextCallback (AddressOf SetText)
      Target.Invoke(D , New Object() {Target, NewValue})
      Else
      Target.Text = NewValue
      End If
      End Sub
      '...
      Sub BtnClick(...)
      SetText(Me.Some TextBox, NewValue)
      '....
      End Sub
      >
      HTH.
      >
      Regards,
      >
      Branco.
      >

      Comment

      Working...