elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  problema en i,primir varias hojas
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problema en i,primir varias hojas  (Leído 1,005 veces)
corlo

Desconectado Desconectado

Mensajes: 114


Ver Perfil
problema en i,primir varias hojas
« en: 15 Julio 2024, 00:02 am »

Hola
tengo un problema a la hora de imprimir varias hojas me hace el listado seguido
hago el siguiente calculo

Código
  1.  
  2.  
  3. If i = 24 Then    
  4.  
  5.  
  6. Printer.NewPage
  7.  
  8. encabezado
  9. End If
  10.  
  11.  


no logro que me cambie de hoja



Código
  1.  
  2.  
  3. Private Sub imprimir()
  4. ' Imprimir
  5.  
  6. 'Imprimir
  7. Dim BeginPage As Long, EndPage As Long, NumCopies As Long, Orientation As Long, Tell As Long
  8. Dim i As Integer
  9. Dim fuente As StdFont
  10. Set fuente = Printer.Font
  11. 'Set fuente = Printer.Font
  12. CommonDialog1.CancelError = True
  13.  
  14. On Error GoTo ErrHandler
  15.  
  16.  
  17.  
  18. CommonDialog1.Flags = &H40&
  19.   CommonDialog1.ShowPrinter
  20.  
  21.  
  22. BeginPage = CommonDialog1.FromPage
  23.   EndPage = CommonDialog1.ToPage
  24.   NumCopies = CommonDialog1.Copies
  25.  
  26.  
  27.  Printer.Orientation = CommonDialog1.Orientation
  28.  
  29.  
  30.  With Printer
  31.   If .Orientation = 1 Then
  32.        .Orientation = vbPRORPortrait
  33.    Else
  34.        .Orientation = vbPRORLandscape
  35.    End If
  36.  
  37.  End With
  38.  
  39.  
  40. On Error Resume Next
  41.  
  42. Dim numCols As Integer
  43.    Dim filas As Long
  44.  
  45.  
  46. encabezado
  47.  
  48.  
  49.    listarcolumnas
  50.  
  51.  
  52.   If i = 24 Then    
  53.  
  54.  
  55. Printer.NewPage
  56.  
  57. encabezado
  58. End If
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. Printer.Print
  68.  
  69.  
  70.  
  71.  
  72. Set Printer.Font = fuente
  73.  
  74.  
  75. Printer.EndDoc
  76. ' Set Printer.Font = fuente
  77. Exit Sub
  78.  
  79. ErrHandler:
  80. ' El usuario hizo clic en el botón Cancelar.
  81. Exit Sub
  82.  
  83.  
  84. End Sub
  85.  
  86. Private Sub listarcolumnas()
  87. Dim AnchoPapel As Integer
  88.    Dim MargenIzquierdo As Integer
  89.    Dim numCols As Integer
  90.    Dim filas As Long
  91.    Dim ultimafila As Long
  92.    Dim k As Long, j As Long, i As Integer, n As Integer, anchocol As Integer
  93.    Dim linea As String
  94.    Dim margen As Integer
  95.    Dim fuente As StdFont
  96.  
  97.  
  98.    Set fuente = Printer.Font
  99.    numCols = 9
  100.    Printer.FontName = "Courier New"  ' una fuente monoespaciada, si no el trabajo es más laborioso...
  101.    filas = ((List1.ListCount + 1) \ numCols)
  102.    ultimafila = ((List1.ListCount + 1) Mod numCols) ' columnas que tendrá la última fila.
  103.    anchocol = ((AnchoPapel - MargenIzquierdo) \ numCols)
  104.  
  105.  
  106.    For k = 0 To filas - 1
  107.        n = margen
  108.        For i = 0 To numCols - 1
  109.            Printer.CurrentX = n  ' imprime el texto de la columna 'i'
  110.            Printer.Print List1.List(j + i)
  111.            n = (n + anchocol)
  112.        Next
  113.  
  114.        j = (j + numCols)
  115.        Printer.CurrentY = (Printer.CurrentY + Printer.TextHeight("t"))  ' el textheight depende de la fuente seleccionada en la impresora, no importa el texto entre paréntesis... es fijo para la  fuente.
  116.    Next
  117.  
  118.    If (ultimafila > 0) Then ' la última fila tiene 1 o más columnas, pero menos que 'numcols'.
  119.        n = margen
  120.        For i = 0 To ultimafila - 1
  121.            Printer.CurrentX = n  ' imprime el texto de la columna 'i'
  122.            Printer.Print List1.List(j + i)
  123.            n = (n + anchocol)
  124.        Next
  125.    End If
  126.  
  127.    Set Printer.Font = fuente
  128. End Sub
  129. Private Sub encabezado()
  130. Printer.Font.Name = "Courier"
  131. Printer.Font.Size = 10
  132. Printer.FontBold = True
  133.  
  134. Printer.Print Tab(5); "HORA: " & UCase(Format(Now, "hh:mm ")); Tab(80); "Fecha:"; Date
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. Printer.Font.Name = "Arial"
  143. Printer.Font.Size = 10
  144. Printer.FontBold = True
  145.  
  146. Printer.DrawWidth = 10
  147. Printer.DrawStyle = 2
  148.  
  149.  
  150.  
  151.  
  152. Printer.CurrentX = 4000
  153. Printer.CurrentY = 0
  154. Printer.Print "Listado de Almacen"
  155.  
  156.  
  157.  
  158.  
  159. Printer.CurrentY = 1000
  160. Printer.CurrentX = 200: Printer.Print "Codigo"
  161. Printer.CurrentY = 1000
  162. Printer.CurrentX = 1000: Printer.Print "Stock"
  163. Printer.CurrentY = 1000
  164. Printer.CurrentX = 2900: Printer.Print "Articulo"
  165. Printer.CurrentY = 1000
  166. Printer.CurrentX = 5000: Printer.Print "Precio"
  167. Printer.CurrentY = 1000
  168. Printer.CurrentX = 6000: Printer.Print "Impuesto"
  169. Printer.CurrentY = 1000
  170. Printer.CurrentX = 7200: Printer.Print "Uds.Caja"
  171. Printer.CurrentY = 1000
  172. Printer.CurrentX = 8300: Printer.Print "Umbral"
  173. Printer.CurrentY = 1000
  174. Printer.CurrentX = 9500: Printer.Print "Pedido"
  175. Printer.CurrentY = 1000
  176. Printer.CurrentX = 10500: Printer.Print "En Oferta"
  177.  
  178.  
  179. End Sub
  180.  
  181.  
  182.  
  183.  
  184.  


