Just got VB.net and im stuck (lots o' code) ... HELP

Audax321

Well-known member
Joined
May 4, 2002
Messages
90
Okay, I understand VB.net coding pretty well. But, I am stuck... I decided to make a search program for my first .NET program. There are two things I am stuck doing...

1. Trying to open a Browse for Folder window:

Code:
Module BrowseFolder
    Open Folder
    Private Const BIF_RETURNONLYFSDIRS = 1
    Private Const BIF_DONTGOBELOWDOMAIN = 2
    Private Const MAX_PATH = 260

    Private Structure BrowseInfo
        Dim hwndOwner As IntPtr
        Dim pIDLRoot As Long
        Dim pszDisplayName As Long
        Dim lpszTitle As Long
        Dim ulFlags As Long
        Dim lpfnCallback As Long
        Dim lParam As Long
        Dim iImage As Long
    End Structure

    Private Declare Function SHBrowseForFolder Lib "shell32" (ByVal lpbi As BrowseInfo) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long

    Public Function OpenDirectoryTV(ByVal odtvOwner As Form, ByVal odtvTitle As String) As String
        Dim lpIDList As Long
        Dim sBuffer As String
        Dim szTitle As String
        Dim tBrowseInfo As BrowseInfo

        szTitle = odtvTitle

        With tBrowseInfo
            .hwndOwner = odtvOwner.Handle
            .lpszTitle = lstrcat(szTitle, "")
            .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
        End With

        lpIDList = SHBrowseForFolder(tBrowseInfo)

        If (lpIDList) Then
            sBuffer = Space(MAX_PATH)
            SHGetPathFromIDList(lpIDList, sBuffer)
            sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
            OpenDirectoryTV = sBuffer
        End If
    End Function
End Module

The program gets stuck at "lpIDList = SHBrowseForFolder(tBrowseInfo)" but I have absolutely no clue why...

2. VB6 had the file list box that you could use to loads files from a directory into. Is there a similiar control or method to do this in Vb.net. Keeping in mind that the program I am trying to make has to filter files according to their extension.... like search just .mp3 file or search just .mp3 and .mpg files, etc...

Thanks.. :)
 
1. There is a class in .net that does this for you, FolderNameEditor or something

2. No. Use a fileopendialog, or populate a listbox by using System.IO.Directory.GetFiles() and adding them yourself.
 
Back
Top