I was trying this TreeView demo and ran into a situation where a Try Catch block will not pass execution onto the Catch code. The error is "Drive not ready" when attempting to access a:\. That is easy enough to understand...I have no floppy on my system. But why does the error handler not pass the error to the Catch area?
Many thanks for any advice!
Here is the demo:
A form just has a TreeView and a button on it. The demo populates a TreeView with the directories of my file system:
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get a list of drives
Dim drives As System.Collections.ObjectModel.ReadOnlyCollection(Of IO.DriveInfo) = My.Computer.FileSystem.Drives
Dim rootDir AsString = String.Empty
'Now loop thru each drive and populate the treeview:
For i AsInteger = 0To drives.Count - 1
rootDir = drives(i).Name
'Add this drive as a root node:
'Populate this root node:
NextEndSubPrivateSub PopulateTreeView(ByVal dir AsString, ByVal parentNode As TreeNode)
Dim folder AsString = String.Empty
TryDim folders() AsString = IO.Directory.GetDirectories(dir)
If folders.Length <> 0ThenDim childNode As TreeNode = NothingForEach folder In folders
childNode = New TreeNode(folder)
NextEndIfCatch ex As UnauthorizedAccessException
parentNode.Nodes.Add(folder & ": Access Denied")
I am very new to programming... I have opened a vb2003 application in visual studio 2010 and have had some thread safe problems when trying to modify a text box from a non-parent form. I implemented the below that I found on a thread with good results:
PrivateSub SetLabelText(ByVal s AsString)
IfMe.lbTime.InvokeRequired ThenMe.lbTime.Invoke(New Action(OfString)(AddressOf SetLabelText), s)
'Me.lbTime.Invoke(New Action(Of String)(AddressOf SetLabelText), s)
ElseMe.lbTime.Text = s
Now when I try to modify the attached for an array of textboxes, while passing the array index into the sub routine I get a "Does not have a signature compatible with the delegate." error. Is it possible to have a delegate with multuple parameters? Is there an easier way to accomplish a threadsafe multiple textbox modifications?
PrivateSub SettxtChannelData(ByVal arrIndex AsInteger, ByVal s AsString)
IfMe.txtChannelData(arrIndex).InvokeRequired ThenMe.txtChannelData(arrIndex).Invoke(New Action(OfString)(AddressOf SettxtChannelData), s)
ElseMe.txtChannelData(arrIndex).Text = s
I have trouble passing arguments to the Process.Start in VB.NET.
What I want to accomplish is to backup a mysql database with its mysqldump.exe which is located in my C drive. I have a code that can do it perfectly when run in the command prompt. The problem if face comes when I want to pass that same code to the process.start.
And it still bring me the error "The system cannot find the file specified" Error message.
Can you please tell me what the problem is and how I can get through it? Please remember that, if I take the contents of txtProgram.text and txtArguments.text and put them to a command prompt, it works fine.
*I have also searched other threads here, no one had an exact similar issue like mine.