gracias




En línea

Mr.Byte

Desconectado Desconectado

Mensajes: 214



Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #1 en: 15 Julio 2024, 15:48 pm »

Si tu intención es cambiar de página después de imprimir un cierto número de líneas, necesitarías incrementar i en cada iteración de tu bucle de impresión y luego verificar si ha alcanzado el límite que deseas para el cambio de página.

Por ejemplo, podrías tener un contador que incrementas cada vez que imprimes una línea, y cuando ese contador llega a 24 (o cualquier número que represente el final de una página para tu impresora), entonces llamas a Printer.NewPage y encabezado.


En línea

corlo

Desconectado Desconectado

Mensajes: 114


Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #2 en: 15 Julio 2024, 17:46 pm »

Kola  Mr.Byte

intento hacer esto:


Código
  1.  
  2. encabezado
  3.  
  4.  
  5.    listarcolumnas
  6.  
  7.  i = i + 1
  8.   If i = 24 Then    '2
  9.  
  10.  
  11. Printer.NewPage
  12.  
  13. encabezado
  14. End If
  15.  
  16.  
  17.  
  18.  
  19.  

y me hace el listado completo
no consigo hacerlo en varias hojas
gracias

En línea

Mr.Byte

Desconectado Desconectado

Mensajes: 214



Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #3 en: 16 Julio 2024, 08:27 am »

Tendrias que resetear el contador cada vez que imprimes una pagina
Código:
encabezado
 
 
    listarcolumnas
 
  i = i + 1
   If i = 24 Then  i=0 and  '2
 
 
Printer.NewPage
 
 encabezado
End If
 
 
 
 
En línea

corlo

Desconectado Desconectado

Mensajes: 114


Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #4 en: 16 Julio 2024, 10:58 am »

estoy haciendo esto

Código
  1.  
  2.  
  3. i = 1
  4. encabezado
  5.  
  6.  
  7.    listarcolumnas
  8.  
  9.  i = i + 1
  10.   If i = 24 Then    '2
  11.  
  12.  
  13. Printer.NewPage
  14.  
  15.  i = 0
  16. encabezado
  17. End If
  18.  
  19.  
  20.  

y me esta haciendo el listado completo, no me hace por varias hojas
gracias
En línea

EdePC
Moderador Global
***
Desconectado Desconectado

Mensajes: 2.146



Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #5 en: 16 Julio 2024, 15:41 pm »

Pasa que no estás controlando la cantidad de líneas impresas para luego comprobarlo. Ya que en listarcolumnas imprimes las líneas, ahí deberías hacer la comprobación, y mejor si usas otra variable porque i ya se está utilizando para otras cosas

