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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit from a loop 1

Status
Not open for further replies.
Dec 17, 2006
8
CA
In order to print invoices with a maximum of 15 items I
created a random access file like follows:

file.item(1) = "Red Ink"
file.item(2) = "Blue Ink"
file.item(3) = "Green Ink" etc ( Up to 15 items )

On many invoices there are items with no entries and my
particular question is how to avoid that all 15 items show
when I print the invoice.The items with no entry show
little squares.

In other words I would like to exit the loop when
file.item(x) = "" ( no entry )

I appreciate any help.




 
The little squares represent data items which have not been written to yet and by default will probably be filled with ASCII zeroes ie. Chr$(0)

Check the item before you print it something like this;

For i = 1 to nItems
if asc(file.item(i))>31 then
Print.Printer file.item(i)
end if
Next

Asc (check vb Help) returns the ASCII code (Chr$) of the first letter in the string. In general characters with a Chr$ below 32 (including zero of course) are used as control characters and are unprintable.

HTH Hugh,

 
That should have been;

Printer.Print file.item(i)

of course but I guess you got the gist of the line above.

Thanks for the star.
 
This is how I exit a For-Next loop

For x = 1 To 15
If file.Item(x) = "" Then Exit For
Next
 
The OPs reference to little squares suggests that his empty file.Items (probably fixed length strings within a UDT variable) are not equal to "" but filled with ASCII zeroes.

Chr$(0) + Chr$(0) + ... etc. do not add up to ""

Hugh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top