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!

help with code

Status
Not open for further replies.

compcad

Programmer
Mar 22, 2002
52
0
0
US
i have 2 textboxs the first one is captioned FROM: the second is captioned
TO: i want to enter values into these textboxs. and print out the results
such as FROM: 100 TO: 135 and then have the results print out four per
sheet of paper such as result 100-104, 105-109, 110-114, 115-119, 120-124,
125-129, 130-134, 135 on a seperate sheet of paper. here is the code i am
working with. right now it will print pages as such: first page will be ok
it will print 100-104, the second page will print a page with only a line
down the right the third and following pages will print as such 105 and
then a linedown the rest of the page, 106 and then a linedown the rest of
the page, so forth up to page 133 and the no line down the right. here is
my code.


Dim a As Integer
Dim X As Integer
Dim Y As Integer
Dim nIndex
Dim tickets
Dim pages
Dim z
Dim O
Dim kSingles
Dim nLong As String
Dim mLong As String
'SQL statements to access the
'database.
z = txtValue
O = Text2
If z = "" Then
MsgBox "ENTER a value in the textbox.", vbExclamation + vbOKOnly, "Please
try agian"
GoTo annuleren
ElseIf z < 1 Or z > 1000 Then
MsgBox &quot;ENTER a value in the textbox.&quot;, vbExclamation + vbOKOnly, &quot;Please
try agian&quot;
GoTo annuleren
ElseIf O < 1 Or O > 1000 Then
MsgBox &quot;ENTER a value in the textbox.&quot;, vbExclamation + vbOKOnly, &quot;Please
try agian&quot;
GoTo annuleren
End If
Select Case z
Case 1 To 4000
If txtTickets = txtTickets Then
tickets = txtTickets
pages = tickets / 4
End If
End Select
'Activates the single page printing.
a = 200
For kSingles = z To O

