Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to develop a VB .NET Windows Form Application FTP client that uses the C# .NET FTPLibrary.dll that I obtained from The Code Project article "A Windows FTP Client". I am also converting and using significant amount of the code from the article which, for the most part, I have been able to successfully convert to VB .NET using Developer Fusion's C# to VB code converter. The dll has a new message handler (NewMessageHandler) which is used in the article's main form (frmMain). There is a C# .NET statement in the SetFtpClient() method of frmMain that I am unable to convert to VB .NET. I have boxed the statement I need help with converting to VB .NET with " ===== " statements. I am in over my head with this problem. I will sincerely appreciate help with Solving the problem. I have included the relevant code from the dll and from frmMain below.

C# .NET FTPLibrary.dll Code:
VB
//New Server Message Event
public delegate void NewMessageHandler(object sender, NewMessageEventArgs e);
public event NewMessageHandler OnNewMessageReceived;

VB .NET frmMain.vb Code:
VB
' Setup On Message Received Event
Private Sub FtpClient_OnNewMessageReceived(ByVal myObject As Object, ByVal e As NewMessageEventArgs)
Message = New ListViewItem()
Message.Text = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString()
Message.SubItems.Add(e.StatusType)
Message.SubItems.Add(e.StatusMessage)
Message.SubItems.Add(e.StatusCode)
Message.SubItems.Add(txtRemoteDirectory.Text)
lstMessages.Items.Add(Message)
Me.lstMessages.EnsureVisible(Me.lstMessages.Items.Count - 1)
End Sub

Public Sub SetFtpClient(ByVal client As WinFTP.Library.FTPclient)
' Set FTP client
FtpClient = client

' Display the welcome message
Message = New ListViewItem()
Message.Text = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString()
Message.SubItems.Add("Welcome Message")
Message.SubItems.Add(FtpClient.WelcomeMessage)
Message.SubItems.Add("No Code")
Message.SubItems.Add("/")
lstMessages.Items.Add(Message)

' =========================== C# .NET Code ============================

' Setup on message received Event
FtpClient.OnNewMessageReceived += New FTPclient.NewMessageHandler(FtpClient_OnNewMessageReceived);

' ================================================================


' Open and display root directory and files and folders in it
For Each folder As FTPfileInfo In FtpClient.ListDirectoryDetail("/")
Dim item As New ListViewItem()
item.Text = folder.Filename

If folder.FileType = FTPfileInfo.DirectoryEntryTypes.Directory Then
item.SubItems.Add("Folder")
Else
item.SubItems.Add("File")
End If

item.SubItems.Add(folder.FullName)
item.SubItems.Add(folder.Permission)
item.SubItems.Add(folder.FileDateTime.ToShortTimeString() + _
folder.FileDateTime.ToShortDateString())
item.SubItems.Add(GetFileSize(folder.Size))
lstRemoteFiles.Items.Add(item)
Next
End Sub
Posted
Updated 6-Mar-11 4:56am
v2
Comments
mehdi Saghari 19-Jul-11 5:15am    
for example how can i convert this simple c# code to vb?!
private void ValidateUser()
{
LinqChatReference.LinqChatServiceClient proxy = new LinqChatReference.LinqChatServiceClient();
proxy.UserExistCompleted += new EventHandler<silverlight2chat.linqchatreference.userexistcompletedeventargs>(proxy_UserExistCompleted);
proxy.UserExistAsync(TxtUserName.Text, PbxPassword.Password);
}

void proxy_UserExistCompleted(object sender, Silverlight2Chat.LinqChatReference.UserExistCompletedEventArgs e)
{
if (e.Error == null)
{
int userID = e.Result;

if (userID != -1)
{
// go to the chatroom page
App app = (App)Application.Current;
app.UserID = userID;
app.UserName = TxtUserName.Text;
app.RedirectTo(new Chatroom());
}
else
{
TxtbNotfound.Visibility = Visibility.Visible;
}
}
}

1 solution

I hope that I have not misunderstood your question but for event handlers the += is analogous to VB's AddHandler[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Mar-11 13:56pm    
That simple, my 5
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900