Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

VB Setup Projects File Associations + more

Hello,

I have recently acquired the Visual Basic .NET 2003 software (to begin programming, I went through the Visual Basic .NET Step by Step book), and have some questions about VB .NET programming that I could not find answers to in the help files. If anyone can answer these questions, some samples in code would be very helpful too. The questions are:

1. VB Setup Projects File Associations: I have been trying to create file associations (using a setup project) so that when a file is opened via Windows Explorer (say a text file: file1.txt) it will start with my program and the program will show the file chosen. The trouble I am having is that I can't find out how to make the program recognise and open the file selected in Explorer. The only thing that happens when I double click a file is that my program starts, but without showing the file. I think this is something to do with Actions, but where do I put the code, and how do I make it open the file selected? Basically, what do I do?

Here are the other questions:
2. Port communication: Is there any way to communicate directly with ports (i.e.. the sockets at the back of the computer) that is not too complicated (like I think writing driver software would be)? I am thinking of making an electronic device to be controlled by the computer, so no current software would recognise it.

3. .NET Compact framework: Would the .NET compact framework be suitable for desktop computers where installation size is important? If so, how do I obtain it (for redistribution)?

If this is not descriptive enough, please tell me what else you need to know. I have tried many people, but nobody has been able to help.

Thank you for your assistance.

VBDever
[1782 byte] By [VBDever] at [2007-11-11 6:38:04]
# 1 Re: VB Setup Projects File Associations + more
You can create a Setup and Deployment Project to create a file association:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vbtskcreatinginstallerforyourapplication.asp

Regarding port communication see the following:

http://www.microsoft.com/downloads/details.aspx?FamilyID=075318ca-e4f1-4846-912c-b4ed37a1578b&DisplayLang=en

The Compact Framework is for .NET applications that run on mobile devices.
pclement at 2007-11-11 20:48:50 >
# 2 Re: VB Setup Projects File Associations + more
More information on your first question: When you launch an app via an associated file, the file name(s) are passed to your application as command line parameters. See the following article for details on how to process these parameters: http://www.dev-archive.com/dotnet/Article/10115
Phil Weber at 2007-11-11 20:49:44 >
# 3 Re: VB Setup Projects File Associations + more
I have got File associations working with Console Applications, but when I try using Command() in the Windows Forms enviroment I get the following error message:
'System.Windows.Forms.Command' is not available in this context because it is 'Private'.
'This is the code I typed above the 'Windows Forms Designer Generated Code' Region
'of Form1 (the startup form)
Dim filename As String = Command()
Do you know how to get Command() (or it's equivelant) to work with Windows forms? :confused:
VBDever at 2007-11-11 20:50:54 >
# 4 Re: VB Setup Projects File Associations + more
Command() is a function, so it must be used within a method (a Sub or a Function). It sounds like you're trying to use it outside a method.

Another option is to start your application with a Sub Main, which may optionally receive command line parameters as an array:

Sub Main(ByVal args() as String)
For Each FileName As String In args
' Process FileName here
Next
End Sub
Phil Weber at 2007-11-11 20:51:55 >
# 5 Re: VB Setup Projects File Associations + more
When I enter that code and choose 'Run', I get the following build error:
No accessable 'Main' method with appropriate signature was found.
I tried making a Main() function (below), but it still had the same error!

Public Sub Main()

End Sub

:confused:
VBDever at 2007-11-11 20:52:48 >
# 6 Re: VB Setup Projects File Associations + more
Try looking up "Sub Main" in VB's online help. Or look in your "Step-By-Step" book; doesn't it mention Sub Main?
Phil Weber at 2007-11-11 20:53:53 >
# 7 Re: VB Setup Projects File Associations + more
Thanks, everything is working now, I put Sub Main() in a seperate module and set the startup object of my project to Sub Main. :)
VBDever at 2007-11-11 20:54:53 >