|
treddie wrote: In his code, he does not include declarations for his API functions, although he does import namespaces. Is this because he is working in C# He does. You can browse the source code using the links in the article. His P/Invokes start on line number 46.
treddie wrote: the online converter cannot necessarily know that declarations need to be added to the converted code, if in fact they DO need to be. Bad translator.
treddie wrote: why wouldn't those same Import lines work just as well in vb.Net? If that is where these functions are located, then why does vb.Net require explicit declarations? Is this so an entire library does not need to be loaded into memory all at once? There's multiple ways to link/load a dll. The "using" or "import" lines are defining which namespaces to look in when searching for a specific class-type. Sometimes one needs to "add (a) reference" to an external assembly to be able to access types in other libraries. That's the usual route for managed code - anything in .NET.
There's also a lot of unmanged code on the machine, as is the WinAPI. The code is also linking to a specific part in the WinAPI in "kernel32.dll". Both VB.NET and C# need special declarations for these, decorated with the DllImport attribute.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Cool. Tank you very much for your help, Eddy.
|
|
|
|
|
You're welcome
|
|
|
|
|
Hello,
I have an application where users opens more than one windows on an MDI form.
I want users to be able to save their work environment for future opening and used. When next the saved look is open, all previously opened windows should also open at exactly where they were before closing/saving the work area.
Any help please
Thanks
|
|
|
|
|
A very high level suggestion to your question:
Save the information to a database table linked to the user or save it to an xml file on the user's computer
Then when the forms are next opened consult these saved settings and restore the forms to how the user left them.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
hello,
I have MDI form that users open more than one windows at a time. I want user to be able to save these opened windows and be able to reopen them next time.
Please help
Thanks
Olu
|
|
|
|
|
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.
|
|
|
|