Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1469

[VB6] Faster RTB Code Formatting

$
0
0
The scenario here is a program that allows user scripting in VBScript. This program needs a script IDE to make it easier for users to write, test, and modify their scripts. Instead of a simple text editor, we want to format entered VBScript code in a manner similar to the way VB6.EXE does it. This means more than simple "colorization" but also includes correction of whitespace and punctuation as well as re-formatting statements as they are manually altered.

Performance is a factor because in the real code far more is going on and it occurs during user editing as well as upon loading.


Demo

Stripped down implementation for illustration. Only about 5% of the real thing is included here.

Does not take into account predefined constants, comments, line continuations, or string literals. Does not attempt to correct whitespace and punctuation usage. Also does not include the logic to handle statement by statement user edits.

Merely does some one-pass simplified colorizing of the entire script after loading. Just enough to look interesting.

This is done using four different methods in four different Forms varying only as needed to add optimizations in steps:

  1. RTB.Visible = True (default).
  2. Let RTB.Visble = False at start of formatting, then True again when done. Flawed, see MS KB 189483.
  3. Let RTB.Visible = False at start and make ShowWindow calls per KB article.
  4. Use TOM with Freeze and ITextRange objects.


The four Forms are MDI child Forms within a parent Form. They are run in sequence and timings are displayed for each child Form upon completion. They all use the same large sample script (testcase.txt).


Name:  sshot-sm.png
Views: 88
Size:  16.4 KB


Name:  sshot-timings.png
Views: 62
Size:  2.0 KB


Requirements

To use TOM with the VB6 RichTextBox, Windows 2000 or later is required. This causes RichTextBox to use Riched20.dll in Microsoft Rich Edit 1.0 emulation mode, thus giving us the TOM interfaces to use. TOM is not supported by Riched32.dll.


Links

BUG: Cannot Set RichTextBox Visible Property to False

Text Object Model
Attached Images
  
Attached Files

Viewing all articles
Browse latest Browse all 1469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>