Stefan Sterk

Wouldn't VBA Syntax Highlighting be great?

Discussion created by Stefan Sterk on Nov 4, 2020
Latest reply on Nov 4, 2020 by Eddy Alleman

I always find it hard to read when code isn't highlighted. Now there isn't a option to marking syntax as VBA in Jive. But wouldn't it be great if you could?

 

An alternative option would be to go to Syntax Highlighter  paste your code in the source code section, select VB.net as Language and tick Line numbers and Use <font> tag (i.e. for Habrahabr). Now copy the HTML code and paste it as sourcecode by clicking on the <> on the toolbar. As is show in de image below. 

 

 

So for example i copied some code from 2020 SOLIDWORKS API Help - Save Drawing as DXF Example (VBA). And did the steps as given above to get the highlighted code as shown below. What are your thought about this?

 

  1. '----------------------------------------------------------------------------
  2. ' Preconditions:
  3. ' 1. Open a drawing.
  4. ' 2. Open the Immediate window.
  5. '
  6. ' Postconditions:
  7. ' 1. Gets and sets DXF-related system settings.
  8. ' 2. Saves the drawing as a DXF file in the same folder as the drawing,
  9. '    overwriting any existing file of the same name.
  10. ' 3. Examine the Immediate window and the folder to which the DXF file
  11. '    was saved.
  12. '----------------------------------------------------------------------------
  13. Option Explicit
  14.     Dim swApp                   As SldWorks.SldWorks
  15.     Dim swModel                 As SldWorks.ModelDoc2
  16.     Dim sPathName               As String
  17.     Dim nErrors                 As Long
  18.     Dim nWarnings               As Long
  19.     Dim nRetval                 As Long
  20.     Dim bShowMap                As Boolean
  21.     Dim bRet                    As Boolean
  22.  
  23. Sub main()
  24.  
  25.     Set swApp = Application.SldWorks
  26.     Set swModel = swApp.ActiveDoc
  27.  
  28.     ' Strip off SOLIDWORKS drawing file extension (.slddrw)
  29.     ' and add DXF file extension (.dxf)
  30.     sPathName = swModel.GetPathName
  31.     sPathName = Left(sPathName, Len(sPathName) - 6)
  32.     sPathName = sPathName + "dxf"
  33.  
  34.     ' Show current settings
  35.     Debug.Print "DxfMapping             = " & swApp.GetUserPreferenceToggle(swDxfMapping)
  36.     Debug.Print "DXFDontShowMap         = " & swApp.GetUserPreferenceToggle(swDXFDontShowMap)
  37.     Debug.Print "DxfVersion             = " & swApp.GetUserPreferenceIntegerValue(swDxfVersion)
  38.     Debug.Print "DxfOutputFonts         = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputFonts)
  39.     Debug.Print "DxfMappingFileIndex    = " & swApp.GetUserPreferenceIntegerValue(swDxfMappingFileIndex)
  40.     Debug.Print "DxfOutputLineStyles    = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputLineStyles)
  41.     Debug.Print "DxfOutputNoScale       = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputNoScale)
  42.     Debug.Print "DxfMappingFiles        = " & swApp.GetUserPreferenceStringListValue(swDxfMappingFiles)
  43.     Debug.Print "DxfOutputScaleFactor   = " & swApp.GetUserPreferenceDoubleValue(swDxfOutputScaleFactor)
  44.     Debug.Print ""
  45.  
  46.     ' Turn off showing of map
  47.     bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap)
  48.     Debug.Print "bShowMap = " & bShowMap
  49.  
  50.     swApp.SetUserPreferenceToggle swDXFDontShowMap, False
  51.  
  52.     bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
  53.  
  54.     If bRet = False Then
  55.         nRetval = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)
  56.     End If
  57.  
  58.     ' Restore showing of map
  59.     swApp.SetUserPreferenceToggle swDXFDontShowMap, bShowMap
  60.  
  61. End Sub

Outcomes