English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have made a Txt file on my desktop, and call it Test.txt.

If I right click on it and say Open With then find my program, I want my program to know the directory and filename of the txt I just opened with. EG. C:\Documents and Settings\user name\Desktop\Test.txt

How do I make my program learn that? Obviously, I would do it to different files.

And if possible, (Or is this too much) If I open with on a shortcut, can it tell my program not itself but the shortcut it is pointing to.

2007-10-14 00:50:47 · 4 answers · asked by Mattmatician 3 in Computers & Internet Programming & Design

4 answers

>I want my program to know the directory and filename

dim fso
dim varFileName
dim varDrive
dim varFolder
dim strFileSpec As String

strFileSpec = "C:\Documents and Settings\user name\Desktop\Test.txt"
set fso = CreateObject("Scripting.FileSystemObject")

' returns Test.txt
varFileName = fso.GetFile(strFileSpec)

' returns C:
varDrive = fso.GetDrive(strFileSpec)

' returns C:\Documents and Settings\user name\Desktop
varFolder = fso.GetFolder(strFileSpec)

FileSystemObject is a useful add-on to VB - allows you to do all sorts of things with drives, folders and files.

2007-10-14 06:58:45 · answer #1 · answered by JA12 7 · 0 0

In vb2005 you can create settings via the programs property page which are accessible via the new MY object. ( my.settings OR my.mysettings).

The technical term for remembering data between sessions is called persistance. You will need to store your settings to a standardized location your program will easily find, and if it can't find the settings it will have to use default settings so it doesn't generate an error.

Settings management and persistance is done via the registry. Other means are available such as making an INI file, using a txt file or storing info into a database. (Your choice)

As I mentioned VB2005 has an easy way to manage settings builtin to the new MY object. Project > ....Properties then click on the settings TAB

You can accomplish your own settings managment by providing a set of variables to store the information in. These variables need to be either
1.) global
2.) Module level at the main form
3.) or encapsulated within a module or class object

The idea is to simply save the information to a variable which won't get destroyed or erased while the program is running. Then persist that data by storing it in one of the aformentioned locations. I preferr to make a settings module as I can easily reuse the module in another program.

Module modSettings
Private m_filename As String

Public Property myFilename() As String
Get
myFilename = m_filename
End Get
Set(ByVal value As String)
'you can add code here to validate
'and ensure a "" is not entered
m_filename = value
End Set
End Property
Public Sub ResetFilenameToDefault()
m_filename = "C:\mydefault.txt" ' or whereever
'or
m_filename = My.Application.Deployment.DataDirectory & "\myfile.txt"
End Sub
Public Sub SaveSettings()
'TODO: write code to store to a txt file

ENd Sub
End Module


This is a small sample settings module which provides a property and methods to manage a filename. I did not include a functional SAVE function as you will have to define where and how you save this setting. You will also have to manage when the setting is saved for reuse when the program is started again. Typicaly this can bedone when ever a setting is changed or at program close. I preferre to offer the user the option to save the settings instead of relying on automatic saves. This allows the user to easily revert to the previous setting (using a readsettings function) if they don't like the new setting .

2007-10-14 03:04:33 · answer #2 · answered by MarkG 7 · 0 0

for the second part---

when you make 100 copies of a file, it doesn't mean that 100 physical copies of your file have been made.
the operating system just creates links for them, pointing to the original file, but it refelcts the size of 100 copies on the disk free space.
in case of a shortcut, a special link is created in which the only difference is that the link doesn't reflect any changes to free space and is dependent on the existence of one of the links of the original copy. Else remains the same.
so, you guessed it right, SHORTCUT CAN ALSO TELL YOUR PROGRAM ABOUT THE ORIGINAL COPY, don't be worried about that.

2007-10-14 01:24:29 · answer #3 · answered by Rahul K 2 · 0 0

once you first open the considered situation-free 2005, look on the left hand section. You shoudl see a container that announces "present day initiatives". You rfile would properly be below there. Double click on the rfile you opt for to open. If it opens yet you do now no longer see your challenge, look to the perfect. There would properly be a grey container talked about as "answer Explorer". below it really is going to be your rfile call and the words "My challenge" and "Form1.vb". the 'Form1.vb' section would properly be diverse searching on you opportunities. Double click on the "Form1.vb" and your challenge might want to look. From there you may jsut double click on your challenge to view your code.

2016-10-21 03:31:04 · answer #4 · answered by ? 4 · 0 0

fedest.com, questions and answers