VB 6 ( Need to save in .txt file )

Discussion in 'Programming' started by raghav, Nov 24, 2007.

  1. #1
    Hi All,

    I am sure that i am at correct place for thread ?, I didnt found a VB section.
    I have a little programme that prints directely to the printer through LPT port, what i want is that, when the form is filled up with details and ready to print, it should create a .TXT file and make a entry of data.
    and in next time it should open the same .txt and enter the data in the next line, probably below it.
    Can some one help is general ? I am able to put the text file but i am unable to reopen and write the data in it.
    Help would be really appreciated.

    Regards
    Raghav
     
    raghav, Nov 24, 2007 IP
  2. iwyrobi

    iwyrobi Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you must append the text file.

    Open "file.txt" For Append As #1
     
    iwyrobi, Nov 25, 2007 IP
    raghav likes this.
  3. yngvie

    yngvie Peon

    Messages:
    178
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    why not save these data in a database?
     
    yngvie, Nov 26, 2007 IP
  4. raghav

    raghav Active Member

    Messages:
    716
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    70
    #4
    Yep thanks, works fine, Rep added :)

    you mean DB in MSexcel ? or ..i got you wrong ?
     
    raghav, Nov 26, 2007 IP
  5. chapicha

    chapicha Peon

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    database of "yngvie" mean MS Access or MS SQL server
     
    chapicha, Nov 26, 2007 IP
  6. raghav

    raghav Active Member

    Messages:
    716
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    70
    #6
    chapicha : you are correct, but now it seems that i am traped up somewhere else.

    Print command to LPT is working awsome to the printer, but I dont know code to send command to USB.
    I am using
    type c:\Prt.txt >lpt1
    Code (markup):
    when i swap LPT to USB..doesnt work (I knew it wont, just giving it a try )
    So any ideas how to proceed up ?
     
    raghav, Nov 26, 2007 IP
  7. iwyrobi

    iwyrobi Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    LPT and USB is different port, if you use type command it just print the output to lpt1
    and what about usb ? so better u use the printer object of vb. because the printer object use the windows printer. don't care if usb, lpt or network printer.
     
    iwyrobi, Nov 26, 2007 IP
  8. raghav

    raghav Active Member

    Messages:
    716
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    70
    #8
    Yes i can understand that, but i have used the printers code to set up a form and push command to LPT to give those codes to the printer, I was just wondring if any how the command can be send to USB ?

    Yes but then it will send to all ports of the PC ? and here we have more then 2 printers on a PC, wont it print on all ? or did i understood wrong what you have said ?
     
    raghav, Nov 26, 2007 IP
  9. iwyrobi

    iwyrobi Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    it use your default printer. you can set the default printer on windows control panel printer. or in code.
    
    Dim w As New WshNetwork
    w.SetDefaultPrinter (”ThePrinterYouWant”)
    Set w = Nothing
    
    Code (markup):
    you can read here for more tutorial on printing http://www.devarticles.com/c/a/Visual-Basic/Printing-With-Visual-Basic/3/

    u need to add referenced to Windows Script Host Object Model (/system32/wshom.ocx)
     
    iwyrobi, Nov 27, 2007 IP
  10. raghav

    raghav Active Member

    Messages:
    716
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    70
    #10
    iwyrobi
    The code did not work, dont know if i am doing something wrong.
    Isnt there any way simple like the one for LPT ? to through command to USB ?

    Secondly, As per your previos code, I was able to append and save, but can i make the data non editable or the txt file that cannot be deleted ?
     
    raghav, Nov 27, 2007 IP