Microsoft KB Archive/75613

= In CodeView, Strings Not Watchable Beyond Null (0) Character =

Article ID: 75613

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft CodeView 4.1
 * Microsoft CodeView 3.0
 * Microsoft CodeView 3.0
 * Microsoft CodeView 4.1
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1
 * Microsoft BASIC Professional Development System 7.1
 * Microsoft QuickBasic 4.0, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBASIC 4.0b, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBasic 4.5 for MS-DOS, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition

-



This article was previously published under Q75613



SUMMARY
This article documents a limitation of Microsoft CodeView's Watch feature when viewing Basic string expressions. A fixed-length or variable-length string containing a null character is only watchable up to the null character under CodeView. Any text beyond the null character is not watchable. This is not a problem with CodeView, but rather a design limitation.

This information applies to Microsoft CodeView versions 2.2 and 3.1 for MS-DOS and MS OS/2; Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS and version 7.1 for MS OS/2; and Microsoft QuickBasic versions 4.0, 4.0b, 4.5 for MS-DOS. (Note: CodeView is not shipped with QuickBasic 4.x products).



MORE INFORMATION
A null character is a byte with an ASCII value of 0, such as returned by the Basic function CHR$(0). (Note that null bytes serve as the standard string terminator in the Microsoft C language.)

CodeView interprets a null character as a null terminator for a string. Any attempt to display a string expression containing null characters in the Watch window of CodeView will result in a display of the string truncated at the null character. For example, if a null character is the first character of a string, an empty string (&quot;&quot;) will be displayed in the Watch window for the string.

Example 1
An example of this behavior can be demonstrated in the following one line code example: message$ = &quot;Hi&quot; + CHR$(0) + &quot;there&quot; If a watchpoint is set for message$ from within CodeView, the text displayed in the Watch window for message$ will be &quot;Hi&quot;. However, if the variable message$ is printed as output, the displayed output will be Hi there.

Example 2
In the following example for fixed-length strings, CodeView will not display any text:
 * 1) A fixed-length string is DIMensioned, but not initialized or assigned to a value.
 * 2) The MID$ statement is used to place a string fragment at any point after the first character position of the fixed-length string.
 * 3) A watchpoint is set for the string under CodeView.

When you first dimension a fixed-length string, it contains null characters, not spaces. When you use the MID$ statement to place a string fragment within the fixed-length string at any point after the first character position, a null byte (which CodeView treats as a string terminator) is left as the first character. If you set a Watchpoint for the string under CodeView, an empty string will be displayed in the Watch window. However, the embedded string fragment will still be part of the string and can be printed to the screen as output.

The following is a code example that demonstrates the behavior described above: DIM temp AS STRING * 20 MID$(temp,5,3) = &quot;abc&quot; PRINT temp This code puts &quot;abc&quot; starting at the fifth character position of the variable temp. However, if you view the contents of temp within a Watch window of CodeView, an empty string (&quot;&quot;) will be displayed for the string. The PRINT statement above will correctly print the contents of temp to the screen. The PRINT statement causes a space to be printed for each null character.

One workaround for this behavior is to assign an empty string (&quot;&quot;) to the fixed-length string variable. The assignment should be made after the DIM statement and before the MID$ statement. When a fixed-length string is assigned to an empty string, all null characters are replaced by spaces (ASCII 32). If a Watchpoint is set on temp in the following code example, the full contents of the string will be displayed in the Watch window. DIM temp AS STRING * 20 temp = &quot;&quot; MID$(temp,5,3) = &quot;abc&quot;  ' The whole string is watchable. PRINT temp

Additional query words: QuickBas BasicCom 2.20 3.10 3.14 4.00 4.00b 4.50 7.00 7.10

Keywords: KB75613

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.