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       Download the code (2KB)

  GEEK I have an Active Server Page with an input text box and a couple of command buttons that are ActiveX controls. The page takes user input and passes some values as parameters in a QueryString when the user clicks on the appropriate command button. In the onClick event of the control, the parameter values are assigned and the application navigates to the next page with the QueryString. No form method has been set.
      The problem is, if the Enter key is pressed, values get appended to the QueryString. Each time Enter is pressed, more values get appended to the QueryString. When the page finally gets submitted to its target page, a SQL error results from the incorrect number of parameters. How can I correct this?

GEEK
The fact that this is an ASP page is immaterial, since it sounds like the problem is occurring on the client. By the time this error is generated, all of the server scripting has been completed. Even the fact that you are using QueryString on the server to extract the values isn’t an issue, since by the time you get back to the server to process the fetch, the damage has already been done.
      It sounds like the problem is that the URL you are constructing on the client is getting formed incorrectly. Without seeing your code, I really can’t advise you on how to correct it. I’d recommend that instead of doing something like
 location.href = newURL
(or however it is that you are performing the "and the application navigates to the next page" functionality), you do
 alert (newURL) 
which will allow you to easily see the URL you are trying to go to. I expect you will see something like
 http://server/path/page.asp?param=value1&param=value2&param=value3
which would indicate that you are continually appending information to the constructed URL, as opposed to simply updating internal variables that you would then use to better control the construction of the final URL reference.
      There are a couple of ways you could do this, depending on how your page is laid out. Where your code currently does something every time the user presses Enter, you could update the appropriate values in some variables on your page. It might be easier to keep track of what QueryString values you want to use in <form> elements, and then extract the values from those form elements and construct the URL in one fell swoop when it finally is time to fetch the data.

GEEK I have an HTML form with two checkboxes that can be checked in any combination. Once the form is submitted to an Active Server Page, I want to perform certain actions depending on the state of each box (as determined through Request.QueryString). I understand that if the checkbox is unchecked, no data is passed to the ASP page, so I have written my VBScript code with that in mind. The problem is that I cannot get the value of the checkbox when it is passed in the string. I see in the URL

 http://file.asp?chkbox1=on&chkbox2=on
but I can’t capture these values in Boolean variables to use in my code. What’s the problem?
GEEK
Since the value of a checkbox is the string "on" if it is checked, then you just need to do string comparisons to set the Boolean value. The most simplistic approach would be
 <%chkbox1 = request.querystring("chkbox1")=="on"%> 
which would set a local Boolean value to reflect the status of the checkbox. Figure 1 is a sample page that illustrates this.

GEEK How can my application determine if it is supposed to use wide characters when saving text files and displaying text? What aspects of my application need to concern themselves with the differences between the character sets? What happens when a program that uses only ANSI/SBCS characters is run on a Far East version of Windows that uses DBCS? Are there any technical differences between the terms "wide characters" and DBCS or between "ANSI characters" and SBCS?
GEEK How your application should deal with Unicode or DBCS depends a lot on what you need to do and what other applications you might need to interface with. If your application is creating or storing its own proprietary document files, and if you don't need to store anything other than ASCII text, then there isn't really anything you need to do.
      If your application needs to read in data files created by other applications, or if you want users to be able to enter text that might extend beyond the ASCII character set, then you will need to take the appropriate steps to handle this. A very good source of information for understanding software internationalization is Developing International Software for Windows 95 and Windows NT, by Nadine Kano (Microsoft Press, 1995).

GEEK I copied the code in Figure 2 directly from the wave effect wizard on the Microsoft Web site. Why doesn't it work? One error I found is that phaseme is not defined again in phaseit. Once I added that in, I didn't get the script error, but the text is not animated as it is on the wizard.
GEEK I believe the page you are talking about is: http://msdn.microsoft.com/psdk/inetsdk/samples/dhtml
/wavewizard/wavewzrd.htm
      The code didn't animate because there was a little sleight of hand going on. The animation in the display pane wasn't really coming from the code that was put into that pane. Instead, it was coming from the outer window, and the HTML code they created and put into both the code window (using the .innerText property) and the display window (using the .innerHTML property) is actually incorrect for implementing the illustrated feature (the wave effect).
      The main problem with the code in Figure 2 is that there isn't anything there that will repeatedly invoke the phaseit function, which is necessary to perform an animation. The function is called only once during the onload event. Instead of simply doing a

 phaseit();
this code should have done something like
 window.setInterval ("phaseit()", 100);
which would have caused the phaseit function to be called repeatedly.
      Of course, the animated waving of text is obnoxious and should be avoided except in situations where it truly adds value to the displayed page. And even then, you should allow the user to turn off the animation before they succumb to motion sickness. Figure 3 shows an updated version of this sample that allows the user to view animated text waving or turn it off. Example Online!

GEEK How can I reduce the number of colors in an image that I paste into Microsoft Image Composer 1.5? I want to create an image that can load quickly in any browser.
GEEK Image Composer supports custom palettes. Just open the Color Picker window, switch to the Custom Palette tab, and select New to build your own color palette that you can then apply to the image.
      Let's say you have a JPEG image that you want to convert to a 16-color GIF. Load the image into Image Composer and make sure it's the current selection. Open the Color Picker window and then the Custom Palette tab. Click on New. Specify My Palette as the name, and select the options 16 colors and Error Diffusion. Click OK, then click on Generate Colors and specify 16 colors and Generate from Selection. Click OK. In the Color Picker window, click OK. Now, with the image still selected, select File | Save Selection As. Set the format to CompuServe GIF, and set the palette to My Palette. After specifying a file name, click on Save.
      The resulting image will be a GIF with 16 colors, optimized for the colors in the original JPEG image. Of course, these colors are probably not optimized for the safety palette (the set of 216 colors that will prevent dithering of GIF images on Web pages). Achieving both a 16-color reduction and safety palette reduction takes a little more care and manipulation, and is often achieved by the designer and her image tools.


From the September 1998 issue of Microsoft Interactive Developer.