Results 1 to 7 of 7

Thread: Opening files

  1. #1
    Guest
    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.

  2. #2
    Junior Member
    Join Date
    Jan 2000
    Location
    MN, USA
    Posts
    25
    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

  3. #3
    Guest
    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


  4. #4
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    You may want to see "Parsing delimited text files"
    http://www.vb-world.net/files/tip87.html

  5. #5
    Junior Member
    Join Date
    Feb 2000
    Posts
    19
    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

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    IF it is the executing parameters, i had the same problem, check this out:
    http://www.vb-world.net/forums/showt...threadid=11843

  7. #7
    Junior Member
    Join Date
    Feb 2000
    Posts
    19
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width