bossman1111 bossman1111 - 3 months ago 15
C# Question

Converting VBA HTML to C#

Can someone convert or tell me how to implement the below HTML so I can use it in a C method? Its for a STMP email which I have working, I just need the body in this format which I got from VBA.

sBody = sBody & sRequestTypeDescription & " analysis requested"
sBody = sBody & "<BR><BR>"

If Len(sAssignComments) > 3 Then
sBody = sBody & "<BR>"
sBody = sBody & "Please note these additional comments from the assigner: "
sBody = sBody & "<BR><BR>"
sBody = sBody & "<b>" & sAssignComments & "</b>"
sBody = sBody & "<BR><BR>"
End If
sBody = sBody & "<Table border=""1"">"
sBody = sBody & "<TR>"
sBody = sBody & "<TH align=""left""><NOBR><U>ProgramID</U></NOBR></TH>"
sBody = sBody & "<TH align=""center""><NOBR><U>Cedant</U></NOBR></TH>"
sBody = sBody & "<TH align=""center""><NOBR><U>UW</U></NOBR></TH>"
sBody = sBody & "<TH align=""center""><NOBR><U>Due By</U></NOBR></TH>"
sBody = sBody & "<TH align=""center""><NOBR><U>Notes</U></NOBR></TH>"
sBody = sBody & "<TH align=""center""><NOBR><U>Assigned By</U></NOBR></TH>"
sBody = sBody & "</TR> "

sBody = sBody & "<TR>"
sBody = sBody & "<TD align=""left""><NOBR>" & g_ProgramID & "</NOBR></TD>"
sBody = sBody & "<TD align=""right""><NOBR>" & oRS.Fields("Cedant") & "</NOBR></TD>"
sBody = sBody & "<TD align=""right""><NOBR>" & sUWCode & "</NOBR></TD>"
sBody = sBody & "<TD align=""Center""><NOBR>" & Format(dRequired, "mm/dd/yy") & "</NOBR></TD>"
sBody = sBody & "<TD align=""left"" width=""200"">" & oRS("Comments") & "</TD>"
sBody = sBody & "<TD align=""right""><NOBR>" & sAssignedBy & "</NOBR></TD>"
sBody = sBody & "</TR>"

sBody = sBody & "</TABLE>"
sBody = sBody & "<BR><BR>"

Answer

SO is not a translation service but I like these tasks

You need to fix oRS.Fields("Cedant")and Format(dRequired, "mm/dd/yy") yourself

  • change all sBody = sBody & to sBody +=
  • all & to +
  • All ifs will be on the form if (statement) { and all end-ifs will be }
  • Add semicolons to each statement
  • investigate the stringBuilder

Minimum effort:

sBody += sRequestTypeDescription + " analysis requested";
sBody += "<BR><BR>";

if (sAssignComments.length > 3) {
   sBody += "<BR>";
   sBody += "Please note these additional comments from the assigner: ";
   sBody += "<BR><BR>";
   sBody += "<b>" + sAssignComments + "</b>";
   sBody += "<BR><BR>";
}
sBody += "<Table border=\"1\">";
sBody += "<TR>";
sBody += "<TH align=\"left\"><NOBR><U>ProgramID</U></NOBR></TH>";
sBody += "<TH align=\"center\"><NOBR><U>Cedant</U></NOBR></TH>";
sBody += "<TH align=\"center\"><NOBR><U>UW</U></NOBR></TH>";
sBody += "<TH align=\"center\"><NOBR><U>Due By</U></NOBR></TH>";
sBody += "<TH align=\"center\"><NOBR><U>Notes</U></NOBR></TH>";
sBody += "<TH align=\"center\"><NOBR><U>Assigned By</U></NOBR></TH>";
sBody += "</TR>    ";

sBody += "<TR>";
sBody += "<TD align=\"left\"><NOBR>" + g_ProgramID + "</NOBR></TD>";
sBody += "<TD align=\"right\"><NOBR>" + oRS.Fields("Cedant") + "</NOBR></TD>";
sBody += "<TD align=\"right\"><NOBR>" + sUWCode + "</NOBR></TD>";
sBody += "<TD align=\"center\"><NOBR>" + Format(dRequired, "mm/dd/yy") + "</NOBR></TD>";
sBody += "<TD align=\"left"" width=\"200\">" + oRS("Comments") + "</TD>";
sBody += "<TD align=\"right\"><NOBR>" + sAssignedBy + "</NOBR></TD>";
sBody += "</TR>";

sBody += "</TABLE>";
sBody += "<BR><BR>";

Using StringBuilder instead (without going into TOO many loops like appendFormat)

  • All sBody += to sb.AppendLine(
  • all "; to ");

Result:

StringBuilder sb = new StringBuilder();
sb.AppendLine(sRequestTypeDescription + " analysis requested");
sb.AppendLine("<BR><BR>");
if (sAssignComments.length > 3) {
   sb.AppendLine("<BR>");
   sb.AppendLine("Please note these additional comments from the assigner: ");
   sb.AppendLine("<BR><BR>");
   sb.AppendLine("<b>" + sAssignComments + "</b>");
   sb.AppendLine("<BR><BR>");
}
sb.AppendLine("<Table border=\"1\">");
sb.AppendLine("<TR>");
sb.AppendLine("<TH align=\"left\"><NOBR><U>ProgramID</U></NOBR></TH>");
sb.AppendLine("<TH align=\"center\"><NOBR><U>Cedant</U></NOBR></TH>");
sb.AppendLine("<TH align=\"center\"><NOBR><U>UW</U></NOBR></TH>");
sb.AppendLine("<TH align=\"center\"><NOBR><U>Due By</U></NOBR></TH>");
sb.AppendLine("<TH align=\"center\"><NOBR><U>Notes</U></NOBR></TH>");
sb.AppendLine("<TH align=\"center\"><NOBR><U>Assigned By</U></NOBR></TH>");
sb.AppendLine("</TR>    ");

sb.AppendLine("<TR>");
sb.AppendLine("<TD align=\"left\"><NOBR>" + g_ProgramID + "</NOBR></TD>");
sb.AppendLine("<TD align=\"right\"><NOBR>" + oRS.Fields("Cedant") + "</NOBR></TD>");
sb.AppendLine("<TD align=\"right\"><NOBR>" + sUWCode + "</NOBR></TD>");
sb.AppendLine("<TD align=\"center\"><NOBR>" + Format(dRequired, "mm/dd/yy") + "</NOBR></TD>");
sb.AppendLine("<TD align=\"left"" width=\"200\">" + oRS("Comments") + "</TD>");
sb.AppendLine("<TD align=\"right\"><NOBR>" + sAssignedBy + "</NOBR></TD>");
sb.AppendLine("</TR>");

sb.AppendLine("</TABLE>");
sb.AppendLine("<BR><BR>");