Click to See Complete Forum and Search --> : Can anyone change the code from C# to vb.net?


galaxy_thestars
May 18th, 2008, 10:01 AM
Can anyone change code from C# to vb.net. The code is as below:

public void UpdateTextBox(string data)
{
if ( txtOutput.InvokeRequired )
txtOutput.Invoke(new OutputUpdateDelegate(OutputUpdateCallback),
new object[] { data });
else
OutputUpdateCallback(data); //call directly
}

private void OutputUpdateCallback(string data)
{
txtOutput.Text += data;
}

I have tried and that has error on row
txtOutput.Invoke(new OutputUpdateDelegate(OutputUpdateCallback),

My code is

Public Sub UpdateTextBox(ByVal data As String)

If (TextBox2.InvokeRequired) Then
TextBox2.Invoke(New OutputUpdateDelegate(OutputUpdateCallback), New Object() {data})
Else
OutputUpdateCallback(data) ' //call directly
End If
End Sub

Private Sub OutputUpdateCallback( data As String)

TextBox2.Text += Data
End Sub


thanks in advance

dglienna
May 18th, 2008, 10:18 AM
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]

del = New MyDelSub(AddressOf WriteToDebug)
del2 = New MyDelSub(AddressOf WriteToDebug2)
delAll = MulticastDelegate.Combine(del, del2)
delAll.DynamicInvoke( Nothing )


http://www.developerfusion.co.uk/show/5251/2/

galaxy_thestars
May 18th, 2008, 10:58 AM
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]

del = New MyDelSub(AddressOf WriteToDebug)
del2 = New MyDelSub(AddressOf WriteToDebug2)
delAll = MulticastDelegate.Combine(del, del2)
delAll.DynamicInvoke( Nothing )


http://www.developerfusion.co.uk/show/5251/2/

it do not relate to above. Isn't it??

David Anton
May 18th, 2008, 07:26 PM
(via Instant VB):

Public Sub UpdateTextBox(ByVal data As String)
If txtOutput.InvokeRequired Then
txtOutput.Invoke(New OutputUpdateDelegate(AddressOf OutputUpdateCallback), New Object() { data })
Else
OutputUpdateCallback(data) 'call directly
End If
End Sub

Private Sub OutputUpdateCallback(ByVal data As String)
txtOutput.Text += data
End Sub

galaxy_thestars
May 19th, 2008, 10:37 AM
ok thanks

Marraco
May 19th, 2008, 11:50 AM
For small pieces of code, here is an online automatic translator.

http://www.carlosag.net/Tools/CodeTranslator/default.aspx

Use with care.
_