Results 1 to 7 of 7

Thread: open text file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Red face

    Hey guys check this out...i have a readme.txt in

    \flag\documents\readme.txt

    I want a command button to open it....i seem to be getting access errors everytime i use the open command....any help?

    Note: If i understand correctly you have to put if its readonly or not...if so then make it readonly...also with the tips in the tip section all the open code gives me wrong path or file name and its in there....
    -RaY
    VB .Net 2010 (Ultimate)

  2. #2
    New Member
    Join Date
    May 2000
    Location
    Rochester, NY
    Posts
    6

    Security

    I have had those problems when trying to open files on computers at school due to their Fortres 101 security crap... any security programs on the computer you're running this app on? If not then maybe you're using the open command wrong. This is the format -

    Code:
    Private Sub Command1_Click()
    Open "...\flag\documents\readme.txt" for Input as #1
    Input #1, strVariable
    Close #1
    End Sub
    That will put the contents of that readme.txt file into strVariable. If that doesn't help I don't know what to tell ya...

    [Edited by ToneDogg on 05-30-2000 at 02:39 PM]

  3. #3
    Guest
    Yes, but if you require multiple lines, that method will not work. If you want multiple lines, the method below will work.

    Make a Form with a CommandButton and a TextBox. Put the below code in the CommandButton

    Code:
    Private Sub Command1_Click()
    
       ' This will open the file and place the contents in
       ' a TextBox
    
       Open "C:\MyFile.txt" For Input As #1
       Text1 = Input(LOF(1), 1)
       Close #1
    
    End Sub

  4. #4
    New Member
    Join Date
    May 2000
    Posts
    13

    Talking My experience...

    My experience with partial paths has met with limited success. Sometimes the current directory isn't what I expect it to be, so (wrong or not) I always format as follows:

    pathname = app.path & "\flag\documents\readme.txt"

    and then open the file.

    Hope that's helpful!

    Shawn

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Unhappy ARGHHH

    Ok guys, first i want to say the reason why i was getting a file not found is because i am using vb3 and the documents dir is more then 7 characters so it didn't recognize it!!!! After i figured that out i tried your code with the \flag\doc\readme.txt.......

    First i tried tonedogg's didnt work...

    then i tried you meth...it workssss however its one huge line with boxes for spaces and a big mess....I was under the assumption that notepad would just open up and show me the readme.txt..... is there a way to do that? If not how can i get the text to scroll down not one big bunch line.
    -RaY
    VB .Net 2010 (Ultimate)

  6. #6
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    Well, I don't know if it works in VB3, but I use a Rich Text box and the code
    Text1.Loadfile filename

    where filename is a string containing the full path and name, e g "C:\vb98\flags\readme.txt" or whatever it is.

    If you want the file opened by notepad I guess it could be done with the shell command, but I don't know hot.
    Good luck,
    Pentax
    Wilhelm Tunemyr,
    Swede in London

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Code:
    Open myFile for Input as #1
    Do until Eof(1)
    Input #1, myNewVar 
    myVar = MyNewVar & myVar
    Loop
    Close #1

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