I am sorry, but I am learning VB-NET (very slowly), and I wanted a function to do a recursive search, so I imported one I found on http://www.planetsourcecode.com/ that I had been told about. But in the conversion, it came up with a couple of errors that I am really out of my depth with. Can anyone help me. THE OFFENDING PORTION OF CODE - Public Function GetFolder(ByRef hWnd As Integer, Optional ByRef sPrompt As String = "", Optional ByRef sStartFolder As String = "") As String
-
'##############################################################################################
-
'Displays a Folder Browser to select a Folder
-
'##############################################################################################
-
-
Dim BI As BROWSEINFO
-
Dim pidl As Integer
-
Dim sFolder As String
-
Dim pos As Short
-
-
'Fill the BROWSEINFO structure with the needed data
-
With BI
-
'hwnd of the window that receives messages from the call. Can be your application or the handle from GetDesktopWindow().
-
.hOwner = hWnd
-
-
'Pointer to the item identifier list specifying the location of the "root" folder to browse from.
-
'If NULL, the desktop folder is used.
-
.pidlRoot = 0
-
-
'message to be displayed in the Browse dialog
-
If Len(sPrompt) = 0 Then
-
.lpszTitle = "Select the folder:"
-
Else
-
.lpszTitle = sPrompt
-
End If
-
-
'the type of folder to return. - the constants perform differently for non networked pc's
-
.ulFlags = BIF_RETURNONLYFSDIRS
-
-
'UPGRADE_WARNING: Add a delegate for AddressOf BrowseCallbackProc Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
-
.lpfn = FARPROC(AddressOf BrowseCallbackProc)
-
'UPGRADE_ISSUE: Constant vbUnicode was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="55B59875-9A95-4B71-9D6A-7C294BF7139D"'
-
.lParam = SHSimpleIDListFromPath(StrConv(sStartFolder, vbUnicode))
-
End With
-
-
'show the browse for folders dialog
-
pidl = SHBrowseForFolder(BI)
-
-
'the dialog has closed, so parse & display the user's returned folder selection contained in pidl
-
sFolder = Space(MAX_PATH)
-
-
If SHGetPathFromIDList(pidl, sFolder) Then
-
pos = InStr(sFolder, Chr(0))
-
GetFolder = Left(sFolder, pos - 1)
-
End If
-
-
Call CoTaskMemFree(pidl)
-
End Function
Thank you
Chris
10 2621
Thank you for the quick reply.
And sorry, I didn't know about the # - but I do now!! :) I will check out the link.
@Chris Wills
Yeah, a button with '#' on it doesn't intuitively scream out "Wrap with code tags" - Unless maybe you are working in C#
I read the article in MSDN and that seems to work quite well, except that it does raise a couple of points.
The first is that it only seems to work for "C:\Documents an Settings\", and not for any other directory that I may set.
And the second is that it doesn't always seem to "Initialise"? - Imports System.IO
-
-
Public Class Form1
-
-
Public Sub New()
-
InitializeComponent()
-
PopulateTreeView()
-
-
End Sub 'New
-
-
Private Sub treeView1_NodeMouseClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
-
-
Dim newSelected As TreeNode = e.Node
-
ListView1.Items.Clear()
-
Dim nodeDirInfo As DirectoryInfo = CType(newSelected.Tag, DirectoryInfo)
-
Dim subItems() As ListViewItem.ListViewSubItem
-
Dim item As ListViewItem = Nothing
-
-
Dim dir As DirectoryInfo
-
For Each dir In nodeDirInfo.GetDirectories()
-
item = New ListViewItem(dir.Name, 0)
-
subItems = New ListViewItem.ListViewSubItem() {New ListViewItem.ListViewSubItem(item, "Directory"), New ListViewItem.ListViewSubItem(item, dir.LastAccessTime.ToShortDateString())}
-
-
item.SubItems.AddRange(subItems)
-
ListView1.Items.Add(item)
-
Next dir
-
Dim file As FileInfo
-
For Each file In nodeDirInfo.GetFiles()
-
item = New ListViewItem(file.Name, 1)
-
subItems = New ListViewItem.ListViewSubItem() {New ListViewItem.ListViewSubItem(item, "File"), New ListViewItem.ListViewSubItem(item, file.LastAccessTime.ToShortDateString())}
-
item.SubItems.AddRange(subItems)
-
ListView1.Items.Add(item)
-
Next file
-
-
ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
-
-
End Sub
-
-
Private Sub PopulateTreeView()
-
Dim rootNode As TreeNode
-
Dim info As New DirectoryInfo("C:\Documents and Settings\")
-
'Dim info As New DirectoryInfo("C:\Program Files\")
-
If info.Exists Then
-
rootNode = New TreeNode(info.Name)
-
rootNode.Tag = info
-
GetDirectories(info.GetDirectories(), rootNode)
-
TreeView1.Nodes.Add(rootNode)
-
End If
-
-
End Sub
-
-
Private Sub GetDirectories(ByVal subDirs() As DirectoryInfo, _
-
ByVal nodeToAddTo As TreeNode)
-
-
Dim aNode As TreeNode
-
Dim subSubDirs() As DirectoryInfo
-
Dim subDir As DirectoryInfo
-
For Each subDir In subDirs
-
aNode = New TreeNode(subDir.Name, 0, 0)
-
aNode.Tag = subDir
-
aNode.ImageKey = "folder"
-
subSubDirs = subDir.GetDirectories()
-
If subSubDirs.Length <> 0 Then
-
GetDirectories(subSubDirs, aNode)
-
End If
-
nodeToAddTo.Nodes.Add(aNode)
-
Next subDir
-
-
End Sub
-
-
End Class
Thanks
Chris
I read the article in MSDN and that seems to work quite well, except that it does raise a couple of points.
The first is that it only seems to work for "C:\Documents an Settings\", and not for any other directory that I may set.
And the second is that it doesn't always seem to "Initialise"?
A) other directories. That seems very unlikely. I use this kind of thing all the time. Is it possible you are setting paths to directories that you don't have permissions to, or have typos in the paths just like you did above? You should try a test with a simple path that you make first. "C:\test\" for example
B) You don't have an "Initialise" method in your code. So what is is you are saying doesn't happen consistently. Have you tried putting a breakpoint in the method you feel isn't always working and stepping through it line by line to see under what conditions it does something you don't expect?
@tlhintoq
The code may have gotten missed as I had to save the text in Notepad, as I have been trying to post back here since Friday, and it always "bombed on submission. IE had somehow set to debug scripts and that caused it.
To A).- This code seems to work normally so long as it is working with line 41 "C:\Documents and Settings" in the above code. But if I "comment out" line 41 and substitute line 42, then nothing happens. (I am running as Administrator on this machine on XP, not Vista). Any other Drive or directory it just seems to sit there?
To B).- I wanted this initialisation to happen during loading of the form and I think I'd read, probably wrongly that that was what line 6 should do.
PS: Sorry to be such a "plank", perhaps the old DOS days of Basic spoilt me. Now retired, I am purely attempting VB as an interest, which I hope to use in my hobby.
Comment out line 41.
Restore line 42
Put a breakpoint on line 40
When the code stops on line 40 use the f-10 key to walk through the code one line at a time.
After it has moved to line 43 you can hover your mouse over any occurence of the variable "info" and the pop-up tooltips will show you its values.
This way you can see if you are getting any values for this.
I can at last see an end to this, as yesterday I deliberately re-built the form and code, and found that the reason for my thinking that it was broken for anything but "Documents and Settings" was the fact that not only was the treeview disappearing somtimes, but also, to read "Program Files" for example, it took a very measurable amount of time (about 1 min) before it decided to display.
So I guess I'll have to find something a bit quicker.
That is the issue with pre-loading the entire directory structure and all the subdirectories at once.
Since you are doing this in a treeview might I suggest that you only populate one level of hierarchy at a time?
You can get all of the folders at "C:\Programs" and put those into your treeview quickly.
Then when the user opens a node, load just the next level of just that folder. It will also go quickly.
That way you don't waste time loading 500 folders of data the user isn't going to go to anyway.
@tlhintoq
Oh OK, never thought of that!! haha
Anyway thanks very much for all your help, thank you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: claudel |
last post by:
Hi
I have a newb PHP/Javascript question regarding checkbox processing
I'm not sure which area it falls into so I crossposted to comp.lang.php
and comp.lang.javascript.
I'm trying to...
|
by: Hari |
last post by:
Basically I would like to downlod the visual basic 6.0 compiler, but i
already have the vb.net compiler. I had to pay for the VB.net IDE, just
wondering if I can get the vb 6.0 IDE for free or not....
|
by: David E. |
last post by:
So as a programmer, what's the best thing to study? EJB? How much of the
J2EE or Enterprise architecture is necessary to no? I guess I need a good
overview for a newb like me... thanks..
--...
|
by: Alexandre |
last post by:
Hi,
Im a newb to dev and python... my first sefl assigned mission was to read a
pickled file containing a list with DB like data and convert this to
MySQL... So i wrote my first module which...
|
by: Walter |
last post by:
But I'm stumped.....
I've got a windows 2000 server and I am trying to set up PHPBB on it using a
mysql database.. I am very inexperienced on this.....
Ive installed mysql V4.0.20d and I can...
|
by: claudel |
last post by:
Hi
I have a newb PHP/Javascript question regarding checkbox processing
I'm not sure which area it falls into so I crossposted to comp.lang.php
and comp.lang.javascript.
I'm trying to...
|
by: notbob |
last post by:
Newb here! Using 4.0.20 on Slack. Slogging through the official
manual. At 2.4.3 Securing the Initial MySQL Accounts, I'm finally
stopped cold while trying to follow instructions. Here's what I...
|
by: Donald Newcomb |
last post by:
I'm a real Python NEWB and am intrigued by some of Python's features, so I'm
starting to write code to do some things to see how it works. So far I
really like the lists and dictionaries since I...
|
by: A_StClaire_ |
last post by:
hey there,
I was able to read a char string containing only digits and convert it
to its int equivalent. however now I need to do the same thing with a
char string containing a hexadecimal...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |