This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.


MIND

GEEK

Robert Hess

GEEK Is there any way to print a Web page without clipping the text on long lines?
GEEK I assume that you have developed a Web page where, when you print the page out, the rendered width of the page appears to be larger than the printable area of the paper and long lines of text get chopped off.
      This same situation can occur when pages are viewed in a browser. Text that is too wide would be cut off on the sides, except the browser provides a scrollbar that lets the reader scroll back and forth to see all of the text. Unfortunately, until the new "electronic paper" stuff becomes readily available, there isn't any way to provide scrolling on a paper printout.
      Basically, the page you have designed is wider than the paper on which you want to output it. When a Web page is printed out, it is essentially rerendered to a surface the width of the printable area of the paper and isn't associated directly with the current width of the screen at all. Just because the page fits on the screen doesn't mean it is going to fit onto the paper. Usually, this problem is due to fixed-width tables or graphical elements on the page that are forcing a minimum size at which the page can be rendered without also displaying scroll bars on the window.
      There are two ways around this problem. You can either design your pages to be sizable to a narrower width that will allow proper printing, or you can print out the pages in landscape mode instead of portrait mode.
      Eventually Cascading Style Sheets (CSS) will allow Web page designers to embed printer switching options, such as landscape and portrait, directly into the Web page itself. That feature hasn't been added yet, so at the moment there isn't any way for the author to force the printer into landscape mode—only the user can do that.

GEEK I'm a student working on my thesis. I would like to use Visual Basic® to develop an electronic interface for a device that communicates via the printer port. How do I manipulate the outgoing individual bits of data? Could you recommend code samples that do what I've just described?
GEEK If you are going to be interfacing with some sort of device on a port connected to your computer, I recommend that you attach it to the serial (or COM port), not the parallel (or printer) port. The serial port provides much greater I/O flexibility, and is specifically designed for read/write operations to external devices. The parallel port, on the other hand, is primarily a write-only device, designed for high-speed output to a printing device. Incoming information is limited to monitoring status pins on the port for device status information. While it is possible for you to do I/O via the printer port, that is not its normal mode of operation.
      The Win32® API is generally designed to virtualize the functionality of these ports, not requiring the programmer to be concerned with the raw information that is being transmitted across the cables. That sort of control is best left up to device drivers, which know what form the devices expect data to be transmitted in.
      If you have a custom device attached to a communication port on the computer, and you want to have a program perform I/O operations with this external device, you are technically better off writing a device driver that interacts with the port and device at a very low level—a lower level of access than I expect you can easily achieve via Visual Basic. You're probably looking at C, C++, or even assembler project.
      However, there are some options available to you if you need to perform relatively simple access. Here is a link to an MSDN Online article that outlines some of what you need to do to access a COM port via the Win32 API: http://msdn.microsoft.com/library/techart/msdn_serial.htm. This will be a little trickier to do using Visual Basic, but it won't be absolutely impossible. Enough information should be provided on this page to get you started.

GEEK I'm learning about letting visitors customize Web sites using cookies (for user and preference detection). What if the visitor has cookies disabled at the client side? In this case the entire site's content would be messed up. Is there any way of detecting whether cookies are enabled? Besides using cookies, what other techniques are suitable for automated user/client detection?
GEEK To detect whether the client browser has cookies enabled, you just need to ask it for the value of a cookie that you previously set. While this might seem sort of like a chicken and egg situation, it isn't that difficult; it only means that any browser with cookies disabled has to visit at least two pages on your site before you can know whether it's a new user or an old user that doesn't accept cookies.
      Assume, for instance, that you only want to maintain the user's selection of a page background color throughout your site. Your Active Server Page (ASP) code for each page might look something like this:


 <%bgcolor = Request.Cookies("bgcolor")%>
 <html>
 <body bgcolor=<%=bgcolor%>>
 test
 </body>
 </html>
If the user has cookies enabled and the value for this cookie had been previously set to indicate a preference, then your page will be able to appropriately extract this value and assign the proper color value.
      However, the value of bgcolor might not be available because either the session belongs to a new user who never specified a color preference, or the user does not have cookies enabled on his system. Your page code simply needs to be prepared to check for these possibilities.
      But getting back to your scenario, providing the capability for the user to customize their view of your pages is a lot easier to deal with than other cookie concepts might be. The best solution would be to store a unique user account number in the cookie on the client side, then look up this user number in a database on your server to determine the settings that the user might have indicated in a previous visit to your site. Your code might look something like:

 <%
     userid = Request.Cookies("userid")
     if len(userid) > 0 then
         ' insert code here to extract user settings from database
     else
         userid = "000000"
         Response.Cookies("userid") = userid
         ' insert code here to assign "default" user settings
     end if
 %>
      On all subsequent pages, if you see a userid of "000000" then you know that the user just hasn't created an account yet. But if there isn't a value set for userid, then you know that the user does not have cookies enabled in his browser. How you choose to handle these two situations is completely up to you.
      If you want to create a site solution that can use cookies when they are available, but can also provide the same level of user customization when cookies aren't available, you will need to rely on some form of server-side management of user identification. Since, by design, Web pages are supposed to be free from any state information of this nature, there is no direct method for providing this capability built into the HTTP data transfer process. Each individual page is intended to live all by itself. However, various techniques have been devised to get around this.
      The easiest technique would be to mangle the URL with which the user accesses the site and embed a unique userid into the URL itself by appending it to the end of the address, as I did in this URL: http://www.genericserver.com/somepage.asp?userid=123456.
      If all the links on the page are coded to automatically embed the userid in this fashion, then you have a trackable userid throughout your site.

From the January 2000 issue of Microsoft Internet Developer.