Por ejemplo usaré lineas y resaltaré la parte que he agregado a tu código:

Código
  1. Private Sub listarcolumnas()
  2.  Dim AnchoPapel As Integer
  3.  Dim MargenIzquierdo As Integer
  4.  Dim numCols As Integer
  5.  Dim filas As Long
  6.  Dim ultimafila As Long
  7.  Dim k As Long, j As Long, i As Integer, n As Integer, anchocol As Integer
  8.  Dim linea As String
  9.  Dim margen As Integer
  10.  Dim fuente As StdFont
  11.  Set fuente = Printer.Font
  12.  numCols = 9
  13.  Printer.FontName = "Courier New"  ' una fuente monoespaciada, si no el trabajo es más laborioso...
  14.  filas = ((List1.ListCount + 1) \ numCols)
  15.  ultimafila = ((List1.ListCount + 1) Mod numCols) ' columnas que tendrá la última fila.
  16.  anchocol = ((AnchoPapel - MargenIzquierdo) \ numCols)
  17.  
  18.  For k = 0 To filas - 1
  19.      n = margen
  20.      For i = 0 To numCols - 1
  21.          Printer.CurrentX = n  ' imprime el texto de la columna 'i'
  22.          Printer.Print List1.List(j + i)
  23.          n = (n + anchocol)
  24.      Next
  25.      j = (j + numCols)
  26.      Printer.CurrentY = (Printer.CurrentY + Printer.TextHeight("t"))  ' el textheight depende de la fuente seleccionada en la impresora, no importa el texto entre paréntesis... es fijo para la  fuente.
  27.  
  28.      lineas = lineas + 9 'Arriba se imprimieron 9 líneas
  29.      If lineas > 24 Then
  30.        Printer.NewPage
  31.        encabezado
  32.        lineas = 0
  33.      End If
  34.  Next
  35.  
  36.  If (ultimafila > 0) Then ' la última fila tiene 1 o más columnas, pero menos que 'numcols'.
  37.      n = margen
  38.      For i = 0 To ultimafila - 1
  39.          Printer.CurrentX = n  ' imprime el texto de la columna 'i'
  40.          Printer.Print List1.List(j + i)
  41.          n = (n + anchocol)
  42.      Next
  43.  End If
  44.  
  45.  Set Printer.Font = fuente
  46. End Sub

---
No es normal trabajar con coordenadas (x, y) para estos trabajos de impresión ya que requieren de buenos cálculos matemáticos y/o trabajar con prueba y error. Las coordenadas se usan más cuando el tipo y tamaño de fuente varían en la hoja a imprimir, se van a agregar elementos gráficos y se requiere moverse por toda la hoja para imprimir en diferentes lugares en cualquier orden.

- Pero si se va a trabajar con un tamaño de fuente determinado y que además es monoespaciada, es mejor crear una plantilla en un editor de texto plano como Notepad++ o similar, luego se facilita mucho la impresión de líneas usando Format y demás opciones que hay para formatear, alinear y distribuir el texto de acuerdo a la plantilla, por ejemplo esta plantilla para una hoja A4, y fuente Consolas de tamaño 10:

Citar

  HORA: 05:19:42                           LISTADO DE ALMACEN                           FECHA: 16/07/2024
  =======================================================================================================
  Código | Stock | Artículo                  | Precio | Impuesto | Uds.Caja | Umbral | Pedido | En Oferta
  -------------------------------------------------------------------------------------------------------
  A00001 |  5000 | Lapicero                  |   0.15 |     0.18 |    20.20 |    5.3 |    200 |       500

- El objetivo de esta plantilla es reconocer los tamaños y espaciados requeridos para el trabajo de impresión, luego con esto es más fácil usar Print porque ya se conocen estos detalles
- Ahí dejé libre la primera fila y las dos primeras columnas como margen
- Le puse barritas | como separador para que sea más legible pero se pueden quitar si molestan y de paso ganar más espacio

Para imprimir es fácil porque me basta con escribir tal cual las líneas o datos que no varían y formatear con la cantidad de caracteres correcta para los que si varían, todo dependerá de la plantilla. Acá dejo un ejemplo por si lo quieres probar, si no entiendes algo dale click a esa instrucción y presiona F1 para que te muestra a ayuda de VB, sino siempre puedes preguntar por acá.

