Visual Basic Code of the Week (COTW)
Issue #34
All content and source code is Copyright (c) 1998 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.

This issue is brought to you by Videosoft's VS-OCX Version 6.0. The latest and greatest control from Videosoft. It can be yours for only $149. The upgrade version is only $99. If you are interested, email for complete ordering details. There is a light version of the Elastic control available for only $49.

Here are the details about the control:

No more resizing code! Just add a single vsElastic control to your existing form, set a couple of properties and voila; your form becomes resolution independent, EGA, VGA, SVGA ---it doesn't matter. The vsElastic control automatically resizes all of the controls on your form.

No more switching between forms! Let the vsIndexTab control present several screens worth of data in the space of one by using notebook-style tabs like those in Word or Excel. Resize the form and watch the contents of each tab automatically resize.

No more slow code to parse strings and read files! Let the vsAwk string parser control slice and dice your strings automatically. It even includes an expression evaluator that supports variables.

No more tedious work! Let these three controls do the work for you.

Requirements for this Issue

The source code in this issue is designed for Visual Basic 4.0 and above.

In this Issue

This issue will discuss a useful string padding routine. It has several parameters which make it very flexible. It is geared more towards the beginner level of Visual Basic programming.

If anyone has any string handling routines that they use all the time, please forward them to us and we will reward you with 4 free issues of Code of the Week. We will also publish them in our ezine to share with all of our subscribers. You can email us at

String Handling Module


This module introduces a string handling function to pad a string.

COTWPad Subroutine

Adds blanks to the right side of string if necessary. The routine will handle null strings appropriately. This routine can be useful when you are trying to output a text file that has evenly spaced columns or you are creating multi-column output for the screen or print using a fixed-pitch font. Basically it is most useful for doing simple reporting. Most recently we have used it to generate a email message that had columns of data.


COTWPad(sData as Variant, iLen as Integer, sChar as String) as String