Search code examples
vb.netstringbuilder

Object Reference Error while trying to put <hr> tag in stringBuilderObject.Append() VB.net


My main aim is to underline some words in pdf with blue color using VB.net. The code is shown below:

strSignHTML.Append("<TD class=""TBLDATA"" width=""25%"" align=left><br /><br>")
strSignHTML.Append("<hr color=""midnightblue"">")
strSignHTML.Append("</TD>")
strSignHTML.Append("<td width=50%>&nbsp;</td>")
strSignHTML.Append("<td class=""TBLDATA"" width=""25%"" align=left> <br>")
strSignHTML.Append("<hr color=""midnightblue"">")
strSignHTML.Append("</td>")
strSignHTML.Append("</tr>")
strSignHTML.Append("<tr>")
strSignHTML.Append("<td class=""TBLDATA"">")
strSignHTML.Append("<font color=""midnightblue""><b>Signature</b></font>")
strSignHTML.Append("</td>")
strSignHTML.Append("<td width=50%>&nbsp;</td>")
strSignHTML.Append("<td class=""TBLDATA"">")
strSignHTML.Append("<font color=""midnightblue""><b>Date</b></font>")
strSignHTML.Append("</td>")
strSignHTML.Append("</tr>")
strSignHTML.Append("<tr>")

Solution

  • After you do import library

    Imports System.Text
    

    And actually set the strSignHTML as StringBuilder you are good to go

        Dim strSignHTML As New StringBuilder
        strSignHTML.Append("<TD class=""TBLDATA"" width=""25%"" align=left><br /><br>")
        strSignHTML.Append("<hr color=""midnightblue"">")
        strSignHTML.Append("</TD>")
        strSignHTML.Append("<td width=50%>&nbsp;</td>")
        strSignHTML.Append("<td class=""TBLDATA"" width=""25%"" align=left> <br>")
        strSignHTML.Append("<hr color=""midnightblue"">")
        strSignHTML.Append("</td>")
        strSignHTML.Append("</tr>")
        strSignHTML.Append("<tr>")
        strSignHTML.Append("<td class=""TBLDATA"">")
        strSignHTML.Append("<font color=""midnightblue""><b>Signature</b></font>")
        strSignHTML.Append("</td>")
        strSignHTML.Append("<td width=50%>&nbsp;</td>")
        strSignHTML.Append("<td class=""TBLDATA"">")
        strSignHTML.Append("<font color=""midnightblue""><b>Date</b></font>")
        strSignHTML.Append("</td>")
        strSignHTML.Append("</tr>")
        strSignHTML.Append("<tr>")
    
        Dim myString As String = strSignHTML.ToString
    

    Even so i would rather use CDATA

    Dim myString As String = <![CDATA[
                    <TD class="TBLDATA" width="25%" align=left><br /><br>
                    <hr color="midnightblue">
                    </TD>
                    <td width=50%>&nbsp;</td>
                    <td class="TBLDATA" width="25%" align=left> <br>
                    <hr color="midnightblue">
                    </td>
                    </tr>
                    <tr>
                    <td class="TBLDATA">
                    <font color = "midnightblue"><b>Signature</b></font>
                    </td>
                    <td width = 50% >& nbsp;</td>
                    <td class="TBLDATA">
                    <font color = "midnightblue"><b>Date</b></font>
                    </td>
                    </tr>
                    <tr>]]>.Value