PRB: Problems Editing Long Declares in the Conditional Compile (143403)



The information in this article applies to:

  • Microsoft Visual Basic Control Creation Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
  • Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
  • Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0

This article was previously published under Q143403

SYMPTOMS

When you have long declare statements in conditional code, if you copy the declare from one condition to the other, then modify the identifier in the Alias clause, additional changes occur in your declaration which you did not specify.

CAUSE

This behavior is by design. The Alias clause disappears and the type elements wrap differently; however, the code runs as desired.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. Place the following code in the declaration section of Form1.
           #If Win32 Then
              Private Declare Function ShellExecute Lib _
                 "shell32.dll" Alias "ShellExecuteA" _
                   (ByVal hwnd As Long, _
                    ByVal lpOperation As String, _
                    ByVal lpFile As String, _
                    ByVal lpParameters As String, _
                    ByVal lpDirectory As String, _
                    ByVal nShowCmd As Long) As Long
           #Else
           #End If
    						
  3. Copy the Declare statement in the "If Win32" clause and paste it in the #Else clause.
  4. Insert the cursor following the "A" in "ShellExecuteA" and backspace over the "A".
  5. Commit the line by stepping off the declare statement.
  6. The line continuation for the #ELSE clause gets scrambled as is shown below. The Alias clause is gone and the type elements are not wrapped as you would expect; however, the code runs as desired.
           #If Win32 Then
             Private Declare Function ShellExecute Lib _
                 "shell32.dll" Alias "ShellExecuteA" _
                   (ByVal hwnd As Long, _
                    ByVal lpOperation As String, _
                    ByVal lpFile As String, _
                    ByVal lpParameters As String, _
                    ByVal lpDirectory As String, _
                    ByVal nShowCmd As Long) As Long
           #Else
             Private Declare Function ShellExecute Lib _
                 "shell32.dll" (ByVal _
                   hwnd As Long, ByVal lpOperation _
                    As String, ByVal lpFile _
                    As String, ByVal lpParameters _
                    As String, ByVal lpDirectory _
                    As String, ByVal nShowCmd _
                    As Long) As Long
           #End If
    						
If you press CTRL+Z to undo the erasing of the "A", the following will appear. The actual edit is undone, but your incorrect line continuations are still there. This code will not run because part of the declaration is missing.
      Private Declare Function ShellExecute Lib _
          "shell32.dll" Alias "ShellExecuteA" _
            hwnd As Long, ByVal lpOperation _
             As String, ByVal lpFile _
             As String, ByVal lpParameters _
             As String, ByVal lpDirectory _
             As String, ByVal nShowCmd _
             As Long) As Long
				

Modification Type:MajorLast Reviewed:5/7/2003
Keywords:kbprb KB143403