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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing text file - problem

Status
Not open for further replies.

shanmugham

Programmer
Jun 19, 2001
71
0
0
IN
Dear friends

i have a text file "doc6.txt"

that text file was created through program (fox pro - text file)

i wanted to take the print out thru laser rint

thru the following VB program
=================================================
On Error GoTo error1
bcancel = False
CommonDialog1.Flags = cdlPDHidePrintToFile Or _
cdlPDNoSelection Or _
cdlPDNoPageNums Or _
cdlPDCollate
CommonDialog1.CancelError = True
CommonDialog1.PrinterDefault = True
CommonDialog1.Copies = 1
CommonDialog1.ShowPrinter

If bcancel = False Then
Printer.Print ;
With Printer
.FontName = "Roman"
.FontSize = 10
.FontBold = False
.FontItalic = False
.FontUnderline = False
End With
Dim i1, j, n, k As Integer
TheIndex = 0
Open ("d:\ftp\doc6.txt") For Input As #1
Do Until EOF(1)
Line Input #1, tempstring
Printer.Print ; RTrim(tempstring)
TheIndex = TheIndex + 1
Loop
Close #1
MsgBox "over"
End

End If
Exit Sub
error1:
If Err.Number = cdlCancel Then
bcancel = True
Resume Next
End If
End Sub
=================================================
at the time of printing, the each line alignment was changed, that is
for example input text file as
=================================================
7. CORPUS FUND FOR
EMPLOYEES HEALTH FUND 130

8. CORPUS FUND FOR FAMILY BENEFIT
FUND/GROUP INSURANCE SCHEME 131

9. CORPUS FUND DEATH-CUM-RETIREMENT
GRATUITY 132
======================================================
it prints the following way, i.e. zig zag way


7. CORPUS FUND FOR
EMPLOYEES HEALTH FUND 130

8. CORPUS FUND FOR FAMILY BENEFIT
FUND/GROUP INSURANCE SCHEME 131

9. CORPUS FUND DEATH-CUM-RETIREMENT
GRATUITY 132
======================================================

how can i overcome this problem

thanks in advance

shan




 
To start I would have a closer look at the data, is it possible that there are spaces or tab characters at the beginning of the string ?

As a comment the line Dim i1, j, n, k As Integer seems superfluous...
 
If you don't have control on incoming data layout, you might do better to use Trim rather than RTrim and insert your own Tabs/spaces whatever to line it up as you want.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Dear johnwm
if i use ltrim, some string come left side

the following line
8. CORPUS FUND FOR FAMILY BENEFIT
FUND/GROUP INSURANCE SCHEME 131
prints

8. CORPUS FUND FOR FAMILY BENEFIT
FUND/GROUP INSURANCE SCHEME 131

what can i do

thanks
shan
 
As I said in my previous < insert your own Tabs/spaces whatever to line it up as you want.>

Printer.Print vbTab & Trim(tempstring)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 

Sir,

after inserting vbTab , after printing no change, any other command available instead of vbTab

thanks

shan
 
The Space function - see VBHelp for details

Space(6)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
thanks johnwm

doc6.txt as text file

i want to print already created file named doc6.txt

i understand that space function is used at the time of creation only, i want to print already created report Sir

if u want to test my doc6.txt file, i will send u thru email

shan
 
Sorry I intended that you use the Tab or Space when you print, after you do the Trim:


myString = Trim(myString)
Printer.Print Space(6) & myString

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
it does not work, any other shortcuts available ?

shan
 
Another aside following on from earlier comment that:

>As a comment the line Dim i1, j, n, k As Integer seems superfluous...

I believe that this will declare i1,j & n as Variant datatypes and k as an integer which is probably not the intention - more likely:

Dim i1 As Integer, j As Integer, n As Integer, k As Integer

I started off making the same assumption in VB - i.e. that datatype applied to all preceding declarations.
 
By superfluous I meant that they are not used after being declared.

You would also need to remove existing tabs first -

MyString = replace(MyString,vbtab,&quot;&quot;)
 
Ooops my previous suggestion could introduce new problems if there are tabs embedded elsewhere in the string....

They should only be removed from the start of the string, you would need to use some sort of loop such as

MyString = Trim(MyString)
Do Until Left(MyString, 1) <> vbTab
MyString = Trim(Mid(MyString, 2))
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top