As a general rule, you can transform C# to
VB pretty easily.
The biggest differences:
(1) C# uses the form
typename variablename to declare variables.
VB uses
DIM variablename AS typename.
VB also allows a more compact form when creating a NEW instance of a class, as we'll see below.
(2) C# uses a semicolon on the end of every statement and a statement can continue across as many lines as needed.
VB does not use a semicolon and if a statement must continue across multiple lines you must use an underline at the end of each line to signify continuation.
(3) C# uses
\n to indicate an embedded new line character and other backslash-letter combinations to indicate other special characters.
VB does none of that. So you must append a newline separately to a string and you don't need to use \\ to indicate a single \ in the string.
****
There are other differences, of course, but mostly these are pretty simple (and wordier!) transformations.
So here is a *SAMPLE* of a translation of PART of that code:
Code:
Protected Sub btnExport_Click(sender As Object, e As EventArgs)
Dim form As new HtmlForm() ' notice how we only mention the type name once! NICE!
form.Controls.Add(GridView1)
Dim sw As new StringWriter()
Dim hTextWriter As new HtmlTextWriter(sw)
form.Controls[0].RenderControl(hTextWriter)
Dim html As String = sw.ToString( )
Dim Doc As new Document()
PdfWriter.GetInstance( Doc, _
newFileStream( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) _
+ "\AmitJain.pdf", _
FileMode.Create) _
)
Doc.Open()
Dim c As new Chunk( "Export GridView to PDF Using iTextSharp " & vbNewLine, _
FontFactory.GetFont("Verdana", 15) _
)
Dim p As new Paragraph()
p.Alignment = Element.ALIGN_CENTER
p.Add(c)
Dim chunk1 = As new Chunk( "By Amit Jain, [email protected] " & vbNewLine, _
FontFactory.GetFont("Verdana", 8) _
)
Dim p1 As new Paragraph()
p1.Alignment = Element.ALIGN_RIGHT
p1.Add(chunk1)
Doc.Add(p)
Doc.Add(p1)
Dim xmlReader As new System.Xml.XmlTextReader(newStringReader(html))
HtmlParser.Parse(Doc, xmlReader)
Doc.Close()
... and so on ...