Complete Newbie

  • Thread starter Thread starter encino1030
  • Start date Start date
E

encino1030

I have only slightly tried to learn VB, and have been trying to do
something vith VB.net.

I am sure it is simple to some (probably most), but please bear with
me.

I want to creat a form with various buttons. each button will load a
file on the same CD that the exe file is on.
nothing fancy, just launch some .doc, .xls and PDF files.
second issue, I want to be able to load these files regarless of the CD
drive letter the user may have assigned to the drive.

I am just trying to learn some simple stuff, and am at a complete loss.

If someone has the time to walk me through the process, I would
appreciate it.

Thank you for your help
 
Try using this.

Dim pth as String = InputBox("What letter is your CD Drive assigned to?
Please use this format: "X".")
Process.Start(pth & ":\path to file.doc")

I hope this helps.
 
I want to creat a form with various buttons. each button will load a
file on the same CD that the exe file is on.
nothing fancy, just launch some .doc, .xls and PDF files.

This should be fairly straightforward...

Create your form and add the buttons you want to use to launch the files.
Lay them all out and set their properties however you want.

Double-click one of the buttons to open up its Click event handled in the
code editor. Paste in the following code:

\\\
Dim filename As String

'Get the drive the running EXE was launched from
filename = IO.Path.GetPathRoot(Assembly.GetExecutingAssembly.Location)

'Append the name of the file to open
filename &= "Test.doc"

'Launch the file
Process.Start(filename)

///

This code first gets the root path of the running executable. If it's
running from the CD-ROM drive, this will be the letter of that drive. It is
returned in the format "X:\".

The filename to be opened ("Test.doc" in this case) is then appended. Change
this for each button to be whatever you need. Include subdirectories too if
required (e.g., "MyFolder/MyFile.pdf").

Finally, Process.Start() is used to instruct Windows to open the file in the
appropriate file viewer. If no viewer is registered for the file type, this
will throw an exception so be prepared to catch it in this case. With a
little more work you can prompt the user to select which viewer to use under
these circumstances -- take a look at the documentation for the
System.Diagnostics.Process class for more info, and in particular the
ErrorDialog property.

HTH,
 
I will try this. Thank you for your help. Like I said, I am trying to
teach myself and will be looking for help frequently I am sure.

Thanks again
 
Back
Top