For nIndex = kSingles To tickets Step pages
Printer.Print
Printer.PaintPicture picAddress, 7600, a + 500, 4000, 2500
Y = Printer.CurrentY
Printer.Line (7222, 15500)-(7222, 25)
Printer.Line (7223, 15500)-(7223, 25)
Printer.CurrentX = Y
Printer.ForeColor = QBColor(15)
Printer.Print Format$(nIndex, &quot;0000&quot;)
Data1.RecordSource = number1 'Charity
Data1.Refresh
Printer.CurrentX = 300
Printer.CurrentY = a
Printer.ForeColor = QBColor(0)
Printer.Font.Size = 11
Printer.Print &quot;&quot;
Printer.Font.Name = &quot;arial&quot;
Printer.Font.Size = 17
Printer.CurrentX = (6900 \ 1 - Printer.TextWidth(txtText)) \ 2
Printer.Print txtText
Printer.Font.Size = 5
Printer.Print &quot;&quot;
Printer.Font.Size = 10
Printer.Print Tab(35); &quot;presents&quot;
Printer.Font.Size = 5
Printer.Print &quot;&quot;
Printer.Font.Size = 13
Data1.RecordSource = number1 'ShortDescription
Data1.Refresh
Printer.CurrentX = (6900 \ 1 - Printer.TextWidth(txtText1)) \ 2
Printer.Print txtText1
Printer.Font.Size = 8
Data1.RecordSource = number1 'LongDescription
Data1.Refresh
nLong = Mid(txtText2, 1, 95)
mLong = Mid(txtText2, 96)
Printer.Print Tab(6); nLong
Printer.Print Tab(6); mLong
Printer.Font.Size = 5
Printer.Print &quot;&quot;
Printer.Font.Size = 12
Data1.RecordSource = Prize 'PrizeName line.
Data1.Refresh
Printer.Print Tab(14); &quot;1st Prize:&quot;; Tab(25); txtText3
Printer.Font.Size = 5
Printer.Print &quot;&quot;
Printer.Font.Size = 12
Data1.RecordSource = Prize 'MarketValue line.
Data1.Refresh
Printer.Print Tab(6); &quot;Value:&quot;; Tab(14); Format$(txtText6, &quot;$##,###.00&quot;);
Data1.RecordSource = number1
Data1.Refresh
Printer.Print Tab(39); &quot;Drawing:&quot;; Tab(49); txtText4
Printer.Font.Size = 5
Printer.Print &quot;&quot;
Printer.Font.Size = 12
Data1.RecordSource = number1 'TimePlace
Data1.Refresh
Printer.CurrentX = (6900 \ 1 - Printer.TextWidth(txtText5)) \ 2
Printer.Print txtText5
Printer.Font.Size = 5
Printer.Print &quot;&quot;
Printer.Font.Size = 10
Printer.Print Tab(3); Format$(txtTool, &quot;$##,###.00&quot;); ; Tab(62);
Format$(nIndex, &quot;0000&quot;) & &quot; of &quot; & Format$(tickets, &quot;0000&quot;); Tab(85);
Format$(txtTool, &quot;$##,###.00&quot;); Tab(120); Format$(nIndex, &quot;0000&quot;)
Printer.Print
a = a + 3800
Next nIndex
Next kSingles
Printer.NewPage
End
End
annuleren:
Form1.Show

thank you
stephen mentzer
compcad@aol.com
 
pages is currently not declared as a type of variant. In the line pages = tickets / 4, if tickets does not equal a value divisible exactly by 4, then a non-integer is return which will cause you problems when you use the step pages command.

Make sure you round up pages to the next int, and declare this variant as an integer.

BB
 
ps 120-124 is 5 per sheet. 120,121,122,123,124

Sorry, but I thought I'd mention it.

BB
 
can you explain to me little bit more about what you are trying to get across to me. i see were you are talking about but i need it explained little bit more.

thank you
stephen mentzer
 
i just noticed that as you had posted before me i do need every 4 to be printed per sheet such as: 120-123, 124-127, 128-131, 132-135 and if it were 136 instead of 135 i would need that odd page printed i hope this makes since.

thank you
stephen mentzer
compcad@aol.com
 
All of your variables need to be declared as integers, otherwise you will get into the situation where you are trying to print x pages, where x=3/4.

Everytime you step, this need to be across 4 records. Therefore the value of 'pages' needs to be an exact integer, because you cannot print a part of a page.

Next, why do you use the code 'step page'. Page is the total number of pages to print, where as this value should be the number of tickets to the page.

eg For nIndex = kSingles To tickets Step 4

and finally, why do you use this code:

Select Case z
Case 1 To 4000
If txtTickets = txtTickets Then
tickets = txtTickets
pages = tickets / 4
End If
End Select

What does this do? Surely as you have already discarded all values of z when it is below 0 and above 1000, both the select case and if statements will always be true?

BB
 
do you think that i could get what i want if i were to get rid of some of the code you are talking about in the above post and replacing it maybe with just nIndex = Z to O if so how would i do it.

z=from=text1
o=to=text2

i have tried it and it does not seem to work.

when a=200 is outside the for next loop it does not work it prints a blank page. if it is located in the same loop as a=a+3800 it still does not work.

thank you
stephen mentzer
compcad@aol.com
 
I'm not sure want exactly some of your routines do. For example, I don't know why you have include the 'select case z' statement. Also, the first validation section, where you want to test that the user input is between 0 and 1000, could be simplified, to find out if the input is numeric. This way, when your software is a great success, and you have a record of 100000 tickets, you don't need to alter anything.

Try the following

Dim a As Integer, X As Integer, Y As Integer
Dim nIndex
Dim tickets
Dim pages as Integer
Dim z
Dim O
Dim kSingles
Dim nLong As String, mLong As String

'SQL statements to access the
'database.
z = txtValue
O = Text2

If isnumeric(z) = False then
MsgBox &quot;ENTER a value in the textbox.&quot;, vbExclamation + vbOKOnly, &quot;Please
try agian&quot;
text1.setfocus 'set the focus back to incorrect value.
GoTo annuleren

ElseIf isnumeric(O) = False then
MsgBox &quot;ENTER a value in the textbox.&quot;, vbExclamation + vbOKOnly, &quot;Please
try agian&quot;
text2.setfocus 'set the focus back to incorrect value.
GoTo annuleren

End If

If txtTickets = txtTickets Then 'This equation will always be true, as txtTickets is txtTickets
tickets = txtTickets
pages = tickets / 4
End If

Also, your printer.newpage command comes after all of your next loops have finished. Should this be inside a loop, when the number of tickets printed reaches the maximum for the page.

BB
 
i think i found the problem it might be dealing with the:

a=200

and

a=a+3800

i need to use this counter

a=200 needs to be in its own loop and a=a+3800 needs to be in a nested loop here is a sample of the code that i know works

For X = 1 To pages
a = 200
For nIndex = X To tickets Step pages
Printer.Print
'Prints the Address form on the
'ticket.
Printer.PaintPicture picAddress, 7600, a + 500, 4000, 2500
'Prints a line down the right side.
Y = Printer.CurrentY
Printer.Line (7222, 15500)-(7222, 25)
Printer.Line (7223, 15500)-(7223, 25)
Printer.CurrentX = Y
Printer.ForeColor = QBColor(15)
Printer.Print Format$(nIndex, &quot;0000&quot;)
Data1.RecordSource = number1 'Charity
Data1.Refresh
Printer.CurrentX = 300
Printer.CurrentY = a
Printer.ForeColor = QBColor(0)
Printer.Font.Size = 11
.
.
.
Printer.Print &quot;&quot;
Printer.Font.Size = 10
Printer.Print Tab(3); Format$(txtTool, &quot;$##,###.00&quot;); Tab(62); Format$(nIndex, &quot;0000&quot;) & &quot; of &quot; & Format$(tickets, &quot;0000&quot;); Tab(85); Format$(txtTool, &quot;$##,###.00&quot;); Tab(120); Format$(nIndex, &quot;0000&quot;)
Printer.Print
a = a + 3800
Next nIndex
Next X
Printer.NewPage
End
End
annuleren:
Form1.Show
End Sub

and this is what i tried and am having problems with


a = 200
For nIndex = z To O
'For kSingles = z To O
'For nIndex = kSingles To tickets Step pages
Printer.Print
Printer.PaintPicture picAddress, 7600, a + 500, 4000, 2500
Y = Printer.CurrentY
Printer.Line (7222, 15500)-(7222, 25)
Printer.Line (7223, 15500)-(7223, 25)
Printer.CurrentY = Y
Printer.ForeColor = QBColor(15)
Printer.Print Format$(nIndex, &quot;0000&quot;)
Data1.RecordSource = number1 'Charity
Data1.Refresh
Printer.CurrentX = 300
Printer.CurrentY = a
Printer.ForeColor = QBColor(0)
Printer.Font.Size = 11
Printer.Print &quot;&quot;

if you understand and have some ideas
thank you
stephen mentzer
compcad@aol.com

would you like to see a sample of how it should look when printed and a sample of what it looks like with the errors
 
i tried creating a sample program of the code i am using above and i had taken out a=200 and a=a+3800 and then created a single for next loop such as: nIndex=z to o and i tried to print and it works the way i want it to except some of the information is not included in the printout such as the divider line and the graphic i need to use a=200, a=a+3800 in my code to get that information to print as it is suppose to print.

i hope you understand and can help me.
THANK YOU VERY MUCH FOR THE HELP SO FAR
STEPHEN MENTZER
COMPCAD@AOL.COM
 
if you want ask a question on this subject again, you merely have to post a new post within your last thread.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top