Visual Basic Syntax Highlighting

I noticed that the Syntax Highlighting doesn’t work for Visual Basic and is often washed out looking as shown in the code block below. Wonder if this could be fixed with Codeblock Theme Picker - Theme component - Discourse Meta

Option Explicit
Sub main()
 
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
 
End sub

Should get something like this.

Option Explicit
Sub main()
 
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swModelDocExt As SldWorks.ModelDocExtension

End Sub
Option Explicit
Sub main()
 
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
 
End sub

VBA was missing from the list of languages.

2 Likes

Its still not showing correctly for me.

What about for other languages?

int main() {
    printf("Hello World!");
  }

C# is showing same color for class types and variable name. To my eyes it looks like modifier keywords (static) are same color as function parameters (args). These aren’t show stoppers. Having code in it’s own section with different back ground and most importantly using fixed width font are the big items for me.

Is there a way to tell it what the language is, like notepad++, or is it automatic?

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Diagnostics;

using EPDM.Interop.epdm;

namespace PDM_fileLastActiveDateUpdater
//namespace PDM_fileMaint
{
  /*Comments
   * 
   */

  public class LastActiveUpdater
  {
    private static IEdmVault20 vault;
    private static StreamWriter logStream;
    private static DateTime newlastActiveDateDT;
    public const string LAST_ACT_VAR_NAME = "LastActiveDate";
    private const string DATE_TIME_FORMAT = @"yyyy-MM-dd HH:mm:ss";
    public const string DATE_FORMAT = @"yyyy-MM-dd";

    static int Main(string[] args)
    { 
      //do stuff
    }
  }
}

Batch script (Kill PDM process) Looks like BATCH/CMD is not fully supported.

cd "%LOCALAPPDATA%\SOLIDWORKS\SOLIDWORKS PDM\Plugins\Product Data"
taskkill /f /IM explorer.exe
taskkill /f /IM EDMSERVER.exe
taskkill /f /IM EDMSER~1.exe
taskkill /f /IM Search.exe
taskkill /f /IM AddInSrv.exe
taskkill /f /IM ViewServer.exe

rd "%LOCALAPPDATA%\SOLIDWORKS\SOLIDWORKS PDM\Plugins\Product Data" /s /q

start explorer.exe
exit

The project that provides the highlighting (HighlightJS) doesn’t have a BAT/CMD syntax. It can be done, but it might be a while.

1 Like

Is it customizable by you or do you have to rely on a community plugin to support? If its anything like cerating a custom langauge on Notepad++, its a challenge to create.

My brief research shows that we would need a custom theme component, but a lot of the heavy lifting already exists for other languages and it may just be a matter of incorporating a proper syntax description file/library/database into it.

3 Likes

My opinion is what we have is usable but improvable. Put it on the list if you want, but hopefully we have years to improve the new site.

1 Like

I assume this forum is for sharing code, and the users are doing the editing elsewhere. I realize this makes it easier to read, but like bnemec says, I wouldn’t put it high on the priority list.

1 Like

It does automatically select the language, but you could also override it by adding the language behind the ``` java|c|csharp|python|vbnet|vbscript and more, as shown in the image below. highlight.js supportes 192 languages.

The “VBA” code block in the image below is automatically marked as csharp.


Currently this auto language detection does not know what to do with the VBA language and I noticed that it jumps allot between different languages.

@JimSculley What languages have you configured for highlighting?
I can find this list in the source code. Is this the same list? If so, and I am not sure, but I belive vba should be either vbscript or vbnet. Could you try this?

bash|c|cpp|csharp|css|diff|go|graphql|ini|java|javascript|json|kotlin|lua|makefile|markdown|objectivec|perl|php|php-template|plaintext|python|python-repl|r|ruby|rust|scss|shell|sql|swift|typescript|xml|yaml|wasm|vba|bat

1 Like

I added vbnet:

Here it is without specifying a language:

Imports System

Public Module Hello
   Public Sub Main(  )
      Console.WriteLine("hello, world")
   End Sub
End Module

and with specifying the language:

Imports System

Public Module Hello
   Public Sub Main(  )
      Console.WriteLine("hello, world")
   End Sub
End Module

So, it is auto-detected.

VBA isn’t listed at highlight.js so specifying it in your markdown just disables the highlighting:

Dim swApp As Sldworks.Sldworks
Dim mDoc As ModelDoc2
Set mDoc = swApp.ActiveDoc As ModelDoc2

If you let it auto-detect, you get this:

Dim swApp As Sldworks.Sldworks
Dim mDoc As ModelDoc2
Set mDoc = swApp.ActiveDoc As ModelDoc2

which is auto-detected as vbnet

1 Like

For me this shows up as java.

EDIT: after refreshing the page it shows up as vbnet aswel! awesome stuff Jim!

1 Like

The closet you will get to VBA is VB.NET highlighting.

I’ve created a new theme component for highlighting VBA, so syntax highlighting for it should now work correctly. For example, VBA has a ‘DefBool’ keyword which VB.NET does not and VB.NET has ‘Of’, which VBA does not. Both are handled correctly by the auto language detect:

A VBA sample:

    Sub Main()
        DefBool abc
        DefBool xyz
    End Sub


A VB.NET sample:

IPublic Class classHolder(Of t)
    Public Sub processNewItem(ByVal newItem As t)
        Dim tempItem As t
        Dim DefBool as String
    End Sub
End Class
1 Like

Imagine 3DXperience being that efficient.

1 Like