Results 1 to 3 of 3

Thread: c# to vbnet delegate

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    2

    c# to vbnet delegate

    Hi Ive been trying to translate part of a code using this websites :
    http://www.developerfusion.com/tools.../csharp-to-vb/
    http://converter.telerik.com/

    But I could not make it work specially this part :

    Code:
    bw.DoWork += delegate(object sender2, DoWorkEventArgs e2)
                       {
                           _lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight);
                       };

    This is the source I would like you to help me out :

    Code:
    bw.DoWork += delegate(object sender2, DoWorkEventArgs e2)
         {
             _lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight);
         };
     
         bw.RunWorkerAsync();
     
         // when the background worker is finished, run this anonymous method which either updates
         // the details of the last uploaded image or displays an appropriate error message
         // if there were problems.
         bw.RunWorkerCompleted += delegate(object sender3, RunWorkerCompletedEventArgs e3)
         {
             try
             {
                 if (e3.Error != null)
                 {
                     throw e3.Error;
                 }
                 UpdateLastUploadedImageDisplayDetails(_lastImageUploadDetails); txtInfo.Text = "Image Uploaded.";
             }
             catch (FileNotFoundException exp)
             {
                 txtInfo.Text = exp.Message;
             }
             catch (XmlException exp)
             {
                 txtInfo.Text = exp.Message;
             }
         };
    So please if anybody here knows some c# and vbnet if he could do it I will really appreciate it.
    Regards.

  2. #2
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: c# to vbnet delegate

    Is this what you mean?

    vb.net Code:
    1. Private Sub bw_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bw.DoWork
    2.         _lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight)
    3.     End Sub
    4.  
    5.     Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bw.RunWorkerCompleted
    6.         Try
    7.             If e.Error IsNot Nothing Then
    8.                 Throw (e.Error)
    9.             End If
    10.  
    11.             UpdateLastUploadedImageDisplayDetails(_lastImageUploadDetails)
    12.             txtInfo.Text = "Image Uploaded."
    13.         Catch exp As FileNotFoundException
    14.             txtInfo.Text = exp.Message
    15.         Catch exp As XmlException
    16.             txtInfo.Text = exp.Message
    17.         End Try
    18.  
    19.     End Sub

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: c# to vbnet delegate

    For VB10 - VS 2010 (in earlier versions of VB, this is not nearly as clean, but VB10 has 'Sub' lambdas):

    Code:
    	 AddHandler bw.DoWork, Sub(sender2 As Object, e2 As DoWorkEventArgs) _lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight)
    
    	 bw.RunWorkerAsync()
    
    	 ' when the background worker is finished, run this anonymous method which either updates
    	 ' the details of the last uploaded image or displays an appropriate error message
    	 ' if there were problems.
    	 AddHandler bw.RunWorkerCompleted, Sub(sender3 As Object, e3 As RunWorkerCompletedEventArgs)
    		 Try
    			 If e3.Error IsNot Nothing Then
    				 Throw e3.Error
    			 End If
    			 UpdateLastUploadedImageDisplayDetails(_lastImageUploadDetails)
    			 txtInfo.Text = "Image Uploaded."
    		 Catch exp As FileNotFoundException
    			 txtInfo.Text = exp.Message
    		 Catch exp As XmlException
    			 txtInfo.Text = exp.Message
    		 End Try
    	 End Sub
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width