473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Conversion obscurities for a newb

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
Expand|Select|Wrap|Line Numbers
  1.     Public Function GetFolder(ByRef hWnd As Integer, Optional ByRef sPrompt As String = "", Optional ByRef sStartFolder As String = "") As String
  2.         '##############################################################################################
  3.         'Displays a Folder Browser to select a Folder
  4.         '##############################################################################################
  5.  
  6.         Dim BI As BROWSEINFO
  7.         Dim pidl As Integer
  8.         Dim sFolder As String
  9.         Dim pos As Short
  10.  
  11.         'Fill the BROWSEINFO structure with the needed data
  12.         With BI
  13.             'hwnd of the window that receives messages from the call. Can be your application or the handle from GetDesktopWindow().
  14.             .hOwner = hWnd
  15.  
  16.             'Pointer to the item identifier list specifying the location of the "root" folder to browse from.
  17.             'If NULL, the desktop folder is used.
  18.             .pidlRoot = 0
  19.  
  20.             'message to be displayed in the Browse dialog
  21.             If Len(sPrompt) = 0 Then
  22.                 .lpszTitle = "Select the folder:"
  23.             Else
  24.                 .lpszTitle = sPrompt
  25.             End If
  26.  
  27.             'the type of folder to return. - the constants perform differently for non networked pc's
  28.             .ulFlags = BIF_RETURNONLYFSDIRS
  29.  
  30.             '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"'
  31.             .lpfn = FARPROC(AddressOf BrowseCallbackProc)
  32.             '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"'
  33.             .lParam = SHSimpleIDListFromPath(StrConv(sStartFolder, vbUnicode))
  34.         End With
  35.  
  36.         'show the browse for folders dialog
  37.         pidl = SHBrowseForFolder(BI)
  38.  
  39.         'the dialog has closed, so parse & display the user's returned folder selection contained in pidl
  40.         sFolder = Space(MAX_PATH)
  41.  
  42.         If SHGetPathFromIDList(pidl, sFolder) Then
  43.             pos = InStr(sFolder, Chr(0))
  44.             GetFolder = Left(sFolder, pos - 1)
  45.         End If
  46.  
  47.         Call CoTaskMemFree(pidl)
  48.     End Function
Thank you

Chris
Oct 15 '09 #1
10 2621
tlhintoq
3,525 Expert 2GB
So in the end you're saying you want to browse files and folder recursively.
Same topic in C# with links to the MSDN tutorial.

TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Oct 15 '09 #2
Thank you for the quick reply.

And sorry, I didn't know about the # - but I do now!! :) I will check out the link.
Oct 15 '09 #3
tlhintoq
3,525 Expert 2GB
@Chris Wills
Yeah, a button with '#' on it doesn't intuitively scream out "Wrap with code tags" - Unless maybe you are working in C#
Oct 15 '09 #4
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"?

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.  
  5.     Public Sub New()
  6.         InitializeComponent()
  7.         PopulateTreeView()
  8.  
  9.     End Sub 'New
  10.  
  11.     Private Sub treeView1_NodeMouseClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
  12.  
  13.         Dim newSelected As TreeNode = e.Node
  14.         ListView1.Items.Clear()
  15.         Dim nodeDirInfo As DirectoryInfo = CType(newSelected.Tag, DirectoryInfo)
  16.         Dim subItems() As ListViewItem.ListViewSubItem
  17.         Dim item As ListViewItem = Nothing
  18.  
  19.         Dim dir As DirectoryInfo
  20.         For Each dir In nodeDirInfo.GetDirectories()
  21.             item = New ListViewItem(dir.Name, 0)
  22.             subItems = New ListViewItem.ListViewSubItem() {New ListViewItem.ListViewSubItem(item, "Directory"), New ListViewItem.ListViewSubItem(item, dir.LastAccessTime.ToShortDateString())}
  23.  
  24.             item.SubItems.AddRange(subItems)
  25.             ListView1.Items.Add(item)
  26.         Next dir
  27.         Dim file As FileInfo
  28.         For Each file In nodeDirInfo.GetFiles()
  29.             item = New ListViewItem(file.Name, 1)
  30.             subItems = New ListViewItem.ListViewSubItem() {New ListViewItem.ListViewSubItem(item, "File"), New ListViewItem.ListViewSubItem(item, file.LastAccessTime.ToShortDateString())}
  31.             item.SubItems.AddRange(subItems)
  32.             ListView1.Items.Add(item)
  33.         Next file
  34.  
  35.         ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
  36.  
  37.     End Sub
  38.  
  39.     Private Sub PopulateTreeView()
  40.         Dim rootNode As TreeNode
  41.         Dim info As New DirectoryInfo("C:\Documents and Settings\")
  42.         'Dim info As New DirectoryInfo("C:\Program Files\")
  43.         If info.Exists Then
  44.             rootNode = New TreeNode(info.Name)
  45.             rootNode.Tag = info
  46.             GetDirectories(info.GetDirectories(), rootNode)
  47.             TreeView1.Nodes.Add(rootNode)
  48.         End If
  49.  
  50.     End Sub
  51.  
  52.     Private Sub GetDirectories(ByVal subDirs() As DirectoryInfo, _
  53.         ByVal nodeToAddTo As TreeNode)
  54.  
  55.         Dim aNode As TreeNode
  56.         Dim subSubDirs() As DirectoryInfo
  57.         Dim subDir As DirectoryInfo
  58.         For Each subDir In subDirs
  59.             aNode = New TreeNode(subDir.Name, 0, 0)
  60.             aNode.Tag = subDir
  61.             aNode.ImageKey = "folder"
  62.             subSubDirs = subDir.GetDirectories()
  63.             If subSubDirs.Length <> 0 Then
  64.                 GetDirectories(subSubDirs, aNode)
  65.             End If
  66.             nodeToAddTo.Nodes.Add(aNode)
  67.         Next subDir
  68.  
  69.     End Sub
  70.  
  71. End Class
Thanks

Chris
Oct 19 '09 #5
tlhintoq
3,525 Expert 2GB
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?
Oct 19 '09 #6
@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.
Oct 19 '09 #7
tlhintoq
3,525 Expert 2GB
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.
Oct 20 '09 #8
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.
Oct 21 '09 #9
tlhintoq
3,525 Expert 2GB
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.
Oct 21 '09 #10
@tlhintoq
Oh OK, never thought of that!! haha

Anyway thanks very much for all your help, thank you.
Oct 22 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
4
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....
0
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.. --...
5
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...
3
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...
3
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...
1
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...
4
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...
2
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...
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.