-
Jul 10th, 2009, 03:30 PM
#1
Thread Starter
Hyperactive Member
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
-
Jul 10th, 2009, 03:42 PM
#2
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 -
-
Jul 10th, 2009, 03:46 PM
#3
Thread Starter
Hyperactive Member
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
-
Jul 10th, 2009, 03:56 PM
#4
Re: Type 'SetTextCallback' is not defined.
You did not copy this.
Code:
Delegate Sub SetTextCallback(ByVal [text] As String)
-
Jul 10th, 2009, 03:57 PM
#5
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 -
-
Jul 10th, 2009, 05:12 PM
#6
Thread Starter
Hyperactive Member
Re: Type 'SetTextCallback' is not defined.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|