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 I hacked together some subroutines that let me write multiple values to one cookie and then read them out of that cookie. How do you name cookies so you can have multiple things going on? If I have a bunch of customized pages, I don't want them all reading the same cookie. I want each page to have its own cookie, but I can't seem to get it going.

    GEEK As you've discovered, cookies aren't local to a specific page, but instead are tied to the domain/path of the page that is utilizing them. This is a good thing, since it allows for cookie values to be easily shared between pages. However, a problem arises if you want to store a value that only applies to the particular page in question.

    The easiest way to solve this would be to simply use cookie names that are unique to the page. If you want to maintain the background color for a page, then you might want to concatenate the name of the page with the name of the value you are storing, thus using something like IndexBGCOLOR to store the background color for your Index page.

    GEEK How can I turn the cursor on my Web page to an hourglass while reading data? I'm using Microsoft® Internet Information Server, Visual InterDev 6.0, DHTML, and JScript®. I've found that changing the style cursor attribute for an object doesn't take effect until after I exit the function/event in which the code is executed. It needs to have focus back on the screen to actually change shape. My function should change my cursor to an hourglass, read my data, and then change the cursor back. But the cursor never changes to an hourglass in this scenario. (I also have to change the style cursor attribute on every object on the page.)

     I've enclosed some code that actually works using the style cursor attribute (see Figure 1). It uses the window.setTimeout function to momentarily give focus back to the page. The drawback is that I have to execute two separate functions for this to work, one to set the hourglass and the setTimeout function. The setTimeout function then executes another function (with a slight delay) containing my read logic and code to set the cursor back. Retrofitting this code in my application would cause a fair amount of work, so this is not ideal.

    GEEK You are definitely on the right track here. Your best bet for setting the "wait" cursor to be displayed is through the use of the cursor style. But as you have noticed, not only does the cursor not get set until after you leave your tight code loop, but you also have to enumerate through all of your page elements and set their cursor style appropriately as well. This leads to some pretty messy code.
Fortunately, there is a way past both of these problems. The most straightforward is to create a <DIV> object that covers your entire page and has its cursor style set appropriately. Then when you want to turn on the wait cursor, you simply make this <div> visible; to turn it off, you make it invisible. Your <DIV> could be defined with:



 <div style="position:absolute;width=100%;height=100%;cursor=wait;display=none">
</div>

    There is still a problem getting the display to update within your calculation loop so that the wait cursor can actually get displayed. The browser is waiting for your script function to finish before it updates the display. Perhaps the easiest way to give the display code the time it needs is to use the window.SetTimeout method to kick off your calculation code, and then at the end of your calculation code it sets the display property of the <DIV> back to none. Figure 2 provides a very small example of how this might be accomplished.

    GEEK Given a URL, what is the best way to retrieve files from the Internet using Visual Basic®? Ideally, I'd like to load the file into a string in memory (and not have to deal with temp files). I'd like the method to work even for non-HTML files.

    I've been using a SHDocVw.InternetExplorer control that I call Internet. I can call Internet.navigate, and then on the Internet_DownloadComplete Event I check the Internet.document (and, specifically, Internet.document.body.outerHTML, which seems to have data the second time the Event is fired). This has been working well for getting HTML files, but doesn't seem to work for non-HTML documents.

    GEEK Using the InternetExplorer object to download files is sort of like using a hammer to pound in a screw. It works, sort of. This object might be doing exactly what you want it to do, but it doesn't make it easy. You really need to access a Web server directly and download the data yourself.

    Fortunately, two controls that ship with Visual Basic Professional and Enterprise editions provide this functionality. These are the Internet Transfer control and the WinSock control. Which one you use depends on exactly what you want to do. I expect you want the Internet Transfer control. It allows you to access files across the Internet via either HTTP or FTP. The WinSock control would be useful if you want to open up a two-way conversation with an application that might be running on the server. You can get more information about both of these controls at: http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbcon98/vbconusingwinsockcontrol.htm
http://msdn.microsoft.com/library/partbook/egvb6/usinginternettransfercontrolmethods.htm
Or, search for "WinSock control" or "Internet Transfer control" at http://search.microsoft.com.

    GEEK I would like to randomly generate a record from a database into a Web page. I've included the code I have so far, but it only pulls up the first record.

    GEEK The problem is in your use of MaxRecords. This is not a property that tells you how many records resulted from your query, but instead specifies the maximum number of records you want returned from your query. This is best used for managing potential low-memory conditions on the client or for speeding up processing time.
Since the value of MaxRecords in your code is the crux of your calculations, it would have been a good idea to try displaying that value so you could verify where your calculations were breaking down:



 <%
     NumOfRecords = MyRS.MaxRecords
     response.write ("MaxRecords = " & NumOfRecords & "<br>")
 %>

    This would have shown by its 0 value that perhaps you needed to use something else to obtain the necessary value.

    Perhaps the simplest way to count the number of records that would be returned from a query is to build up a query string similar to this, which will give you the number of records that would have been returned.



 <%
     SQL = "SELECT COUNT(*) FROM Historydb"
     NumOfRecords = MyRS.fields(0)
 %>
    I am not indicating which fields to extract, since at this time they won't change the count of the records to be returned. You will then need to perform your normal query, since the COUNT(*) won't actually return any record values.

    GEEK I'm working on ASP code with IIS 4.0 and Visual InterDev 6.0. I'm hoping ASP 2.0 has a way to do server-side frame targets, so I don't have to code this on the client. Is it possible to use response.redirect to redirect the target before the actual page redirect? My plan was to toggle the target as needed.

    GEEK ASP code, as you note, runs on the server, and the server has zero notion of the layout or configuration of the client-side rendering of the browser. Likewise, the HTTP protocol has no specifications for controlling/displaying information based on a named frame in the browser.

    So the only way to get something like this to work is to rely on client-side functionality, where the browser itself is handling what URL to put into which frame. Netscape Navigator has added a special meta tag that does what you want:



 <META HTTP-EQUIV="Window-target" CONTENT="frame_name">
But as far as I know, this is a nonstandard option and only supported by Navigator.

From the April 1999 issue of Microsoft Internet Developer.