2012-11-02 54 views
1

當我有這樣的代碼在c#代表誤差變換C#到VBNET

void Backup() 
{ 
    string constr = "server=localhost;user=root;pwd=qwerty;database=test;"; 
    string file = "C:\\MyDumpFile.sql"; 
    MySqlBackup mb = new MySqlBackup(constr); 
    mb.ExportInfo.FileName = file; 
    mb.ExportProgressChanged += new MySqlBackup.exportProgressChange(mb_ExportProgressChanged); 
    mb.ExportCompleted += new MySqlBackup.exportComplete(mb_ExportCompleted); 
    timerRead.Start(); 
    mb.Export(); 
} 

當轉換爲VBNet

Private Sub Backup() 
    Dim constr As String = "server=localhost;user=root;pwd=qwerty;database=test;" 
    Dim file As String = "C:\MyDumpFile.sql" 
    Dim mb As New MySqlBackup(constr) 
    mb.ExportInfo.FileName = file 
    mb.ExportProgressChanged = mb.ExportProgressChanged + New MySqlBackup.exportProgressChange(mb_ExportProgressChanged) 
    mb.ExportCompleted = mb.ExportCompleted + New MySqlBackup.exportComplete(mb_ExportCompleted) 
    timerRead.Start() 
    mb.Export() 
End Sub 

我總是得到這個錯誤

'exportProgressChange' 是一個鍵入 'MySql.Data.MySqlClient.MySqlBackup',不能用作 表達式。

我在這裏錯過了什麼?

+0

重複副本重複http://stackoverflow.com/questions/7636382/how-can-i-use-the-following-events-delgates-written-in-c-in-vb-net和http:// stackoverflow.com/questions/9728926/how-to-convert-this-line-from-c-sharp-to-vb-net-windows-phone-7和http://stackoverflow.com/questions/4448323/how- do-i-translate-newbutton-click-delegate-window-isopen-false-in-vb – MarkJ

+0

嗨,Derek Floss,我是MySqlBackup.NET的作者之一。目前,該項目的主要文檔中沒有提供VB.NET的示例。因此,歡迎您在這裏爲VB.NET專門提供文檔:http://mysqlbackupnet.codeplex.com/wikipage?title=Code%20Examples%20in%20VB.NET這將作爲VB.NET未來程序員的參考。謝謝 – mjb

回答

2
Private Sub Backup() 
Dim constr As String = "server=localhost;user=root;pwd=qwerty;database=test;" 
Dim file As String = "C:\MyDumpFile.sql" 
Dim mb As New MySqlBackup(constr) 
mb.ExportInfo.FileName = file 
AddHandler mb.ExportProgressChanged, New MySqlBackup.exportProgressChange(AddressOf mb_ExportProgressChanged) 
AddHandler mb.ExportCompleted, New MySqlBackup.exportComplete(AddressOf mb_ExportCompleted) 
timerRead.Start() 
mb.Export() 
End Sub 

應該工作,原因在VB中,你不能使用+ =爲subcribing一個事件.NET,你必須使用AddHandlerRemoveHandler

編輯:試了一下,所以編譯得很好。