ayuda urgente

Alex
01 de Agosto del 2003
hola quiero apelar a la buena voluntad de Uds. y ver si me pueden ayudar... Soy un completo principiante y tengo el siguiente problema

tengo dos Text Box y un Command Button
TxtInicial y Txtfinal y cmdPrint


debo ingresar un N° Inicial y un N° Final
pero que me respete cualquier N° como inicial y final

y el cmdPrint debe imprimir a la impresora con el papel en forma horizontal de la siguiente manera:

ejemplo y codigo:
Imprimir desde el 1 al 2500
en la Primera fila debe imprimir del 1 al 1250
en la segunda fila del 1251 al 2500
CON INTERVALOS DE 5 EN CINCO

N° 000005 N° 000004 N° 000003 N° 000002 N° 000001



N° 001255 N° 001254 N° 001253 N° 001252 N° 001251

LA SIGUIENTE HOJA DEBE IMPRIMIR EL CORRELETIVO

N° 000010 N° 000009 N° 000008 N° 000007 N° 000006



N° 001260 N° 001259 N° 001258 N° 001257 N° 001256

Y ASI SUCESIVAMENTE HASTA COMPLETAR LA SECUENCIA

YO TENGO EL CODIGO ASI PERO NO ME RESPETA EL INICIAL NI EL FINAL, ADEMAS ME IMPRIME LA HOJA EN FORMA VERTICAL
Y COMO SI FUERA POCO NO ME IMPRIME LA SEGUNDA LINEA
Y SE DETIENE....


Private Sub CmdPrint_Click()
Dim i As Long
Dim j As Long
Dim Div As Long
Dim Str As String
If IsNumeric(TxtInicial) And IsNumeric(Txtfinal) Then
If CLng(TxtInicial) < (Txtfinal) Then
Open "LPT1" For Output As #1
For i = TxtInicial To (Txtfinal / 2)
If Div <= 5 Then
Str = Str + "N" & Chr(167) & " " & Format(i, "000000") & " "
Div = Div + 1
Else
Print #1, Str
Div = 1
Str = ""
End If
Next
Print #1, Str
Print #1, Chr(12)
Div = 1
Str = ""
For i = ((Textfinal - (Textfinal / 2)) + 1) To Textfinal
If Div <= 5 Then
Str = Str + "N" & Chr(167) & " " & Format(i, "000000") & " "
Div = Div + 1
Else
Print #1, Str
Div = 1
Str = ""
End If
Next
Print #1, Str
Close #1
Else
MsgBox "El Folio Inicial Debe ser Menor que el Folio Final", , "ERROR EN FOLIO INICIAL"
End If
Else
MsgBox "Estos Campos Admiten Solo Valores Numericos", , "ERROR EN FOLIOS"
End If


End Sub
LES RUEGO RESPONDER A MI CORREO Y A ESTA PAGINA
POR CUAQUIER PROBLEMA QUE PUEDA TENER MI CORREO



Juan
01 de Agosto del 2003
He revisado el código y he cambiado algunas lineas, no se
si el resultado es el que esperabas pero se parece bastante.

Las lineas modificadas estan marcadas con un comentario
y he cambiado la salida hacia un archivo de texto para no
usar papel con pruebecitas.
Aqui tienes el código:

Private Sub CmdPrint_Click()
Dim i As Long
Dim j As Long
Dim Div As Long
Dim Str As String
If IsNumeric(txtInicial) And IsNumeric(txtFinal) Then
If CLng(txtInicial) < (txtFinal) Then
'Open "LPT1" For Output As #1
Open "c:prueba.txt" For Output As #1
For i = txtInicial To (txtFinal / 2)
If Div < 5 Then 'modificada
Str = Str + "N" & Chr(167) & " " & Format(i, "000000") & " "
Div = Div + 1
Else
Print #1, Str
Div = 1
Str = "N" & Chr(167) & " " & Format(i, "000000") & " " 'modificada
End If
Next i
Print #1, Str
Print #1, Chr(13)
Div = 0 'modificada
Str = ""
For i = ((txtFinal / 2) + 1) To txtFinal 'modificada
If Div < 5 Then 'modificada
Str = Str + "N" & Chr(167) & " " & Format(i, "000000") & " "
Div = Div + 1
Else
Print #1, Str
Div = 1
Str = "N" & Chr(167) & " " & Format(i, "000000") & " " 'modificada
End If
Next i
Print #1, Str
Close #1
Else
MsgBox "El Folio Inicial Debe ser Menor que el Folio Final", , "ERROR EN FOLIO INICIAL"
End If
Else
MsgBox "Estos Campos Admiten Solo Valores Numericos", , "ERROR EN FOLIOS"
End If
End Sub

Huy se me olvidaba, para imprimir horizontal tienes que ejecutar esto:

printer.Orientation = vbPRORLandscape

Juan
01 de Agosto del 2003
Perdona pero no estaba bien del todo, al código que te he dado antes
cambiale las lineas de los for por estas dos:

For i = txtInicial To (Val(txtFinal) + Val(txtInicial)) / 2
For i = (((Val(txtFinal) + Val(txtInicial)) / 2) + 1) To txtFinal

Para acabar unos consejillos:
1. No omitas la propiedad Text de los campos de texto aunque
sea la predeterminada, escribe txtFinal.Text y no sólo txtFinal.
2. No utilices cadenas de texto para hacer operaciones matemáticas
o VB tendrá que conversiones en cada operación,
en este código deberías haber incluido dos variables de tipo long
p.ej.: numInicial y numFinal y haberlas utilizado para almacenar
el valor de los campos de texto.