José Perez
asked on
create a simple formatted Word document or text.
i have a form with several textboxes (10).
i need to print this values in specific positions, it is for a invoice printing app. the result file will be printed with the values only, no images, no backgrounds, just values.
the program does not save any info into any database.
i think the best choice can be to create a Word document and write the information on specific coordenates (x,y). maybe another choice can be create a notepad text file and write into this file, but i dont know how to position the values from the textboxes.
any ideas can help and if any sample source is avaailable, please tell it. and as faster as i can apply a solution.
points will be assigned to the best simple choice.
many, many thanks,
B!
i need to print this values in specific positions, it is for a invoice printing app. the result file will be printed with the values only, no images, no backgrounds, just values.
the program does not save any info into any database.
i think the best choice can be to create a Word document and write the information on specific coordenates (x,y). maybe another choice can be create a notepad text file and write into this file, but i dont know how to position the values from the textboxes.
any ideas can help and if any sample source is avaailable, please tell it. and as faster as i can apply a solution.
points will be assigned to the best simple choice.
many, many thanks,
B!
ASKER
ok, i am understanding, this code is very good, however, i would really like if you code explain a little bit more about the "spaces" usage, just comment, please, for me to understand better.
many thanks,
B!
many thanks,
B!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!
many thanks!
B!
many thanks!
B!
thanks for the points, and happy coding!
ASKER
thanks to you!
and God bless you :)
Oscar.
and God bless you :)
Oscar.
take a textbox
set the font to courier (or courier new)
now a space is the same width as every letter.
formatting is really easy now
example: (left and right alignment!)
create a new form, with a button (command1) and a textbox (text1)
make sure text1 is multiline!
now paste this code, run the program and press the button
Option Explicit
Private Sub Command1_Click()
Text1.Text = "Left aligned example:" & vbCrLf
Text1.Font = "Courier new"
Text1.FontSize = 8
Text1.Width = 6855
Text1.Height = 3975
align_Left "1", "2", "3", "4", "5"
align_Left "5", "4", "3", "2", "1"
align_Left "one", "two", "three", "four", "five"
align_Left "11", "22", "33", "44", "55"
Text1.Text = Text1.Text & vbCrLf & vbCrLf & "Right aligned example:" & vbCrLf
align_Right "1", "2", "3", "4", "5"
align_Right "5", "4", "3", "2", "1"
align_Right "one", "two", "three", "four", "five"
align_Right "11", "22", "33", "44", "55"
End Sub
Private Sub align_Left(x1 As String, x2 As String, x3 As String, x4 As String, x5 As String)
Const CharField As Long = 10 'size of each field
Dim tmp As String
tmp = x1 & Space$(CharField - Len(x1))
tmp = tmp & x2 & Space$(CharField - Len(x2))
tmp = tmp & x3 & Space$(CharField - Len(x3))
tmp = tmp & x4 & Space$(CharField - Len(x4))
tmp = tmp & x5 & Space$(CharField - Len(x5))
Text1.Text = Text1.Text & tmp & vbCrLf
End Sub
Private Sub align_Right(x1 As String, x2 As String, x3 As String, x4 As String, x5 As String)
Const CharField As Long = 10 'size of each field
Dim tmp As String
tmp = Space$(CharField - Len(x1)) & x1
tmp = tmp & Space$(CharField - Len(x2)) & x2
tmp = tmp & Space$(CharField - Len(x3)) & x3
tmp = tmp & Space$(CharField - Len(x4)) & x4
tmp = tmp & Space$(CharField - Len(x5)) & x5
Text1.Text = Text1.Text & tmp & vbCrLf
End Sub