Results 1 to 4 of 4

Thread: [RESOLVED] Unknown VB bug... just for 2 lines of code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    146

    Resolved [RESOLVED] Unknown VB bug... just for 2 lines of code

    Code:
    msgbox getDesktopPath
    msgbox getDesktopPath & "\file1.dat"
    This looks funny
    Attached Images Attached Images  
    Last edited by winterslam; May 6th, 2007 at 10:23 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Unknown VB bug... just for 2 lines of code

    I presume that the function getDesktopPath returns a string ending with a Chr(0) character (as many API calls do), which marks the end of a string for most controls etc - in which case it is not a bug at all, just 'bad' code.

    If you show us the code for getDesktopPath, we can help you correct it.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    146

    Re: Unknown VB bug... just for 2 lines of code

    Code:
    Public Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal csidl As Long, ByVal fCreate As Long) As Long
    
    
    Public Function getDesktopPath() As String
        Dim sPath As String
        sPath = Space$(255)
        SHGetSpecialFolderPath hwnd, sPath, 0, 0
        getDesktopPath = sPath
    End Function

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Unknown VB bug... just for 2 lines of code

    As SI said, the API returns a null terminated string, so you need to get rid of the null character:

    Code:
    getDesktopPath = Trim$(Replace(sPath, Chr(0), ""))
    The reason I added the trim is because the string will be 255 characters long after we remove the null.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width