Código
  1. Const n = 200 'Generaré 200 registros aleatorios para el ejemplo
  2. Dim c1(n), c2(n), c3(n), c4(n), c5(n), c6(n), c7(n), c8(n), c9(n) As String
  3.  
  4. Private Sub Form_Load()
  5.  GenerarDatos 'Genera datos aleatorios para las columnas
  6.  
  7.  Printer.Font.Name = "Consolas"
  8.  Printer.Font.Size = 10
  9.  
  10.  Encabezado
  11.  ListarColumnas
  12.  
  13.  Printer.EndDoc
  14. End Sub
  15.  
  16. Sub Encabezado()
  17.  Printer.FontBold = True
  18.  Printer.Print 'Imprime una línea vacía
  19.  Printer.Print "  HORA: "; Time; Spc(27); "LISTADO DE ALMACEN"; Spc(27); "FECHA: "; Date
  20.  Printer.Print "  "; String(104, "=")
  21.  Printer.Print "  Código | Stock | Artículo"; Spc(19); "| Precio | Impuesto | Uds.Caja | Umbral | Pedido | En Oferta"
  22.  Printer.Print "  "; String(104, "-")
  23.  Printer.FontBold = False
  24. End Sub
  25.  
  26. Sub ListarColumnas()
  27.  lineas = 0
  28.  For i = 0 To n
  29.    Printer.Print "  "; c1(i);
  30.    Printer.Print " | "; Format(c2(i), "@@@@@");
  31.    Printer.Print " | "; Format(c3(i), "!@@@@@@@@@@@@@@@@@@@@@@@@@@");
  32.    Printer.Print " | "; Format(c4(i), "@@@@@@");
  33.    Printer.Print " | "; Format(c5(i), "@@@@@@@@");
  34.    Printer.Print " | "; Format(c6(i), "@@@@@@@@");
  35.    Printer.Print " | "; Format(c7(i), "@@@@@@");
  36.    Printer.Print " | "; Format(c8(i), "@@@@@@");
  37.    Printer.Print " | "; Format(c9(i), "@@@@@@@@@")
  38.    lineas = lineas + 1 'Arriba se imprimió 1 línea
  39.  
  40.    If lineas > 64 Then
  41.      Printer.NewPage
  42.      Encabezado
  43.      lineas = 0
  44.    End If
  45.  Next
  46. End Sub
  47.  
  48. Sub GenerarDatos()
  49.  For i = 0 To n
  50.    c1(i) = (Format(i, "A00000"))
  51.    c2(i) = Int((10000 * Rnd))
  52.    c3(i) = String(25 * Rnd + 1, "x")
  53.    c4(i) = Format(998 * Rnd + 1, "0.00")
  54.    c5(i) = 0.18
  55.    c6(i) = Int((1000 * Rnd))
  56.    c7(i) = Int((1000 * Rnd))
  57.    c8(i) = Int((1000 * Rnd))
  58.    c9(i) = Int((1000 * Rnd))
  59.  Next
  60. End Sub

El resultado es:
https://mega.nz/file/spwmUZxI#qa8RkqNKuR_hxj3LyfIhnPBSxkcQyggQnEfEZjWthAY

Acá dejo el Proyecto por si lo quieres descargar:
https://mega.nz/folder/wpx0hJQJ#TUpjfKk3hEqtKilP4fcE3g
« Última modificación: 16 Julio 2024, 15:54 pm por EdePC » En línea

corlo

Desconectado Desconectado

Mensajes: 114


Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #6 en: 17 Julio 2024, 13:27 pm »

Hola
He podido hacer esto

Código
  1.  
  2. lineas = lineas + i
  3.         If lineas > 24 Then
  4.      Printer.NewPage
  5.      encabezado
  6.      lineas = 0
  7.    End If
  8.  
  9.  


ahora la primera hoja sale bien pero la segunda hoja  a la hora de imprimir sale lo siguiente:



HORA: 13:18                            Listado de Almacen                  Fecha:17/07/2024


Codigo Stock         Articulo         Precio   Impuesto  Uds.Caja  Umbral    Pedido  En Oferta 28 |
 115 |Pizza romana   |  2,200 | 21,00 % |  440 | 20 % |  24 |Falso
30 |  97 |Pizza margarita  |  2,200 | 21,00 % |  440 | 20 % |  20 |Falso
32 | 213 |Galletas tostadas  |  0,800 | 10,00 % |  800 | 10 % |  22 |Falso
33 |  29 |Vinagre de vino 1l |  0,450 | 10,00 % |   1 | 10 % |  8 |Falso
35 |  30 |a       |  2,600 | 21,00 % |   1 | 20 % |  6 |Falso
36 |  30 |b       |  2,800 | 21,00 % |   1 | 20 % |  6 |Falso
37 |  30 |c       |  1,500 | 21,00 % |   1 | 20 % |  6 |Falso


