Type 'SetTextCallback' is not defined.-VBForums
Results 1 to 6 of 6

Thread: Type 'SetTextCallback' is not defined.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Type 'SetTextCallback' is not defined.

    Why Am I getting this error:

    Type 'SetTextCallback' is not defined.

    Code:
        Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click
            Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
            CMDThread.Start()
        End Sub
    
        Private Sub CMDAutomate()
            Dim i = 0
            Dim rows = 10
            While i < rows
                Dim newText As String = "Creating file"
                ' Check if this method is running on a different thread
                ' than the thread that created the control.
                If Me.lblStatus.InvokeRequired Then
                    ' It's on a different thread, so use Invoke.
                    Dim d As New SetTextCallback(AddressOf SetText)
                    Me.InvokePaint(d, New Object() {[newText]})
                Else
                    ' It's on the same thread, no need for Invoke.
                    Me.lblStatus.Text = [newText]
                End If
            End While
        End Sub
    I basically copied and pasted from:
    http://msdn.microsoft.com/en-us/library/ms171728.aspx
    I am still very new to VB.NET, so I have MANY questions

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,237

    Re: Type 'SetTextCallback' is not defined.

    From that code, SetTextCallBack is a delegate and SetText is a method.
    You will need to write them yourself.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Re: Type 'SetTextCallback' is not defined.

    I have this too, I still get the error

    Code:
        Private Sub SetText(ByVal [text] As String)
            Me.lblStatus.Text = [text]
        End Sub
    I am still very new to VB.NET, so I have MANY questions

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,702

    Re: Type 'SetTextCallback' is not defined.

    You did not copy this.

    Code:
    Delegate Sub SetTextCallback(ByVal [text] As String)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,237

    Re: Type 'SetTextCallback' is not defined.

    The whole thing should look like this:
    Code:
     Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click
            Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
            CMDThread.Start()
        End Sub
    
        Private Sub CMDAutomate()
            Dim i = 0
            Dim rows = 10
            While i < rows
                Dim newText As String = "Creating file"
                SetText(newText)
           End While
        End Sub
    
    Private Delegate Sub SetTextCallback(ByVal [text] As String)
    
        Private Sub SetText(ByVal newText As String)
            If Me.lblStatus.InvokeRequired Then
                ' It's on a different thread, so use Invoke.
                Dim d As New SetTextCallback(AddressOf SetText)
                Me.Invoke(d, New Object() {newText})
            Else
                ' It's on the same thread, no need for Invoke.
                Me.lblStatus.Text = newText
            End If
    
        End Sub
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Re: Type 'SetTextCallback' is not defined.

    Thanks, it works!
    I am still very new to VB.NET, so I have MANY questions

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.