-
Okay, you know when you double click on a *.txt file
and it automatically opens notepad AND it display's
the text in it? well how would you do that in VB?
How would you make it so when you open the file with your app, the text is automatically loaded.
-
There are many ways to open a file (i think), you could use an OLE, embed or link the file to it, and then use ole1.doverb to open the txt in the notepad or the registered program. Or if you want to put the data in a label or textbox you could read the data, combine it and post it on your label/textbox:
Dim StrText
Dim StrLine
Open "Path" for input as #1
Do until EOF(1) 'eof = end of file
LineInput #1, strline
strtext = strtext & strline
loop
close 1
textbox1.text = strtext
-
but I don't think the code will work if you double click
on a file. Okay, say in a file called "Myfile.mfl" there
are 2 strings: "John","Doe"
When someone double clicks on the file, I want it to launch
up my App and display the first string in Text1.text and
display the 2nd string in Text2.text
-
You may want to see "Parsing delimited text files"
http://www.vb-world.net/files/tip87.html
-
Well, let try this one but it just work correctly with .txt otherwise ghost code will appear if you try .doc or something else.
-------------------------------------
Copy this code to Form_Load:
Dim strPath as string
strPath = command()
'Make sure Path exist.
If dir(strPath)<>"" then
open strPath for input as #1
Text1.Text = input(Lof(1),1)
close #1
else
msgbox "Path not found."
end if
---------------------------------------
Note:
Just try you own extension instead of .txt (.Meg for example)
Then double clidk the file that you create (with .Meg)
When asking to open with program > Click Other > browse to you exe.
Hope that help
vbkids
-
IF it is the executing parameters, i had the same problem, check this out:
http://www.vb-world.net/forums/showt...threadid=11843
-
If you want to have 2 string in different TextBox. Then it is your skill.
One way is making random file.
using Command() to get file name.
Then you have your own format of random file.
Supposed:
Type MyFileStructure
StrForText1 as String*12
StrForText2 as String*14
End Type
When you have such file use this code.
Dim MyFile as MyFileStructure
Dim strPath as String
StrPath = Command()
'Test if file exist as the old one that I showed.
'Then
open StrPath for Random as #1 len= len(MyFile)
Get #1,1,MyFile
Text1.Text = MyFile.StrForText1
Text2.Text = MyFile.StrForText2
close #1
Well let see how it work :)