Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 5th, 2007, 01:43 AM
Registered User
Join Date: Dec 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default auto generate & save text file


I'm just starting to learn VP 2005 Express, i'm currently working an application that the end result is to WRITE the text from TXTBOX to a file then PRINT and SAVE to a file, i got the WRITE & PRINT part correctly but i cant get it to automatically generate a text file name and save it to a folder. For example when i click print, after it print i want it to save the file as "{"time"&"date"}.txt" so that it doesn't override the old one.

Please help me i'm realy stuck.

Here is my code:

Dim docFile As String = "C:\doc.txt"

Private Sub tbPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbPrint.Click

If tbDisplay.Text = Nothing Then

MsgBox("Click On New Document Button First")

ElseIf tbCal.Text = Nothing Then

MsgBox("Must complete Document to Print")


tbDisplay.Text = tbDisplay.Text & vbCrLf & "Document: " & tbCal.Text & vbCrLf

If System.IO.File.Exists(docFile) = True Then

Dim objWriter As New System.IO.StreamWriter(docFile)




MsgBox("File Does Not Exist")

End If


streamToPrint = New StreamReader("C:\doc.txt")


printFont = New Font("Courier New", 8)

Dim pd As New PrintDocument()

AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage




End Try

Catch ex As Exception


End Try



End If

End Sub

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)

Dim linesPerPage As Single = 0

Dim yPos As Single = 0

Dim count As Integer = 0

Dim leftMargin As Single

Dim topMargin As Single

Dim line As String = Nothing

' Calculate the number of lines per page.

linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

' Print each line of the file.

While count < linesPerPage

line = streamToPrint.ReadLine()

If line Is Nothing Then

Exit While

End If

yPos = topMargin + count * printFont.GetHeight(ev.Graphics)

ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())

count += 1

End While

' If more lines exist, print another page.

If (line IsNot Nothing) Then

ev.HasMorePages = True


ev.HasMorePages = False

End If

End Sub

End Class
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Save PDF file as text file in VB.Net kvenkatu Classic ASP Basics 0 April 7th, 2006 01:09 PM
save a PDF file as text file through VB. NET kvenkatu VB.NET 0 April 6th, 2006 12:15 PM
How to Read,Write, & Save (File Processing) ck C++ Programming 2 April 18th, 2005 07:28 AM
how to generate a text file using .NET? pooh2323 VS.NET 2002/2003 2 February 11th, 2004 11:30 AM
How to generate a text file? bebe XML 2 October 9th, 2003 10:51 AM

All times are GMT -4. The time now is 12:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.