Results 1 to 12 of 12

Thread: [RESOLVED] Output to a text file ..

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Lahore
    Posts
    214

    Resolved [RESOLVED] Output to a text file ..

    well i have a workspace in which i keep track of command buttons clicked by user and save them( names of those command buttons ) in a text file ( each name one on next line of this text file ) ... now i want to append a word "new" at very first line of that text file every time my program runs .. how can i do that without disturbing rest of the subs ? ..

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Lahore
    Posts
    214

    Re: Output to a text file ..

    plz Discard the previous post . i didnt know i can be such a stupid at times . anyway .. now i want that when my user clicks on a picturebox at run time my program pops out a window for him . in which my user enters any text and then my program saves that data in a text file ( line by line for each picturebox clicking ) . i hope i ll be making sense ..

  3. #3
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Output to a text file ..

    First off, how did you append "new" to the beginning of the text file? So, if I'm right, a text file with content:

    Code:
    Button1
    Button2
    etc
    would become

    Code:
    new
    Button1
    Button2
    etc
    as opposed to

    Code:
    Button1
    Button2
    etc
    new
    ?

    As for the picturebox, maybe


    Code:
    Private Sub Picture1_Click()
    Dim FF as integer
    Dim TextIn as string
    FF=freefile()
    
    TextIn = InputBox("Input value please")
    Open "C:\Output.txt" for Append as #FF
    Write #FF, TextIn
    Close #FF
    End Sub
    ?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Lahore
    Posts
    214

    Re: Output to a text file ..

    well arby . yeah the scenarios u showed were exactly what i wanted to do .. and for appending "new" to begining .. i simply created another command button . and captioned it as " press to start" and named it as "start " so that user clicks it after running first .. and then i created a sub like

    VB Code:
    1. Public Sub start()
    2. Print #FF, "New"
    3. End Sub

    where FF is the same file i m using for storing other values ..
    simple naa

    well i think the code you have given me right for me but what if Picture1 is a control array ( as i have in my case ) .. i have it instances in my workspace ... what will i do then

  5. #5
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Output to a text file ..

    Ahh, I see, nice one ^_^

    As for the Control array bit... err, that's where i get off the VB knowledge train, i'm still a newbie ^^;; .. We haven't covered Control Arrays yet, hopefully someone can suggest a modification though ^_^ Sorry about that

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Lahore
    Posts
    214

    Re: Output to a text file ..

    its ok .. i m more Goof to VB then another single individual over here .. and its been a lil time since i have been eating their brains and everybody here is real nice to help me out every time
    i m waiting for some other GURU to suggest me any solution of my problem ..

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Output to a text file ..

    It doesn't matter if you use a Control Array or not the code would be the same. However I would use Print #FF, sTheText instead of the Write # statement.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Lahore
    Posts
    214

    Re: Output to a text file ..

    Forget it .. did this too .. thanks a bunch to everybody

  9. #9
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: [RESOLVED] Output to a text file ..

    How did you do it differently?

    And JA, What's the diff wetween Write and Print (where it involves outputting to a file?) Just out of interest

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Output to a text file ..

    Quote Originally Posted by Arby
    How did you do it differently?

    And JA, What's the diff wetween Write and Print (where it involves outputting to a file?) Just out of interest
    There is no real difference in the code itself. The only difference is that in a control array all picture boxes share the same Click event, but that just means that he only needs to write the code in one click procedure instead of the same code for each of the picture boxes.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Output to a text file ..

    The Write # statement will put the string inside quotation marks.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Lahore
    Posts
    214

    Re: [RESOLVED] Output to a text file ..

    well i didnt do it much differently, i used ur code
    all i did is put ur code behind "button_click" instead of "picture_click" ... that helped me in giving data to every single instance .. as those instances are being created by "button_click" ...and i opened ur file in "form_load" and closed it in "form_unload" .. its working fine now
    well the only difference between print and write i came to know abt is that by print i got values in my text file like

    HTML Code:
    A4
    B5
    C7
    and by using write i got them like

    HTML Code:
    "A4"
    "B5"
    "C7"

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