-
Apr 11th, 2021, 09:17 AM
#1
Thread Starter
Addicted Member
print list1 four columns
Hi, I'm ontro
I am making an application where there is a list1 and a commandbuton to print
On the screen it does it well, I can change position, but the problem is that I cannot change position when printing here is the code I have so far:
Code:
Option Explicit
Private Declare Function SendMessageArray Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Const LB_SETTABSTOPS = &H192
Private Sub Command1_Click()
Unload Me
Form1.Show
End Sub
Private Sub Command2_Click()
'Imprimir
Dim BeginPage As Long, EndPage As Long, NumCopies As Long, Orientation As Long, Tell As Long
Dim i As Integer
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
CommonDialog1.Flags = &H40&
CommonDialog1.ShowPrinter
BeginPage = CommonDialog1.FromPage
EndPage = CommonDialog1.ToPage
NumCopies = CommonDialog1.Copies
Printer.Orientation = CommonDialog1.Orientation
With Printer
If .Orientation = 1 Then
.Orientation = vbPRORPortrait
Else
.Orientation = vbPRORLandscape
End If
End With
Printer.Font.Name = "Courier"
Printer.Font.Size = 10
Printer.FontBold = True
Printer.Print Tab(5); "HORA: " & UCase(Format(Now, "hh:mm am/pm"))
Dim aux As String
Printer.Font.Name = "Arial"
Printer.Font.Size = 18
Printer.FontBold = True
Printer.DrawWidth = 10
Printer.DrawStyle = 2
Printer.CurrentX = 4000
Printer.CurrentY = 0
Printer.Print "Listado de Contectos"
Printer.CurrentY = 1000
Printer.CurrentX = 1000: Printer.Print "Nombre"
Printer.CurrentY = 1000
Printer.CurrentX = 3500: Printer.Print "E-mail"
Printer.CurrentY = 1000
Printer.CurrentX = 7350: Printer.Print "Tel Celular"
Printer.CurrentY = 1000
Printer.CurrentX = 9900: Printer.Print "Tel Casa"
'Dim i As Integer
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
Printer.Print List1.Text
Next i
Printer.Print
Printer.EndDoc
Exit Sub
ErrHandler:
Exit Sub
End Sub
Private Sub Form_Load()
muestrareg
End Sub
Private Sub muestrareg()
ReDim lbtab(1 To 4) As Long
lbtab(1) = 10
lbtab(2) = 120
lbtab(3) = 250
lbtab(4) = 360
SendMessageArray List1.hwnd, LB_SETTABSTOPS, 4, lbtab(1)
On Error Resume Next
Dim nombrearch As String
Dim filefree As String
filefree = FreeFile
nombrearch = App.Path & "\Agenda.txt"
Open nombrearch For Random As #1 Len = Len(contacto)
While Not EOF(1)
Get #1, , contacto
List1.AddItem vbTab & contacto.nombre & vbTab & contacto.imeil & vbTab & contacto.celular & vbTab & contacto.casa
Wend
Close #1
End Sub
and in a module
Code:
Public Type persona
nombre As String * 35
imeil As String * 35
celular As String * 10
casa As String * 10
End Type
Global contacto As persona
Global datostemp As persona
Global regactual, totalreg As Long
Thank you
-
Apr 11th, 2021, 11:51 AM
#2
Re: print list1 four columns
So what do you mean when you say you can't change it? Your code does change the position but only for the headers.
If I had to guess I would say your columns are not lining up the way you want. I am not really sure what you get in the text property of the list when it is multi column as I pretty much never use multi column list boxes. When I need columns I generally use a grid or list view.
What is it you are trying to change the position of, how are you trying to change it and what error or result are you getting?
-
Apr 11th, 2021, 12:20 PM
#3
Thread Starter
Addicted Member
Re: print list1 four columns
Hello
I mean, I can't change my position column 1 column 2 column 3 column 4 on the paper to the left or right, move column 3 to the left or right as appropriate
Since I can do it on the screen, but not on the printer.
-
Apr 11th, 2021, 03:35 PM
#4
Re: print list1 four columns
You did not say how or what you tried.
I assume when you say you can do it on the screen that you mean you are using the mouse to drag the column right or left to make it bigger or smaller. It you were using the form print method then the list would print the way it looks on the screen but since you are printing the text of the list I would not expect any column sizing to carry over. I really have no idea how it shows up in the text when there are multiple columns. You may need to split the text and position the columns using the currentx currenty properties of the printer or by inserting spaces to make each column a given length.
-
Apr 11th, 2021, 04:33 PM
#5
Re: print list1 four columns
Although it is possible to use listboxes with columns (of course), but you might want to look at listviews or grids (msflex, mshflex, vb, etc). Easier on the eye! (and easier to code)-IMHO
Sam I am (as well as Confused at times).
-
Apr 11th, 2021, 04:59 PM
#6
Thread Starter
Addicted Member
Re: print list1 four columns
Thanks for the answers
but I have not resolved the issue
the issue is that what is on the screen of list1 comes out the same in the printer
the function lbtab can vary the position of the columns of list1 in printer?
Thanks
-
Apr 11th, 2021, 05:59 PM
#7
Re: print list1 four columns
Well like I said you should be able to split the string and then you have control over where the columns are printed just like you do with the header.
-
Apr 12th, 2021, 02:37 AM
#8
Thread Starter
Addicted Member
Re: print list1 four columns
Can you give me an example of what you say thank you
-
Apr 12th, 2021, 02:56 AM
#9
Re: print list1 four columns
This is air code, untested:
Code:
Dim aLine() As String
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
' The Text is delimited with a Tab
aLine = Split(List1.Text, vbTab)
Printer.CurrentX = 1000: Printer.Print aLine(0)
Printer.CurrentX = 3500: Printer.Print aLine(1)
Printer.CurrentX = 7350: Printer.Print aLine(2)
Printer.CurrentX = 9900: Printer.Print aLine(3)
Next i
-
Apr 12th, 2021, 06:53 AM
#10
Thread Starter
Addicted Member
Re: print list1 four columns
Thank you Armoutdv
I have tried the following code
Code:
Dim aLine() As String
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
' The Text is delimited with a Tab
aLine = Split(List1.Text, vbTab)
Printer.CurrentX = 735: Printer.Print aLine(0)
Printer.CurrentX = 4000: Printer.Print aLine(1)
Printer.CurrentX = 7000: Printer.Print aLine(2)
Printer.CurrentX = 10000: Printer.Print aLine(3)
Next i
and does the following to me
nombre e-mail tel celular tel casa
a
a
a
a
b
b
b
b
c
c
c
c
How do I get it to print everything followed by column? Thank you
-
Apr 12th, 2021, 06:58 AM
#11
Thread Starter
Addicted Member
Re: print list1 four columns
Code:
nombre e-mail tel celular tel casa
a
a
a
a
b
b
b
b
c
c
c
c
How do I get it to print everything followed by column? Thank you
-
Apr 12th, 2021, 08:39 AM
#12
Re: print list1 four columns
In the case above your currentY is changing with each print statement. Print issues a line feed. You need to surpress the line feed on all but the last column. You do this bay adding a semicolon to the end of the statements.
Code:
Printer.CurrentX = 735: Printer.Print aLine(0);
Printer.CurrentX = 4000: Printer.Print aLine(1);
Printer.CurrentX = 7000: Printer.Print aLine(2);
Printer.CurrentX = 10000: Printer.Print aLine(3)
The code above will drop to the next line after the last print statement rather than after every print statement.
-
Apr 12th, 2021, 11:29 AM
#13
Thread Starter
Addicted Member
Re: print list1 four columns
right OK
issue resolved
Thank you so much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|