Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text File - Visual Basic 6.0

Status
Not open for further replies.

Danielvb

Programmer
Oct 8, 2002
34
US
Hello programmers:

I am having problem controlling the printing from the text file. This is the issue:

-- My program creates a text file.

-- When the user opens the text file, the information gets display on a text box

-- The form has a print bottom so the user can print the text

- Once the user Click Print, the program opens the text file and started printing. Because some of the strings are too long, it prints one part and the other does not show up

For Example:

Original String:
------------------
Pablo Ozone from store #1319 sold 6 hams on Thursday and 3 more by 9:00 am today!!! $9 incentive pays for Flor!!! Week to date the store has sold 12 hams.



This is got printed on paper (This is happening because the string is too long):
-----------------------------------------------------------------------------------
Pablo Ozone from store #1319 sold 6 hams on Thursday and 3 more by 9:00


QUESTION:

How can I control the width of the string before write it in the text file?

Thanks to all for your time

Daniel
Hollywood, Florida
 
try this one

"your string messages" & vbcrlf
"your next string " & vbcrlf

DEK
 
I think you can try the following solutions :

1. Make the textfile a multiline one

2. Use a rich text box

3. Control the length of the string with the following code :

private sub txtMYSTRING_change()

if len(txtMYSTRING)>30 then msgbox "Text too long":exit sub
end sub

hope it helps

PK Odendaal
pko@942.co.za

 

Actually if you load the text file in a richtextbox and use it to print you will not need to test the length of the lines. The RTB will take care of most everything for you.

Good Luck

 
hello Vvb5prgrmr

Thanks for your feedback but I am pasting or typing the content on a Rich TextBox and I am looking to create a text file by using the command Print #1.

Once the user click the Print button, the content is going to the be save in a text file and not to the printer.

How can I control the length of the string so that in the text file does not show the long string in one line.

I hope this explains to you what I am trying to acomplish.

Thanks again and I hope to hear from you soon.

Daniel
Florida
 
I have showed you how to control the total length of the text file on the form. The print to file function print #1 will always print in one line. If you do not wish that to happen you can use this :

Open "TESTFILE" For Output As #1
Print #1, Left(Text1.Text, 10) & vbCrLf & Right(Text1.Text, Len(Text1.Text) - 10)
Close
PK Odendaal
pko@942.co.za

 
I "cheat" by putting the file into a RichTextBox with the chosen font and fontsize, saving it to a temporary file then SHELLing to Wordpad to print it.

objRTF.SaveFile strSavedFilename, rtfRTF
Shell "Wordpad """ & " strSavedFilename & """ /p"
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 

Well Danielvb, this is not an easy thing to do but by no means is it hard to do either. It is going to take a little inventiveness to be able to accomplish what you want to do. One of the ways to do this is to save it out as the unformatted text file and in the background reformat the text file by reading it in and testing the length of each line and writing to a new file based upon the length of the line you want to make. This is going to take the understanding of several string parsing function like Instr, InstrRev, Mid, Left and Right.

Good Luck

 
Thanks to all for your tips and knoweledge. I am very thanksful with your guys.


Daniel
Florida
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top