<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
  <channel>
    <title>Office Add.in | Code</title>
    <description>Code and tools for Excel, Project and sometimes Word.</description>
    <link>http://officeadd.in/code.aspx</link>
    <docs>http://backend.userland.com/rss</docs>
    <item>
      <title>Prettify JS - Syntax Highlighting</title>
      <description>This is a test of syntax highlighting using the excellent &lt;a href="http://code.google.com/p/google-code-prettify/"&gt;Prettify JS&lt;/a&gt; library. &lt;br /&gt;&lt;h3&gt;VBA Example&lt;/h3&gt;

&lt;pre class="prettyprint lang-vb"&gt;Public Function InCollection(col As Collection, key As String) As Boolean&lt;br /&gt;  Dim var As Variant&lt;br /&gt;  Dim errNumber As Long&lt;br /&gt;&lt;br /&gt;  InCollection = False&lt;br /&gt;  Set var = Nothing&lt;br /&gt;&lt;br /&gt;  Err.Clear&lt;br /&gt;  On Error Resume Next&lt;br /&gt;    var = col.Item(key)&lt;br /&gt;    errNumber = CLng(Err.Number)&lt;br /&gt;  On Error GoTo 0&lt;br /&gt;&lt;br /&gt;  '5 is not in, 0 and 438 represent incollection&lt;br /&gt;  If errNumber = 5 Then ' it is 5 if not in collection&lt;br /&gt;    InCollection = False&lt;br /&gt;  Else&lt;br /&gt;    InCollection = True&lt;br /&gt;  End If&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;/pre&gt;

&lt;h3&gt;Prettify and VB comments&lt;br /&gt;&lt;/h3&gt;

If you need Prettify to work with VB, VBA and VB.net you'll need to make sure you include the&lt;strong&gt; lang-vb.js&lt;/strong&gt; file along with&lt;strong&gt; prettify.js&lt;/strong&gt;. You will have problems with VB comments if you don't load lang-vb (see &lt;a href="http://code.google.com/p/google-code-prettify/issues/detail?id=68"&gt; Prettify Issues&lt;/a&gt; for more detail).


&lt;pre class="prettyprint lang-html"&gt;&amp;lt;script type="text/javascript" src="/External/css/prettify/prettify.js" &amp;gt; &amp;lt;/script &amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript" src="/External/css/prettify/lang-vb.js" &amp;gt; &amp;lt;/script &amp;gt;&lt;br /&gt;&lt;/pre&gt;

Then add PRE block around your code eg:&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&amp;lt;PRE class="prettyprint lang-vb"&amp;gt;&lt;br /&gt; Function SomeVB() as string&lt;br /&gt;   ' do stuff&lt;br /&gt; End Function&lt;br /&gt;&amp;lt;/PRE&amp;gt;&lt;/pre&gt;

&lt;br /&gt;If you are experiencing problems with prettify and VB comments it's probably because you haven't loaded &lt;strong&gt;lang-vb.js &lt;/strong&gt;in addition to &lt;strong&gt;prettify.js&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;

&lt;h3&gt;No language specified and "nocode" example&lt;/h3&gt;
&lt;pre class="prettyprint"&gt;public partial class UserControls_EMailForm : System.Web.UI.UserControl&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    private string _toemail;&lt;br /&gt;&lt;br /&gt;    public string ToEMail&lt;br /&gt;    {&lt;br /&gt;        get { return _toemail; }&lt;br /&gt;        set { _toemail = value; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private string _smtpserver;&lt;br /&gt;&lt;br /&gt;    public string SmtpServer&lt;br /&gt;    {&lt;br /&gt;        get { return _smtpserver; }&lt;br /&gt;        set { _smtpserver = value; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;	&lt;br /&gt;&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        string subject = Request.QueryString["s"];&lt;br /&gt;        success.Visible = false;&lt;br /&gt;        if(!string.IsNullOrEmpty(subject)){&lt;br /&gt;          SubjectTextBox.Text = subject;&lt;br /&gt;          SubjectTextBox.Enabled = false;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="nocode"&gt;... more code would go here.... &lt;/span&gt;
}

&lt;/pre&gt;</description>
      <link>http://officeadd.in/code/prettify_js_-_syntax_highlighting.aspx</link>
      <comments>http://officeadd.in/code/prettify_js_-_syntax_highlighting.aspx</comments>
      <guid isPermaLink="false">9993c01a-cb0e-4379-8702-98e8276291ec</guid>
      <pubDate>Tue, 05 May 2009 00:00:00 GMT</pubDate>
    </item>
  </channel>
</rss>