Converting from C# to VB.NET


#1

I was wondering if I could get some help. I can get the following to work in C# but was wondering how to do it in VB.NET.


Dim doc As New Document
doc = New Document(MapPath(".") + "\\.\\Documents\\CurriculumMap.doc")

doc.MailMerge.MergeField += New MergeFieldEventHandler(HandleMergeFieldEvent)


private void HandleMergeFieldEvent(object sender, MergeFieldEventArgs e)
{
if (e.FieldName == "Mod_Desc")
{
builder.MoveToMergeField(e.FieldName);
string strTemp = e.FieldValue.ToString();
// for(int i = 0; i < strTemp.Length-1; i++)
// {
//
// }
builder.InsertHtml(strTemp);

}
if (e.FieldName == "Mod_Comment")
{
builder.MoveToMergeField(e.FieldName);
string strTemp = e.FieldValue.ToString();

builder.InsertHtml(strTemp);
}
if (e.FieldName == "Materials")
{
builder.MoveToMergeField(e.FieldName);
string strTemp = e.FieldValue.ToString();
strTemp = "

    " + strTemp + "</ul";
    builder.InsertHtml(strTemp);
    }
    }

    Thanks for any help!


#2

I presume you have a problem with creating an event handler in VB.NET. MSDN is a great resource to learn more about .NET and the programming language you are using.

For C# to VB.NET conversion I mostly use this http://www.123aspx.com/redir.aspx?res=31853, although it has limitations.

Basically it looks like this:

'Note you have New Document twice in you code above, it’s fixed her.
Dim doc As New Document(MapPath(".") + “\.\Documents\CurriculumMap.doc”)

AddHandler doc.MailMerge.MergeField, AddressOf HandleMergeFieldEvent

Sub HandleMergeFieldEvent(ByVal sender As Object, ByVal e As MergeFieldEventArgs)
If e.FieldName = “Mod_Desc” Then
builder.MoveToMergeField(e.FieldName)
Dim strTemp As String = e.FieldValue.ToString()
builder.InsertHtml(strTemp)
End If
If e.FieldName = “Mod_Comment” Then
builder.MoveToMergeField(e.FieldName)
Dim strTemp As String = e.FieldValue.ToString()
builder.InsertHtml(strTemp)
End If
If e.FieldName = “Materials” Then
builder.MoveToMergeField(e.FieldName)
Dim strTemp As String = e.FieldValue.ToString()
strTemp = “

    ” + strTemp + “</ul”
    builder.InsertHtml(strTemp)
    End If
    End Sub