Microsoft KB Archive/183906

= BUG: Drag From FileListBox Includes Extra Backslash =

Article ID: 183906

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q183906



SYMPTOMS
If a file is dragged from the FileListBox control, and that file is located in the root directory, Visual Basic includes an extra backslash (\) in the file path. This may cause one of the following errors on Windows 95, Windows 98, or Windows Me:

Cannot copy file. File System Error (1026)

-or-

Cannot copy. Cannot find the specified file. Make sure you specify the correct path and filename.

While no error occurs under Windows NT or Windows 2000, the erroneous backslash is still present.



RESOLUTION
As a workaround, add the following code to your form. The code will intercept the Drag operation and remove the extra backslash character. This code assumes that the name of the FileListBox is File1: Private Sub File1_OLEStartDrag(Data As DataObject, _                                        AllowedEffects As Long) Dim FileNames As New Collection Dim vFn As Variant

'Retrieve current set of files from the file control For Each vFn In Data.Files FileNames.Add vFn Next vFn

'Clear the list in the data object, and add the corrected files back Data.Files.Clear For Each vFn In FileNames Data.Files.Add RemoveExtraBackslash(vFn) Next vFn End Sub

Private Function RemoveExtraBackslash(ByVal str$) As String While True Dim i%        i = InStr(str, "\\") If i > 0 Then str = Left$(str, i - 1) & Mid$(str, i + 1) Else RemoveExtraBackslash = str Exit Function End If     Wend End Function



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default. Add a FileListBox and a DirListBox to Form1.  Add the following code to Form1: Private Sub Dir1_Change File1.Path = Dir1.Path End Sub  Change OLEDragMode property of the FileListBox to 1-Automatic. Start the program and change the path of the DirListBox to C:\. Start Windows Explorer.</li> If you are running Windows 95, Windows 98, or Windows Me, drag one of the files from the FileListBox to any directory in Windows Explorer. You should see an error dialog as described earlier.</li> Drag one of the files from the FileListBox to the Start...Run dialog window. You should see the incorrect path with the extra backslash.</li> Copy the workaround code from the RESOLUTION section into your project and run it again. Drag one of the files from the FileListBox to the Start...Run dialog window. You should see the correct path displayed.</li></ol>

Additional query words: back slash listbox file list box

Keywords: kbbug kbctrl kbpending kbcontrol KB183906

-

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

© Microsoft Corporation. All rights reserved.