Try saving Printer.Printers to a file where you can load the file into an editor and look at the names carefully.
The next thing is to look at how you are saving the printer name. I assume you are using an INI file. IndexOf will only return an index on an exact match. So if there are trailing spaces in one but not the other, it is no match, even though they look identical. Glenn Lawler www.incodesystems.com -----Original Message----- From: Nesler, Thomas J [SMTP:[EMAIL PROTECTED] Sent: Monday, August 25, 2008 4:03 PM To: delphi-en@yahoogroups.com Subject: RE: [delphi-en] Re: Printing Barcodes(2) Do you think there are some unviewable characters in the name? I did what you suggested and the Listbox line looks the same as my Lblprinter variable. Here is how I load the listbox: For I := 0 to Printer.printers.Count -1 do LBxPrinters.Items.Add(Printer.printers[I]); I am wondering if it would be safer to save the Index number but my concern is that if the user adds a printer to the list then the index will be goofed up. Tom Nesler -----Original Message----- From: delphi-en@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Glenn B. Lawler Sent: Monday, August 25, 2008 3:47 PM To: 'delphi-en@yahoogroups.com' Subject: RE: [delphi-en] Re: Printing Barcodes(2) Tom, >While we are on the subject of printing, I am having trouble printing my >barcode to a specific network printer. I can select a printer using the >printer dialog, but I can't seem to use a stored printer name to direct >my print job to correctly. > >In my code I have a variable called LblPrinter which has the name of the >printer. I use the command: > >I := Printer.Printers.IndexOf(LblPrinter); > >If I >= 0 then Printer.PrinterIndex := I > Else Showmessage('Using default Printer'); //Index is -1 > >No matter what printer I select, I is always -1...;-( > >Any suggestions? When I use the PrinterDialog, I can see the correct >Printer index number and the Printers name, but I can't seem to find it >when I don't use the dialog. Try outputing the list from Printer.Printers to the lines of a Memo, or any other way where you can see them. I think you'll find that the name of the printer om Printer.Printers is a little different than the name that is shown in the common controls printer dialog. If you want to select the printer from a stored printer name, you need to make sure you store the name contained in Printer.Printers, not the printer dialog. This is easy to do. You can have the user select the printer from the printer dialog, but then save the name from Printer.Printers corresponding to the selected printer after they have selected it. Glenn Lawler www.incodesystems.com ------------------------------------ ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: [EMAIL PROTECTED] Groups Links ------------------------------------ ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: [EMAIL PROTECTED] Groups Links