|
Hi all.
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:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim drives As System.Collections.ObjectModel.ReadOnlyCollection(Of IO.DriveInfo) = My.Computer.FileSystem.Drives
Dim rootDir As String = String.Empty
For i As Integer = 0 To drives.Count - 1
rootDir = drives(i).Name
TreeView1.Nodes.Add(rootDir)
PopulateTreeView(rootDir, TreeView1.Nodes(i))
Next
End Sub
Private Sub PopulateTreeView(ByVal dir As String, ByVal parentNode As TreeNode)
Dim folder As String = String.Empty
Try
Dim folders() As String = IO.Directory.GetDirectories(dir)
If folders.Length <> 0 Then
Dim childNode As TreeNode = Nothing
For Each folder In folders
childNode = New TreeNode(folder)
parentNode.Nodes.Add(childNode)
PopulateTreeView(folder, childNode)
Next
End If
Catch ex As UnauthorizedAccessException
parentNode.Nodes.Add(folder & ": Access Denied")
End Try
End Sub
End Class
modified 3-May-13 3:17am.
|
|
|
|
|
You are only catching UnauthorizedAccessException , which is not the same as Drive not ready.
Use the best guess
|
|
|
|
|
Ahhhhh, OK. Was right in front of me the whole time. Thanks for the brain reset.
|
|
|
|
|
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:
Private Sub SetLabelText(ByVal s As String)
If Me.lbTime.InvokeRequired Then
Me.lbTime.Invoke(New Action(Of String)(AddressOf SetLabelText), s)
Else
Me.lbTime.Text = s
End If
End Sub
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?
Private Sub SettxtChannelData(ByVal arrIndex As Integer, ByVal s As String)
If Me.txtChannelData(arrIndex).InvokeRequired Then
Me.txtChannelData(arrIndex).Invoke(New Action(Of String)(AddressOf SettxtChannelData), s)
Else
Me.txtChannelData(arrIndex).Text = s
End If
End Sub
|
|
|
|
|
Try this:
Me.txtChannelData(arrIndex).Invoke(New Action(Of Integer, String)(AddressOf SettxtChannelData), arrIndex, s)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Nope:
Me.txtChannelData(arrIndex).Invoke(New Action(Of Integer, String)(AddressOf SettxtChannelData), arrIndex, s)
Getting the error 'Too many type arguments to 'system.action(of T)'' on the "(Of Integer, String)" portion
|
|
|
|
|
If you are you using a version below .NET 3 the generic delegate suggested by Richard is not available and so you'll need to define one.
e.g.
|
|
|
|
|
Hi all!
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.
The code that does the work is :
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --user=root --password=mypassword --host=localhost --port=3306 --database sakila > "C:\backup\sakilabackup.sql"""
To be sure, I broke the code into two blocks, and I placed them to two textboxes as follows:
txtProgram.Text = "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" ,
txtArguments.Text= "--user=root --password=mypassword --host=localhost --port=3306 --database sakila >"C:\backup\sakilabackup.sql"""
Then I did this:
System.Diagnostics.Process.Start(txtProgram.Text, txtArguments.Text)
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.
I will appreciate any help.
(I use VB 2010)
|
|
|
|
|
Oops - incorrect message redacted.
Use the best guess
modified 2-May-13 7:26am.
|
|
|
|
|
Richard MacCutchan wrote: backslashes are escape characters in strings
Not in VB.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
#!%@#! That's the second time I've made this stupid mistake recently.
Use the best guess
|
|
|
|
|
Thanks for offering to help though!
I tried it and did not work (well, at least it doesn't say "..Can not file the file specified" which is the error msg I've been getting)
If you can offer more help I will appreciate.
|
|
|
|
|
savedlema wrote: --user=root --password=mypassword --host=localhost --port=3306 --database sakila
Based on the other params; I'd expect a "="-sign between the words "database" and "sakila".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
savedlema wrote: Please remember that, if I take the contents of txtProgram.text and txtArguments.text and put them to a command prompt, it works fine.
You are writing the output of mysqldump into a file using the redirection operator > . This is implemented by the command processor, cmd.exe and to get the same effect using Process.Start the various bits should be
Process.Start ( Environment.GetEnvironmentVariable("COMSPEC"),
"/c ""C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe"" --user=root --password=mypassword --host=localhost --port=3306 --database sakila > ""C:\backup\sakilabackup.sql""")
Environment.GetEnvironmentVariable("COMSPEC") resolves to the path of the command processor and is convenient way of locating that program on any system. The arguments are now the command line you would have typed at the prompt, prefixed by /c to tell the command processor to exit once mysqldump has ended. Check all the quotes as I may have these wrong, VB isn't my usual language.
One thing to watch out for when using Process.Start is the working directory. If this needs setting then you should create a ProcessStartInfo object and use the correct overload of Process.Start.
Alan.
|
|
|
|
|
Thank you Alan!
But, I tried your suggested code and, when I run it, a small command prompt window appears and goes away suddenly without giving me time to read it, but I have been able to read that it brings that error message that says ".....is not recognized as internal or external program..batch file..."
But, at least its not saying "the system can not find the file specified"
Do you have any other idea on this? (Sounds like the solution is only few miles ahead!)
|
|
|
|
|
Change the /c in the arguments to /k. This will keep the window open after the command has run and let you see what's wrong.
Process.Start ( Environment.GetEnvironmentVariable("COMSPEC"),
"/k ""C:\Program ..... etc
The message "is not recognized as internal or external program" should be prefixed with the name of the program that can't be found.
Alan.
|
|
|
|
|
Hi Alan!
Thanks so much for that. I tried it, and as you said, now I'm able to see what's in the command window.
The error msg is this:
Quote: 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
I will appreciate more help with this, please.
Thanks.
|
|
|
|
|
If the pathname isn't quoted correctly the command processor will assume that it ends at the first space character.
It may be helpful check that the strings are correct by dumping them to a textbox or the console.
e.g.
Module Module1
Sub Main()
Dim cmd As String = Environment.GetEnvironmentVariable("COMSPEC")
Dim args As String = "/k ""C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe"" --user=root --password=mypassword --host=localhost --port=3306 --database sakila > ""C:\backup\sakilabackup.sql"""
System.Console.WriteLine(cmd)
System.Console.WriteLine()
System.Console.WriteLine(args)
End Sub
End Module
I assume that is correct as the console shows the pathname for mysqldump quoted correctly.
C:\WINDOWS\system32\cmd.exe
/k "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --user=root --password=mypassword --host=localhost --port=3306 --
database sakila > "C:\backup\sakilabackup.sql"
Alan.
|
|
|
|
|
Thanks Alan,
But sorry, I'm kind of a novice here; I created the module as in your reply, but what do I do with it? How do I run what's in that module?
I could only go as far as saying "Call module1.Main()" how should I proceed to run what's inside?
Thanks so far..
modified 3-May-13 10:32am.
|
|
|
|
|
Hi guys,
This might be a little tricky, I don't even know if it's possible.
I've got some code working, but to optimize the performance, I'd like to rewrite parts of it to enhance the performance.
The tables that need to be processed start with a merged cell (spanning all columns), but can be interrupted by another row where all cells are merged. The 2nd row always contains the same text but does not have to be processed.
I'm looking for some time now for an answer to the following questions:
* Is there a way to check if a table is uniform from the 3rd row on? Looping works, but it gets slow on long tables, so I want to avoid looping if possible.
* If the table is not uniform, is there a way to know wich rows are merged (also without looping if possible)?
* One column is populated with ID numbers, wich consist of a number, a linebreak (not a paragraph break) and a code. I want to set the font size for the number to 8 and the font size for the code to 1. Is there a way to apply this to the whole column at once instead of looping trough the cells?
If there's no way to avoid looping, it's not too bad. I've got the code working now, using loops, but since it can take over 5 minutes processing a table of say 600 rows (45 pages), I'm just looking for ways to increase performance.
Thanks in advance!
Cheers!
|
|
|
|
|
|
What kind of Word File are we talking about anyway?
if they are docx they migh be stored as a zip file. Than they are just xml files, and then you could do Linq or other things, they might be much faster.
|
|
|
|
|
Too bad... It's RTF... And the processing involves formatting, that's why taking it out of the document isn't really an option. But it's just a performance tweak
Cheers!
|
|
|
|
|
RTF = Rich Textbox Format?
BTW: it seems all newer formats of Office, that have the x after, like xlsx are stored as xml's in a zip file.
|
|
|
|
|
Indeed, plain Rich Text Format, the one WordPad has used ever since Windows 3.0 Means the file format could well be older than Word itself
The processing involves formatting, so exporting it to another program (like Excel) isn't really an option. I doubt there is a way to avoid the loops.
The macro runs from a userform (just to provide feedback). I start by setting Application.ScreenUpdate = False , and I regulary use Application.ScreenRefresh .
All of my loops end by calling the DoEvents statement. It's just to prevent Word from showing inresponsive. Elsewise, the user might think Word has crashed and force closure of the process. Maybe I used the DoEvents the wrong way...
Cheers!
|
|
|
|