no se donde esta el error

gracias


En línea

corlo

Desconectado Desconectado

Mensajes: 114


Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #7 en: 18 Julio 2024, 00:01 am »

Hoka
ya lo he solucionado
he cambiado el encabezado y todo ok

Código
  1.  
  2.  Private Sub listarcolumnas()
  3.      Dim AnchoPapel As Integer
  4.      Dim MargenIzquierdo As Integer
  5.      Dim numCols As Integer
  6.      Dim filas As Long
  7.      Dim ultimafila As Long
  8.      Dim k As Long, j As Long, i As Integer, n As Integer, anchocol As Integer
  9.      Dim linea As String
  10.      Dim margen As Integer
  11.      Dim fuente As StdFont
  12.      Set fuente = Printer.Font
  13.      numCols = 9
  14.      Printer.FontName = "Courier New"  ' una fuente monoespaciada, si no el trabajo es más laborioso...
  15.      filas = ((List1.ListCount + 1) \ numCols)
  16.      ultimafila = ((List1.ListCount + 1) Mod numCols) ' columnas que tendrá la última fila.
  17.      anchocol = ((AnchoPapel - MargenIzquierdo) \ numCols)
  18.     lineas = 0
  19.      For k = 0 To filas - 1
  20.          n = margen
  21.          For i = 0 To numCols - 1
  22.              Printer.CurrentX = n  ' imprime el texto de la columna 'i'
  23.              Printer.Print List1.List(j + i)
  24.              n = (n + anchocol)
  25.          Next
  26.          j = (j + numCols)
  27.          Printer.CurrentY = (Printer.CurrentY + Printer.TextHeight("t"))  ' el textheight depende de la fuente seleccionada en la impresora, no importa el texto entre paréntesis... es fijo para la  fuente.
  28.     lineas = lineas + i
  29.         If lineas > 24 Then
  30.      Printer.NewPage
  31.       Encabezado
  32.       lineas = 0
  33.    End If
  34.  
  35.      Next
  36.  
  37.      If (ultimafila > 0) Then ' la última fila tiene 1 o más columnas, pero menos que 'numcols'.
  38.          n = margen
  39.          For i = 0 To ultimafila - 1
  40.              Printer.CurrentX = n  ' imprime el texto de la columna 'i'
  41.              Printer.Print List1.List(j + i)
  42.              n = (n + anchocol)
  43.  
  44.     Next i
  45.     End If
  46.      Set Printer.Font = fuente
  47.    End Sub
  48.  
  49. Sub Encabezado()
  50.  Printer.FontBold = True
  51.  Printer.Print 'Imprime una línea vacía
  52.  Printer.Print "  HORA: "; Time; Spc(27); "LISTADO DE ALMACEN"; Spc(20); "FECHA: "; Date
  53.  Printer.Print "  "; String(104, "=")
  54.  Printer.Print "  Código | Stock | Artículo"; Spc(10); "| Precio | Impuesto | Uds.Caja | Umbral | Pedido | En Oferta"
  55.  Printer.Print "  "; String(104, "-")
  56.  Printer.FontBold = False
  57. End Sub
  58.  
  59.  
  60.  
  61.  


tema resuelto
muchas gracias

En línea

Danielㅤ


Conectado Conectado

Mensajes: 1.779


🔵🔵🔵🔵🔵🔵🔵


Ver Perfil
Re: problema en i,primir varias hojas
« Respuesta #8 en: 18 Julio 2024, 01:01 am »

Hola compañeros!

corlo me alegro que hayas solucionado el problema y gracias por dejar el código correcto del cuál, fue la solución.


Saludos
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Creacion de hojas css
Diseño Gráfico
pARANOID 2 2,433 Último mensaje 4 Junio 2004, 03:07 am
por Azielito
Rango de hojas excel
Software
1mpuls0 4 3,485 Último mensaje 23 Abril 2011, 05:32 am
por 1mpuls0
Hojas estilo css
Desarrollo Web
Finlay76 0 1,420 Último mensaje 1 Octubre 2012, 23:38 pm
por Finlay76
Ordenar hojas al imprimir
Programación General
CeLaYa 0 1,643 Último mensaje 19 Octubre 2014, 22:43 pm
por CeLaYa
imrimir varias hojas con numero de pagina
Programación Visual Basic
corlo 0 1,454 Último mensaje 24 Noviembre 2022, 16:16 pm
por corlo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines