<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Will_rickards's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 00:27:09 GMT</pubDate>
    <description>DZone Snippets: Will_rickards's Code Snippets</description>
    <item>
      <title>Programmatically Change a Crystal Reports datasource location</title>
      <link>http://snippets.dzone.com/posts/show/4029</link>
      <description>I had an aspx.net project where I needed to generate a pdf.&lt;br /&gt;I used crystal to do the heavy lifting of geneating the pdf for me.&lt;br /&gt;But as I needed to deploy it to multiple databases/clients I needed a way of programmatically changing the datasource location of the report.  So with a bit of help from the crystal knowledgebase here is the code I use.&lt;br /&gt;There is a lot of debugging information in here and trust me when it fails you need it.&lt;br /&gt;The .dbo of the location reference obviously means I was working with sql server.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;   ' SetupReport&lt;br /&gt;   '&lt;br /&gt;   ' Description:&lt;br /&gt;   '    sets up the crystal report&lt;br /&gt;   '&lt;br /&gt;   ' Arguments:&lt;br /&gt;   '    objCrystalReportDocument             - crystal report document object&lt;br /&gt;   '&lt;br /&gt;   ' Dependencies:&lt;br /&gt;   '    GetConnnectionInfo&lt;br /&gt;   '    CrystalDescisions&lt;br /&gt;   '&lt;br /&gt;   ' History:&lt;br /&gt;   ' 03/17/2006 - WSR : created&lt;br /&gt;   '&lt;br /&gt;   Private Function SetupReport(ByRef objCrystalReportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument) As System.Boolean&lt;br /&gt;&lt;br /&gt;      ' a heck of a lot of objects used&lt;br /&gt;      Dim crParameterDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue&lt;br /&gt;      Dim crParameterFieldDefinitions As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions&lt;br /&gt;      Dim crParameterFieldLocation As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition&lt;br /&gt;      Dim crParameterValues As CrystalDecisions.Shared.ParameterValues&lt;br /&gt;      Dim crSections As CrystalDecisions.CrystalReports.Engine.Sections&lt;br /&gt;      Dim crSection As CrystalDecisions.CrystalReports.Engine.Section&lt;br /&gt;      Dim crReportObjects As CrystalDecisions.CrystalReports.Engine.ReportObjects&lt;br /&gt;      Dim crReportObject As CrystalDecisions.CrystalReports.Engine.ReportObject&lt;br /&gt;      Dim crSubreportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument&lt;br /&gt;      Dim crSubreportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject&lt;br /&gt;      Dim crConnectionInfo As CrystalDecisions.Shared.ConnectionInfo&lt;br /&gt;      Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database&lt;br /&gt;      Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables&lt;br /&gt;      Dim aTable As CrystalDecisions.CrystalReports.Engine.Table&lt;br /&gt;      Dim bTable As CrystalDecisions.CrystalReports.Engine.Table&lt;br /&gt;      Dim crTableLogOnInfo As CrystalDecisions.Shared.TableLogOnInfo&lt;br /&gt;      Dim blnTest As System.Boolean&lt;br /&gt;      Dim strLocation As System.String&lt;br /&gt;      Dim blnErrors As System.Boolean&lt;br /&gt;&lt;br /&gt;      ' instantiate the debug page&lt;br /&gt;      m_strDebugPage = New System.Text.StringBuilder(4096)&lt;br /&gt;      blnErrors = False&lt;br /&gt;&lt;br /&gt;      crConnectionInfo = GetConnectionInfo()&lt;br /&gt;&lt;br /&gt;      crDatabase = objCrystalReportDocument.Database&lt;br /&gt;&lt;br /&gt;      crTables = crDatabase.Tables&lt;br /&gt;&lt;br /&gt;      'For intCounter = 0 To objCrystalReportDocument.Database.Tables.Count - 1&lt;br /&gt;      For Each aTable In crTables&lt;br /&gt;&lt;br /&gt;         crTableLogOnInfo = aTable.LogOnInfo&lt;br /&gt;&lt;br /&gt;         OutputDebugLine("BEFORE")&lt;br /&gt;         OutputDebugLine("TABLE NAME: " &amp; aTable.Name)&lt;br /&gt;         OutputDebugLine("TABLE LOC: " &amp; aTable.Location)&lt;br /&gt;         OutputDebugLine("SERVER: " &amp; crTableLogOnInfo.ConnectionInfo.ServerName)&lt;br /&gt;         OutputDebugLine("DB: " &amp; crTableLogOnInfo.ConnectionInfo.DatabaseName)&lt;br /&gt;         OutputDebugLine("UID: " &amp; crTableLogOnInfo.ConnectionInfo.UserID)&lt;br /&gt;         OutputDebugLine("PWD: " &amp; crTableLogOnInfo.ConnectionInfo.Password)&lt;br /&gt;         OutputDebugLine("RN: " &amp; crTableLogOnInfo.ReportName)&lt;br /&gt;         OutputDebugLine("TN: " &amp; crTableLogOnInfo.TableName)&lt;br /&gt;&lt;br /&gt;         crTableLogOnInfo.ConnectionInfo = crConnectionInfo&lt;br /&gt;         aTable.ApplyLogOnInfo(crTableLogOnInfo)&lt;br /&gt;         strLocation = crConnectionInfo.DatabaseName &amp; ".dbo." &amp; aTable.Location.Substring(aTable.Location.LastIndexOf(".") + 1)&lt;br /&gt;         OutputDebugLine("New Location: " &amp; strLocation)&lt;br /&gt;         Try&lt;br /&gt;            aTable.Location = strLocation&lt;br /&gt;         Catch ex As Exception&lt;br /&gt;            OutputDebugLine("Set Location Error: " &amp; ex.ToString)&lt;br /&gt;            blnErrors = True&lt;br /&gt;         End Try&lt;br /&gt;&lt;br /&gt;         OutputDebugLine("AFTER")&lt;br /&gt;         OutputDebugLine("TABLE NAME: " &amp; aTable.Name)&lt;br /&gt;         OutputDebugLine("TABLE LOC: " &amp; aTable.Location)&lt;br /&gt;         OutputDebugLine("SERVER: " &amp; crTableLogOnInfo.ConnectionInfo.ServerName)&lt;br /&gt;         OutputDebugLine("DB: " &amp; crTableLogOnInfo.ConnectionInfo.DatabaseName)&lt;br /&gt;         OutputDebugLine("UID: " &amp; crTableLogOnInfo.ConnectionInfo.UserID)&lt;br /&gt;         OutputDebugLine("PWD: " &amp; crTableLogOnInfo.ConnectionInfo.Password)&lt;br /&gt;         OutputDebugLine("RN: " &amp; crTableLogOnInfo.ReportName)&lt;br /&gt;         OutputDebugLine("TN: " &amp; crTableLogOnInfo.TableName)&lt;br /&gt;         Try&lt;br /&gt;            blnTest = aTable.TestConnectivity()&lt;br /&gt;            OutputDebugLine("CONNECTED? " &amp; blnTest.ToString())&lt;br /&gt;         Catch ex As Exception&lt;br /&gt;            OutputDebugLine("CONNECTED? NO")&lt;br /&gt;            OutputDebugLine(ex.ToString)&lt;br /&gt;            blnErrors = True&lt;br /&gt;         End Try&lt;br /&gt;&lt;br /&gt;         '// THIS STUFF HERE IS FOR REPORTS HAVING SUBREPORTS &lt;br /&gt;         '// set the sections object to the current report's section &lt;br /&gt;         crSections = objCrystalReportDocument.ReportDefinition.Sections&lt;br /&gt;&lt;br /&gt;         '// loop through all the sections to find all the report objects &lt;br /&gt;         For Each crSection In crSections&lt;br /&gt;&lt;br /&gt;            crReportObjects = crSection.ReportObjects&lt;br /&gt;&lt;br /&gt;            '//loop through all the report objects in there to find all subreports &lt;br /&gt;            For Each crReportObject In crReportObjects&lt;br /&gt;&lt;br /&gt;               If crReportObject.Kind = ReportObjectKind.SubreportObject Then&lt;br /&gt;&lt;br /&gt;                  crSubreportObject = CType(crReportObject, CrystalDecisions.CrystalReports.Engine.SubreportObject)&lt;br /&gt;                  '//open the subreport object and logon as for the general report &lt;br /&gt;                  crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)&lt;br /&gt;                  crDatabase = crSubreportDocument.Database&lt;br /&gt;                  crTables = crDatabase.Tables&lt;br /&gt;&lt;br /&gt;                  For Each bTable In crTables&lt;br /&gt;&lt;br /&gt;                     crTableLogOnInfo = bTable.LogOnInfo&lt;br /&gt;&lt;br /&gt;                     OutputDebugLine("BEFORE")&lt;br /&gt;                     OutputDebugLine("TABLE NAME: " &amp; bTable.Name)&lt;br /&gt;                     OutputDebugLine("TABLE LOC: " &amp; bTable.Location)&lt;br /&gt;                     OutputDebugLine("SERVER: " &amp; crTableLogOnInfo.ConnectionInfo.ServerName)&lt;br /&gt;                     OutputDebugLine("DB: " &amp; crTableLogOnInfo.ConnectionInfo.DatabaseName)&lt;br /&gt;                     OutputDebugLine("UID: " &amp; crTableLogOnInfo.ConnectionInfo.UserID)&lt;br /&gt;                     OutputDebugLine("PWD: " &amp; crTableLogOnInfo.ConnectionInfo.Password)&lt;br /&gt;                     OutputDebugLine("RN: " &amp; crTableLogOnInfo.ReportName)&lt;br /&gt;                     OutputDebugLine("TN: " &amp; crTableLogOnInfo.TableName)&lt;br /&gt;&lt;br /&gt;                     crTableLogOnInfo.ConnectionInfo = crConnectionInfo&lt;br /&gt;                     bTable.ApplyLogOnInfo(crTableLogOnInfo)&lt;br /&gt;                     strLocation = crConnectionInfo.DatabaseName &amp; ".dbo." &amp; bTable.Location.Substring(bTable.Location.LastIndexOf(".") + 1)&lt;br /&gt;                     OutputDebugLine("New Location: " &amp; strLocation)&lt;br /&gt;                     Try&lt;br /&gt;                        bTable.Location = strLocation&lt;br /&gt;                     Catch ex As Exception&lt;br /&gt;                        OutputDebugLine("Set Location Error: " &amp; ex.ToString)&lt;br /&gt;                        blnErrors = True&lt;br /&gt;                     End Try&lt;br /&gt;&lt;br /&gt;                     OutputDebugLine("AFTER")&lt;br /&gt;                     OutputDebugLine("TABLE NAME: " &amp; bTable.Name)&lt;br /&gt;                     OutputDebugLine("TABLE LOC: " &amp; bTable.Location)&lt;br /&gt;                     OutputDebugLine("SERVER: " &amp; crTableLogOnInfo.ConnectionInfo.ServerName)&lt;br /&gt;                     OutputDebugLine("DB: " &amp; crTableLogOnInfo.ConnectionInfo.DatabaseName)&lt;br /&gt;                     OutputDebugLine("UID: " &amp; crTableLogOnInfo.ConnectionInfo.UserID)&lt;br /&gt;                     OutputDebugLine("PWD: " &amp; crTableLogOnInfo.ConnectionInfo.Password)&lt;br /&gt;                     OutputDebugLine("RN: " &amp; crTableLogOnInfo.ReportName)&lt;br /&gt;                     OutputDebugLine("TN: " &amp; crTableLogOnInfo.TableName)&lt;br /&gt;                     Try&lt;br /&gt;                        blnTest = bTable.TestConnectivity()&lt;br /&gt;                        OutputDebugLine("CONNECTED? " &amp; blnTest.ToString())&lt;br /&gt;                     Catch ex As Exception&lt;br /&gt;                        OutputDebugLine("CONNECTED? NO")&lt;br /&gt;                        OutputDebugLine(ex.ToString)&lt;br /&gt;                        blnErrors = True&lt;br /&gt;                     End Try&lt;br /&gt;&lt;br /&gt;                  Next bTable&lt;br /&gt;&lt;br /&gt;               End If&lt;br /&gt;&lt;br /&gt;            Next crReportObject&lt;br /&gt;&lt;br /&gt;         Next crSection&lt;br /&gt;&lt;br /&gt;      Next aTable&lt;br /&gt;&lt;br /&gt;      ' get parameter fields from report&lt;br /&gt;      crParameterFieldDefinitions = objCrystalReportDocument.DataDefinition.ParameterFields&lt;br /&gt;&lt;br /&gt;      '    ' Set the first parameter&lt;br /&gt;      '    ' - Get the parameter, tell it to use the current values vs default value.&lt;br /&gt;      '    ' - Tell it the parameter contains 1 discrete value vs multiple values.&lt;br /&gt;      '    ' - Set the parameter's value.&lt;br /&gt;      '    ' - Add it and apply it.&lt;br /&gt;      '    ' - Repeat these statements for each parameter.&lt;br /&gt;      '    '&lt;br /&gt;      crParameterFieldLocation = crParameterFieldDefinitions.Item("@psindex")&lt;br /&gt;      crParameterValues = crParameterFieldLocation.CurrentValues&lt;br /&gt;      crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue&lt;br /&gt;      crParameterDiscreteValue.Value = m_intReportID&lt;br /&gt;      crParameterValues.Add(crParameterDiscreteValue)&lt;br /&gt;      crParameterFieldLocation.ApplyCurrentValues(crParameterValues)&lt;br /&gt;&lt;br /&gt;      ' if there were errors&lt;br /&gt;      If blnErrors Then&lt;br /&gt;&lt;br /&gt;         ' display debug page&lt;br /&gt;         OutputDebugPage()&lt;br /&gt;&lt;br /&gt;      End If&lt;br /&gt;&lt;br /&gt;   End Function&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;   ' GetConnectionInfo&lt;br /&gt;   '&lt;br /&gt;   ' Description:&lt;br /&gt;   '    retrieves the connection information from the data layer object&lt;br /&gt;   '&lt;br /&gt;   ' Arguments: none&lt;br /&gt;   '&lt;br /&gt;   ' Dependencies:&lt;br /&gt;   '    DataLayer.GetConnectInfo&lt;br /&gt;   '&lt;br /&gt;   ' History:&lt;br /&gt;   ' 03/17/2006 - WSR : created&lt;br /&gt;   '&lt;br /&gt;   Private Function GetConnectionInfo() As CrystalDecisions.Shared.ConnectionInfo&lt;br /&gt;&lt;br /&gt;      Dim objConnectionInfo As CrystalDecisions.Shared.ConnectionInfo&lt;br /&gt;      Dim strDSN As System.String&lt;br /&gt;      Dim strDB As System.String&lt;br /&gt;      Dim strUID As System.String&lt;br /&gt;      Dim strPWD As System.String&lt;br /&gt;      Dim blnTrust As System.Boolean&lt;br /&gt;&lt;br /&gt;      ' get connection information from data layer&lt;br /&gt;      m_objDataLayer.GetConnectInfo(strDSN, strDB, strUID, strPWD, blnTrust)&lt;br /&gt;&lt;br /&gt;      ' create new crystal connection info object&lt;br /&gt;      objConnectionInfo = New CrystalDecisions.Shared.ConnectionInfo&lt;br /&gt;&lt;br /&gt;      ' populate it&lt;br /&gt;      objConnectionInfo.IntegratedSecurity = False&lt;br /&gt;      objConnectionInfo.ServerName = strDSN&lt;br /&gt;      objConnectionInfo.UserID = strUID&lt;br /&gt;      objConnectionInfo.Password = strPWD&lt;br /&gt;      objConnectionInfo.DatabaseName = strDB&lt;br /&gt;&lt;br /&gt;      ' return object&lt;br /&gt;      GetConnectionInfo = objConnectionInfo&lt;br /&gt;&lt;br /&gt;   End Function&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;   ' OutputDebugLine&lt;br /&gt;   '&lt;br /&gt;   ' Description: appends a line to the debug string builder&lt;br /&gt;   '&lt;br /&gt;   ' Arguments: text to add&lt;br /&gt;   '&lt;br /&gt;   ' Dependencies:&lt;br /&gt;   '    m_strDebugPage&lt;br /&gt;   '&lt;br /&gt;   ' History:&lt;br /&gt;   ' 03/17/2006 - WSR : created&lt;br /&gt;   ' 2007.04.25 - WSR : revised to use string builder&lt;br /&gt;   '&lt;br /&gt;   Function OutputDebugLine(ByVal strLine As System.String) As System.Boolean&lt;br /&gt;&lt;br /&gt;      m_strDebugPage.Append("&lt;div&gt;" &amp; Server.HtmlEncode(strLine) &amp; "&lt;/div&gt;")&lt;br /&gt;&lt;br /&gt;   End Function&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;   ' OutputDebugPage&lt;br /&gt;   '&lt;br /&gt;   ' Description: sends debug string builder to response&lt;br /&gt;   '&lt;br /&gt;   ' Arguments: none&lt;br /&gt;   '&lt;br /&gt;   ' Dependencies:&lt;br /&gt;   '    m_strDebugPage&lt;br /&gt;   '&lt;br /&gt;   ' History:&lt;br /&gt;   ' 2007.04.25 - WSR : created&lt;br /&gt;   '&lt;br /&gt;   Function OutputDebugPage() As System.Boolean&lt;br /&gt;&lt;br /&gt;      With Response&lt;br /&gt;         .ClearHeaders()&lt;br /&gt;         .ClearContent()&lt;br /&gt;         .ContentType = "text/html"&lt;br /&gt;      End With&lt;br /&gt;&lt;br /&gt;      Response.Write("&lt;html&gt;&lt;head&gt;&lt;title&gt;Debug Page&lt;/title&gt;&lt;/head&gt;&lt;body&gt;")&lt;br /&gt;      Response.Write(m_strDebugPage.ToString())&lt;br /&gt;      Response.Write("&lt;/body&gt;&lt;/html&gt;")&lt;br /&gt;&lt;br /&gt;      Response.Flush()&lt;br /&gt;      Response.End()&lt;br /&gt;&lt;br /&gt;   End Function&lt;br /&gt;   ' --------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 16 May 2007 20:30:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4029</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>ASP.Net Serve File For Download</title>
      <link>http://snippets.dzone.com/posts/show/3510</link>
      <description>Function I use to serve a file on the webserver to the client machine.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;   ' sends file to browser for download&lt;br /&gt;   Private Sub SendFile(ByVal strPath As System.String, ByVal strSuggestedName As System.String)&lt;br /&gt;&lt;br /&gt;      Dim strServerPath As String&lt;br /&gt;      Dim objSourceFileInfo As System.IO.FileInfo&lt;br /&gt;&lt;br /&gt;      ' convert relative path to path on server machine&lt;br /&gt;      strServerPath = Me.Server.MapPath(strPath)&lt;br /&gt;&lt;br /&gt;      ' get fileinfo of source file&lt;br /&gt;      objSourceFileInfo = New System.IO.FileInfo(strServerPath)&lt;br /&gt;&lt;br /&gt;      ' if the file exists&lt;br /&gt;      If objSourceFileInfo.Exists Then&lt;br /&gt;&lt;br /&gt;         With Me.Response&lt;br /&gt;&lt;br /&gt;            ' tell the browser what content type to expect&lt;br /&gt;            .ContentType = "application/octet-stream"&lt;br /&gt; &lt;br /&gt;            ' tell the browser to save rather than display inline&lt;br /&gt;            .AddHeader("Content-Disposition", "attachment; filename=" &amp; strSuggestedName)&lt;br /&gt;&lt;br /&gt;            ' tell the browser how big the file is&lt;br /&gt;            .AddHeader("Content-Length", objSourceFileInfo.Length.ToString)&lt;br /&gt;&lt;br /&gt;            ' send the file to the browser&lt;br /&gt;            .WriteFile(objSourceFileInfo.FullName)&lt;br /&gt;&lt;br /&gt;            ' make sure response is sent&lt;br /&gt;            .Flush()&lt;br /&gt;&lt;br /&gt;            ' end response&lt;br /&gt;            .End()&lt;br /&gt;&lt;br /&gt;         End With&lt;br /&gt;&lt;br /&gt;      ' if the file does not exist&lt;br /&gt;      Else&lt;br /&gt;&lt;br /&gt;         ' show error page&lt;br /&gt;         ThrowError("Application Error", "File Missing From Server")&lt;br /&gt;&lt;br /&gt;      End If&lt;br /&gt;&lt;br /&gt;   End Sub        &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 16:52:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3510</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>Javascript Manipulate Class Names</title>
      <link>http://snippets.dzone.com/posts/show/2630</link>
      <description>I often have to manipulate class names of objects in javascript.&lt;br /&gt;But className can have multiple classes in it.&lt;br /&gt;These functions deal with that.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// HasClassName&lt;br /&gt;//&lt;br /&gt;// Description : returns boolean indicating whether the object has the class name&lt;br /&gt;//    built with the understanding that there may be multiple classes&lt;br /&gt;//&lt;br /&gt;// Arguments:&lt;br /&gt;//    objElement              - element to manipulate&lt;br /&gt;//    strClass                - class name to add&lt;br /&gt;//&lt;br /&gt;function HasClassName(objElement, strClass)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // if there is a class&lt;br /&gt;   if ( objElement.className )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // the classes are just a space separated list, so first get the list&lt;br /&gt;      var arrList = objElement.className.split(' ');&lt;br /&gt;&lt;br /&gt;      // get uppercase class for comparison purposes&lt;br /&gt;      var strClassUpper = strClass.toUpperCase();&lt;br /&gt;&lt;br /&gt;      // find all instances and remove them&lt;br /&gt;      for ( var i = 0; i &lt; arrList.length; i++ )&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // if class found&lt;br /&gt;         if ( arrList[i].toUpperCase() == strClassUpper )&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;            // we found it&lt;br /&gt;            return true;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   // if we got here then the class name is not there&lt;br /&gt;   return false;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;// &lt;br /&gt;// HasClassName&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// AddClassName&lt;br /&gt;//&lt;br /&gt;// Description : adds a class to the class attribute of a DOM element&lt;br /&gt;//    built with the understanding that there may be multiple classes&lt;br /&gt;//&lt;br /&gt;// Arguments:&lt;br /&gt;//    objElement              - element to manipulate&lt;br /&gt;//    strClass                - class name to add&lt;br /&gt;//&lt;br /&gt;function AddClassName(objElement, strClass, blnMayAlreadyExist)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // if there is a class&lt;br /&gt;   if ( objElement.className )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // the classes are just a space separated list, so first get the list&lt;br /&gt;      var arrList = objElement.className.split(' ');&lt;br /&gt;&lt;br /&gt;      // if the new class name may already exist in list&lt;br /&gt;      if ( blnMayAlreadyExist )&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // get uppercase class for comparison purposes&lt;br /&gt;         var strClassUpper = strClass.toUpperCase();&lt;br /&gt;&lt;br /&gt;         // find all instances and remove them&lt;br /&gt;         for ( var i = 0; i &lt; arrList.length; i++ )&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;            // if class found&lt;br /&gt;            if ( arrList[i].toUpperCase() == strClassUpper )&lt;br /&gt;               {&lt;br /&gt;&lt;br /&gt;               // remove array item&lt;br /&gt;               arrList.splice(i, 1);&lt;br /&gt;&lt;br /&gt;               // decrement loop counter as we have adjusted the array's contents&lt;br /&gt;               i--;&lt;br /&gt;&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      // add the new class to end of list&lt;br /&gt;      arrList[arrList.length] = strClass;&lt;br /&gt;&lt;br /&gt;      // add the new class to beginning of list&lt;br /&gt;      //arrList.splice(0, 0, strClass);&lt;br /&gt;      &lt;br /&gt;      // assign modified class name attribute&lt;br /&gt;      objElement.className = arrList.join(' ');&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;   // if there was no class&lt;br /&gt;   else&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // assign modified class name attribute      &lt;br /&gt;      objElement.className = strClass;&lt;br /&gt;   &lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;// &lt;br /&gt;// AddClassName&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// RemoveClassName&lt;br /&gt;//&lt;br /&gt;// Description : removes a class from the class attribute of a DOM element&lt;br /&gt;//    built with the understanding that there may be multiple classes&lt;br /&gt;//&lt;br /&gt;// Arguments:&lt;br /&gt;//    objElement              - element to manipulate&lt;br /&gt;//    strClass                - class name to remove&lt;br /&gt;//&lt;br /&gt;function RemoveClassName(objElement, strClass)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // if there is a class&lt;br /&gt;   if ( objElement.className )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // the classes are just a space separated list, so first get the list&lt;br /&gt;      var arrList = objElement.className.split(' ');&lt;br /&gt;&lt;br /&gt;      // get uppercase class for comparison purposes&lt;br /&gt;      var strClassUpper = strClass.toUpperCase();&lt;br /&gt;&lt;br /&gt;      // find all instances and remove them&lt;br /&gt;      for ( var i = 0; i &lt; arrList.length; i++ )&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // if class found&lt;br /&gt;         if ( arrList[i].toUpperCase() == strClassUpper )&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;            // remove array item&lt;br /&gt;            arrList.splice(i, 1);&lt;br /&gt;&lt;br /&gt;            // decrement loop counter as we have adjusted the array's contents&lt;br /&gt;            i--;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      // assign modified class name attribute&lt;br /&gt;      objElement.className = arrList.join(' ');&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;   // if there was no class&lt;br /&gt;   // there is nothing to remove&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;// &lt;br /&gt;// RemoveClassName&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;  &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 20 Sep 2006 21:34:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2630</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>Javascript QuickSelect (Coordinated Textbox And ListBox)</title>
      <link>http://snippets.dzone.com/posts/show/2629</link>
      <description>In HTML, say you have a select element with all the states.&lt;br /&gt;Unfortunately typing in this select box only works with the first letter.&lt;br /&gt;So if you type P then A you don't select pennsylvania.&lt;br /&gt;What I commonly do in this situation is to have what I call a quickselect textbox on the page as well.&lt;br /&gt;This is a textbox and listbox that are coordinated.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// in your onload event handler you need this&lt;br /&gt;&lt;br /&gt;// hookup event handlers and control references&lt;br /&gt;var objElement = document.getElementById('cboState');&lt;br /&gt;if ( objElement )&lt;br /&gt;   {&lt;br /&gt;   objElement.onchange = QuickSelect_Change;&lt;br /&gt;   objElement.textbox = document.getElementById('txtState');&lt;br /&gt;   if ( objElement.textbox )&lt;br /&gt;      {&lt;br /&gt;      objElement.textbox.onchange = QuickSelect_TextChange;&lt;br /&gt;      objElement.textbox.onblur = QuickSelect_TextChange;&lt;br /&gt;      objElement.textbox.onkeypress = QuickSelect_KeyPress;&lt;br /&gt;      objElement.textbox.listbox = objElement;&lt;br /&gt;      }&lt;br /&gt;   }       &lt;br /&gt;&lt;br /&gt;// and now the functions&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// QuickSelect_KeyPress&lt;br /&gt;//&lt;br /&gt;// Description : event handler for quick select textbox's key press event&lt;br /&gt;//    selects the appropriate item in the associated listbox control&lt;br /&gt;//&lt;br /&gt;// Arguments : none&lt;br /&gt;//&lt;br /&gt;// Dependencies : &lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.09.20 - WSR : created&lt;br /&gt;//&lt;br /&gt;function QuickSelect_KeyPress( e )&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   var strCompare = '';&lt;br /&gt;   var numEntryLen;&lt;br /&gt;   var strEntry;&lt;br /&gt;   var objSelect = this.listbox;&lt;br /&gt;   var numOptions = objSelect.options.length;&lt;br /&gt;&lt;br /&gt;   var numCharCode;&lt;br /&gt;   var elTarget;&lt;br /&gt;&lt;br /&gt;   // get event if not passed&lt;br /&gt;   if (!e) var e = window.event;&lt;br /&gt;&lt;br /&gt;   // get character code of key pressed&lt;br /&gt;   if (e.keyCode) numCharCode = e.keyCode;&lt;br /&gt;   else if (e.which) numCharCode = e.which;&lt;br /&gt;&lt;br /&gt;   // get target&lt;br /&gt;   if (e.target) elTarget = e.target;&lt;br /&gt;   else if (e.srcElement) elTarget = e.srcElement;&lt;br /&gt;                                              &lt;br /&gt;   // if form input field &amp; it is a printable character&lt;br /&gt;   if ( elTarget.nodeName.toUpperCase() == 'INPUT' &amp;&amp; numCharCode &gt;= 32 &amp;&amp; numCharCode &lt;= 126 )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      strEntry = this.value + String.fromCharCode(numCharCode);&lt;br /&gt;      numEntryLen = strEntry.length;&lt;br /&gt;&lt;br /&gt;      // cycle through options&lt;br /&gt;      for (var i = 0; i &lt; numOptions; i++)&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // get compare string from value same length as entered string&lt;br /&gt;         strCompare = objSelect.options[i].value.substring(0, numEntryLen);&lt;br /&gt;&lt;br /&gt;         // if value matches what is entered&lt;br /&gt;         if (strEntry == strCompare)&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;            // select this option&lt;br /&gt;            objSelect.options[i].selected = true;&lt;br /&gt;&lt;br /&gt;            // end loop&lt;br /&gt;            break;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      // I usually add an error class when input is required and not filled in&lt;br /&gt;      // this removes the class so the input is no longer marked as invalid&lt;br /&gt;      // commented out as it isn't necessary for general purpose&lt;br /&gt;      // RemoveClassName( this, 'error' );&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// QuickSelect_KeyPress&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// QuickSelect_TextChange&lt;br /&gt;//&lt;br /&gt;// Description : event handler for quick select textbox's change &amp; onblur events&lt;br /&gt;//    makes sure item in textbox is a value from list&lt;br /&gt;//&lt;br /&gt;// Arguments : none&lt;br /&gt;//&lt;br /&gt;// Dependencies : none&lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.08.09 - WSR : created&lt;br /&gt;//&lt;br /&gt;function QuickSelect_TextChange()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   var strCompare = '';&lt;br /&gt;   var numEntryLen = this.value.length;&lt;br /&gt;   var strEntry = this.value;&lt;br /&gt;   var objSelect = this.listbox;&lt;br /&gt;   var numOptions = objSelect.options.length;&lt;br /&gt;&lt;br /&gt;   // cycle through options&lt;br /&gt;   for (var i = 0; i &lt; numOptions; i++)&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // get compare string from value same length as entered string&lt;br /&gt;      strCompare = objSelect.options[i].value.substring(0, numEntryLen);&lt;br /&gt;&lt;br /&gt;      // if value matches what is entered&lt;br /&gt;      if (strEntry == strCompare)&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // select this option&lt;br /&gt;         objSelect.options[i].selected = true;&lt;br /&gt;&lt;br /&gt;         // end loop&lt;br /&gt;         break;&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   // copy code to textbox&lt;br /&gt;   this.value = this.listbox.options[this.listbox.selectedIndex].value;&lt;br /&gt;&lt;br /&gt;   // I usually add an error class when input is required and not filled in&lt;br /&gt;   // this removes the class so the input is no longer marked as invalid&lt;br /&gt;   // commented out as it isn't necessary for general purpose&lt;br /&gt;   // RemoveClassName( this, 'error' );&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// QuickSelect_TextChange&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// QuickSelect_Change&lt;br /&gt;//&lt;br /&gt;// Description : event handler for quick select list box's change event&lt;br /&gt;//    updates the textbox with the selected value&lt;br /&gt;//&lt;br /&gt;// Arguments: none&lt;br /&gt;//&lt;br /&gt;// Dependencies :&lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.08.09 - WSR : created&lt;br /&gt;//&lt;br /&gt;function QuickSelect_Change()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // copy code to textbox&lt;br /&gt;   this.textbox.value = this.options[this.selectedIndex].value;&lt;br /&gt;&lt;br /&gt;   }	&lt;br /&gt;//&lt;br /&gt;// QuickSelect_Change&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;  &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 20 Sep 2006 21:31:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2629</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>Javascript LookupControl</title>
      <link>http://snippets.dzone.com/posts/show/2278</link>
      <description>A lookup control is a common thing to have on many web pages.  In this case we assume a textbox, a command button, and a label of some sort to display a description.&lt;br /&gt;&lt;br /&gt;The HTML might look like this&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;label for="txtExistingClient"&gt;Client&lt;/label&gt;&lt;br /&gt;&lt;input id="txtExistingClient" name="txtExistingClient" type="text" size="15" maxlength="14" class="text uppercase" runat="server"&gt;&lt;br /&gt;&lt;input id="cmdExistingClientLookup" name="cmdExistingClientLookup" type="button" value=" ? "&gt;&lt;br /&gt;&lt;span id="lblExistingClient"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here is a javascript function to call in the onload to setup that lookup control.  And examples of the functions required.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// SetupLookupControl&lt;br /&gt;//&lt;br /&gt;// Description : sets up a lookup control by linking it to its &lt;br /&gt;//    associated controls and hooking up the event handlers&lt;br /&gt;//&lt;br /&gt;// Arguments :&lt;br /&gt;//    strTextBoxID               : input type=text id&lt;br /&gt;//    strLookupButtonID          : input type=button id&lt;br /&gt;//    strLabelID                 : span of div id&lt;br /&gt;//    funcTextBoxOnChange        : function for textbox's onchange and onblur event&lt;br /&gt;//    funcLookupButtonOnClick    : function for lookup button's onclick event&lt;br /&gt;//&lt;br /&gt;// Dependencies : none&lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.07.14 - WSR : created&lt;br /&gt;//&lt;br /&gt;function SetupLookupControl( strTextBoxID, strLookupButtonID, strLabelID, funcTextBoxOnChange, funcLookupButtonOnClick )&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // get reference to lookup button&lt;br /&gt;   var ctlLookupButton = document.getElementById(strLookupButtonID);&lt;br /&gt;&lt;br /&gt;   // if lookup button was found&lt;br /&gt;   if (ctlLookupButton)&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // hookup event handlers and control references&lt;br /&gt;      ctlLookupButton.onclick = funcLookupButtonOnClick;&lt;br /&gt;      ctlLookupButton.textbox = document.getElementById(strTextBoxID);&lt;br /&gt;&lt;br /&gt;      // if textbox was found&lt;br /&gt;      if (ctlLookupButton.textbox)&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // hookup event handlers and control references&lt;br /&gt;         ctlLookupButton.textbox.onchange = funcTextBoxOnChange;&lt;br /&gt;         ctlLookupButton.textbox.onblur = funcTextBoxOnChange;&lt;br /&gt;         ctlLookupButton.textbox.label = document.getElementById(strLabelID);&lt;br /&gt;&lt;br /&gt;         // init last value property of textbox&lt;br /&gt;         if ( typeof ctlLookupButton.textbox.lastvalue == 'undefined' )&lt;br /&gt;            ctlLookupButton.textbox.lastvalue = ''; &lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// SetupLookupControl&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// cmdTimekeeperLookup_click&lt;br /&gt;// Description: handler for requesting timekeeper selection button click event&lt;br /&gt;// Arguments: none&lt;br /&gt;// Dependencies:&lt;br /&gt;//    TimekeepQuery (lookup.js)&lt;br /&gt;//&lt;br /&gt;function cmdTimekeeperLookup_click()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // show timekeeper query window&lt;br /&gt;   TimekeepQuery( this.textbox );&lt;br /&gt;&lt;br /&gt;   // update timekeeper information&lt;br /&gt;   this.textbox.onchange();&lt;br /&gt;&lt;br /&gt;   // process default action&lt;br /&gt;   return true;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// cmdTimekeeperLookup_click&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// txtTimekeeper_change&lt;br /&gt;// Description: event handler for timekeeper textbox change event&lt;br /&gt;// Arguments: none&lt;br /&gt;// Dependencies:&lt;br /&gt;//    window.strTkprMask (masking.js)&lt;br /&gt;//    trim&lt;br /&gt;//    ApplyMask (masking.js)&lt;br /&gt;//    TimekeepLookup (lookup.js)&lt;br /&gt;//    UpdateElementText (shared.js)&lt;br /&gt;//&lt;br /&gt;function txtTimekeeper_change()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   var strTimekeepName = '';&lt;br /&gt;   var objXMLDOM;&lt;br /&gt;   var nodField;&lt;br /&gt; &lt;br /&gt;   // trim input&lt;br /&gt;   this.value = this.value.trim();&lt;br /&gt;  &lt;br /&gt;   // if there was input&lt;br /&gt;   if ( this.value.length &gt; 0 )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // apply timekeep mask to textbox input&lt;br /&gt;      ApplyMask( this, window.strTkprMask );&lt;br /&gt;&lt;br /&gt;      // if inputted timekeeper is different from current timekeeper&lt;br /&gt;      if ( this.lastvalue != this.value )&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // request timekeeper information&lt;br /&gt;         objXMLDOM = TimekeepLookup( this.value );&lt;br /&gt;&lt;br /&gt;         // if XML DOM object returned&lt;br /&gt;         if ( typeof objXMLDOM == 'object' )&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;            // get field values&lt;br /&gt;            nodField = objXMLDOM.selectSingleNode('//lastname');&lt;br /&gt;            if (nodField != null)&lt;br /&gt;               strTimekeepName = nodField.firstChild.nodeValue;&lt;br /&gt;&lt;br /&gt;            nodField = objXMLDOM.selectSingleNode('//firstname');&lt;br /&gt;            if (nodField != null)&lt;br /&gt;               strTimekeepName = strTimekeepName + ', ' + nodField.firstChild.nodeValue;&lt;br /&gt;&lt;br /&gt;            // update timekeeper&lt;br /&gt;            this.lastvalue = this.value;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;         // if XML DOM object wasn't returned&lt;br /&gt;         else&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;            // indicate timekeeper was not found&lt;br /&gt;            strTimekeepName = 'Timekeep \'' + this.value + '\' was not found.';&lt;br /&gt;&lt;br /&gt;            // update timekeeper&lt;br /&gt;            this.lastvalue = '';&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;         // update document&lt;br /&gt;         UpdateElementText( this.label, strTimekeepName );&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;   // if there was no input&lt;br /&gt;   else&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // clear the timekeep and display&lt;br /&gt;      this.lastvalue = '';&lt;br /&gt;      UpdateElementText( this.label, '' );&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   // process default action&lt;br /&gt;   return true;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// txtTimekeeper_change&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 14 Jul 2006 22:28:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2278</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>Javascript: Preventing Form Submit When Enter is Pressed</title>
      <link>http://snippets.dzone.com/posts/show/2272</link>
      <description>In a web page, normally pressing enter when any form element has focus will submit the form.  This is often premature.  When you have a checkbox selected you probably just want to check the checkbox, not submit the form.  So I wrote some javascript to translate the enter into a tab when possible (IE) and prevent the form submit when translation isn't possible (non-IE).&lt;br /&gt;&lt;br /&gt;First is the code in your onload event handler.&lt;br /&gt;This sets up onkeydown if window.event is supported (IE) and onkeypress if not.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var frmRequest = document.getElementById('frmRequest');&lt;br /&gt;if (frmRequest)&lt;br /&gt;   {&lt;br /&gt;   if (window.event)&lt;br /&gt;      frmRequest.onkeydown = frmRequest_KeyDown;&lt;br /&gt;   else&lt;br /&gt;      frmRequest.onkeypress = frmRequest_KeyPress;&lt;br /&gt;   }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Next are the actual event handlers.&lt;br /&gt;Nothing really special here, just dealing with the different ways of accessing event properties.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// frmRequest_KeyDown&lt;br /&gt;//&lt;br /&gt;// Description: event handler for request form key down event&lt;br /&gt;//    translates returns on option buttons to a tab&lt;br /&gt;//    this works only for IE, the keypress event is used for other browsers&lt;br /&gt;//&lt;br /&gt;// Arguments : &lt;br /&gt;//    e - the event object&lt;br /&gt;//&lt;br /&gt;// Dependencies : none&lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.07.13 - WSR : adapted to this project&lt;br /&gt;//&lt;br /&gt;function frmRequest_KeyDown( e )&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   var numCharCode;&lt;br /&gt;   var elTarget;&lt;br /&gt;   var strType;&lt;br /&gt;&lt;br /&gt;   // get event if not passed&lt;br /&gt;   if (!e) var e = window.event;&lt;br /&gt;&lt;br /&gt;   // get character code of key pressed&lt;br /&gt;   if (e.keyCode) numCharCode = e.keyCode;&lt;br /&gt;   else if (e.which) numCharCode = e.which;&lt;br /&gt;&lt;br /&gt;   // get target&lt;br /&gt;   if (e.target) elTarget = e.target;&lt;br /&gt;   else if (e.srcElement) elTarget = e.srcElement;&lt;br /&gt;                                              &lt;br /&gt;   // if form input field&lt;br /&gt;   if ( elTarget.tagName.toLowerCase() == 'input' )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // get type&lt;br /&gt;      strType = elTarget.getAttribute('type').toLowerCase();&lt;br /&gt;&lt;br /&gt;      // based on type&lt;br /&gt;      switch ( strType )&lt;br /&gt;         {&lt;br /&gt;         case 'checkbox' :&lt;br /&gt;         case 'radio' :&lt;br /&gt;         case 'text' :&lt;br /&gt;&lt;br /&gt;            // if this is a return - change to tab&lt;br /&gt;            if ( numCharCode == 13 )&lt;br /&gt;               {&lt;br /&gt;               if (e.keyCode) e.keyCode = 9;&lt;br /&gt;               else if (e.which) e.which = 9;&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;            break;&lt;br /&gt;            &lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   // process default action&lt;br /&gt;   return true;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// frmRequest_KeyDown&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// frmRequest_KeyPress&lt;br /&gt;//&lt;br /&gt;// Description: event handler for request form key press event&lt;br /&gt;//    cancels returns on form elements that would prematurely submit the form&lt;br /&gt;//&lt;br /&gt;// Arguments : &lt;br /&gt;//    e - the event object&lt;br /&gt;//&lt;br /&gt;// Dependencies : none&lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.07.13 - WSR : adapted to this project&lt;br /&gt;//&lt;br /&gt;function frmRequest_KeyPress( e )&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   var numCharCode;&lt;br /&gt;   var elTarget;&lt;br /&gt;   var strType;&lt;br /&gt;&lt;br /&gt;   // get event if not passed&lt;br /&gt;   if (!e) var e = window.event;&lt;br /&gt;&lt;br /&gt;   // get character code of key pressed&lt;br /&gt;   if (e.keyCode) numCharCode = e.keyCode;&lt;br /&gt;   else if (e.which) numCharCode = e.which;&lt;br /&gt;&lt;br /&gt;   // get target&lt;br /&gt;   if (e.target) elTarget = e.target;&lt;br /&gt;   else if (e.srcElement) elTarget = e.srcElement;&lt;br /&gt;                                              &lt;br /&gt;   // if form input field&lt;br /&gt;   if ( elTarget.tagName.toLowerCase() == 'input' )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // get type&lt;br /&gt;      strType = elTarget.getAttribute('type').toLowerCase();&lt;br /&gt;&lt;br /&gt;      // based on type&lt;br /&gt;      switch ( strType )&lt;br /&gt;         {&lt;br /&gt;         case 'checkbox' :&lt;br /&gt;         case 'radio' :&lt;br /&gt;         case 'text' :&lt;br /&gt;&lt;br /&gt;            // if this is a return&lt;br /&gt;            if ( numCharCode == 13 )&lt;br /&gt;               {&lt;br /&gt;               // cancel event to prevent form submission&lt;br /&gt;               return false;&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;            break;&lt;br /&gt;            &lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   // process default action&lt;br /&gt;   return true;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// frmRequest_KeyPress&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Jul 2006 20:48:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2272</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>Output DataSet as XML</title>
      <link>http://snippets.dzone.com/posts/show/1975</link>
      <description>I was having problems with my ajax lookups when the database fields returned weird characters like the copyright symbol.  The responseXML would be blank.  After many searches I found you need to output in utf-8 and add an xml declaration to the output that says it is utf-8.  Here is the code below in vb.net for asp.net v1.1&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;   Private Sub OutputDataSetAsXML(ByRef dsSource As System.Data.DataSet)&lt;br /&gt;&lt;br /&gt;      Dim xmlDoc As System.Xml.XmlDataDocument&lt;br /&gt;      Dim xmlDec As System.Xml.XmlDeclaration&lt;br /&gt;      Dim xmlWriter As System.Xml.XmlWriter&lt;br /&gt;&lt;br /&gt;      ' setup response&lt;br /&gt;      Me.Response.Clear()&lt;br /&gt;      Me.Response.ContentType = "text/xml"&lt;br /&gt;      Me.Response.Charset = "utf-8"&lt;br /&gt;      xmlWriter = New System.Xml.XmlTextWriter(Me.Response.OutputStream, System.Text.Encoding.UTF8)&lt;br /&gt;&lt;br /&gt;      ' create xml data document with xml declaration&lt;br /&gt;      xmlDoc = New System.Xml.XmlDataDocument(dsSource)&lt;br /&gt;      xmlDoc.DataSet.EnforceConstraints = False&lt;br /&gt;      xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)&lt;br /&gt;      xmlDoc.PrependChild(xmlDec)&lt;br /&gt;&lt;br /&gt;      ' write xml document to response&lt;br /&gt;      xmlDoc.WriteTo(xmlWriter)&lt;br /&gt;      xmlWriter.Flush()&lt;br /&gt;      xmlWriter.Close()&lt;br /&gt;      Response.End()&lt;br /&gt;&lt;br /&gt;   End Sub &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 03 May 2006 09:18:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1975</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>javascript image swap using DOM</title>
      <link>http://snippets.dzone.com/posts/show/1596</link>
      <description>Here is a javascript image swap that uses the DOM methods.&lt;br /&gt;It uses them to support swapping images with different sizes.&lt;br /&gt;Just changing the src property causes the swapped images to be distorted in IE.&lt;br /&gt;This script uses replaceChild instead.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var blnDOMSUPPORT = (document.getElementById) ? true : false;&lt;br /&gt;window.onload = window_load;&lt;br /&gt;&lt;br /&gt;function window_load()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   if ( blnDOMSUPPORT )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      document.getElementById('icon1').onclick = swapimage;&lt;br /&gt;      document.getElementById('icon2').onclick = swapimage;&lt;br /&gt;      document.getElementById('icon3').onclick = swapimage;&lt;br /&gt;      &lt;br /&gt;      }&lt;br /&gt;   else&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      document.images['icon1'].onclick = swapimage;&lt;br /&gt;      document.images['icon2'].onclick = swapimage;&lt;br /&gt;      document.images['icon3'].onclick = swapimage;&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;function swapimage()&lt;br /&gt;   {&lt;br /&gt;   &lt;br /&gt;   if ( blnDOMSUPPORT )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      var imgMain = document.getElementById('mainimage');&lt;br /&gt;      var divParent;&lt;br /&gt;&lt;br /&gt;      // create new image element&lt;br /&gt;      var imgNew = document.createElement('img');&lt;br /&gt;&lt;br /&gt;      // give it an image&lt;br /&gt;      // here I use the src of the icon just for convenience&lt;br /&gt;      // you'd want to somehow determine the src of your desired image&lt;br /&gt;      imgNew.src = this.src;&lt;br /&gt;   &lt;br /&gt;      // give it an id&lt;br /&gt;      imgNew.id = 'mainimage';&lt;br /&gt;&lt;br /&gt;      // replace image&lt;br /&gt;      divParent = imgMain.parentNode;&lt;br /&gt;      divParent.replaceChild(imgNew, imgMain);&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;   else&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // old school image swap&lt;br /&gt;      document.images['mainimage'].src = this.src;&lt;br /&gt;&lt;br /&gt;      alert( 'old school' );&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;   &lt;br /&gt;   }         &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;It would be used with HTML like this&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div id="main"&gt;&lt;br /&gt;&lt;img id="mainimage" src="http://www.w3schools.com/css/smiley.gif"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div id="icons"&gt;&lt;br /&gt;&lt;img id="icon1" src="http://www.w3schools.com/css/smiley.gif"&gt;&lt;br /&gt;&lt;img id="icon2" src="http://www.w3schools.com/images/vxhtml.gif"&gt;&lt;br /&gt;&lt;img id="icon3" src="http://www.w3schools.com/images/print.gif"&gt;&lt;br /&gt;&lt;input type="button" value="Toggle DOM Support" onclick="window.blnDOMSUPPORT = !window.blnDOMSUPPORT;"&gt;&lt;br /&gt;&lt;/div&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 28 Feb 2006 04:31:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1596</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>splitting a text list in sql</title>
      <link>http://snippets.dzone.com/posts/show/1563</link>
      <description>This goes along with my integer split procedure.&lt;br /&gt;http://www.bigbold.com/snippets/posts/show/774&lt;br /&gt;&lt;br /&gt;Often times I have a list of integers I need to pass to the database to get worked on.  Such as checkboxes on a web page or some other list.  I needed some TSQL that would take a text string and split it by a separator, in this case a comma.  The following is the result of that need.&lt;br /&gt;The way I normally use it is in a stored procedure like the one below with several text type arguments.  This is a variation designed to split a list of strings separated by a special character sequence.  Image two lists, one of the ids and one of the data.  You parse the first list to get a table of the ids and you parse the second list to get the data and insert/update as appropriate.&lt;br /&gt;http://www.bigbold.com/snippets/posts/show/774&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[uspSplitTextList]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)&lt;br /&gt;   DROP PROCEDURE [dbo].[uspSplitTextList]&lt;br /&gt;GO&lt;br /&gt;                                      &lt;br /&gt;SET QUOTED_IDENTIFIER ON &lt;br /&gt;GO&lt;br /&gt;SET ANSI_NULLS ON &lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */&lt;br /&gt;-- uspSplitTextList&lt;br /&gt;--&lt;br /&gt;-- Description:&lt;br /&gt;--		splits a separated list of text items and returns the text items&lt;br /&gt;--&lt;br /&gt;-- Arguments:&lt;br /&gt;--		@list_text				- list of text items&lt;br /&gt;--		@Delimiter				- delimiter&lt;br /&gt;--&lt;br /&gt;-- Notes:&lt;br /&gt;-- 02/22/2006 - WSR : use DATALENGTH instead of LEN throughout because LEN doesn't count trailing blanks&lt;br /&gt;--&lt;br /&gt;-- History:&lt;br /&gt;-- 02/22/2006 - WSR : revised algorithm to account for items crossing 8000 character boundary&lt;br /&gt;--&lt;br /&gt;CREATE PROCEDURE uspSplitTextList&lt;br /&gt;	@list_text				text,&lt;br /&gt;   @Delimiter				varchar(3)&lt;br /&gt;AS&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;DECLARE @InputLen			integer			-- input text length&lt;br /&gt;DECLARE @TextPos			integer			-- current position within input text&lt;br /&gt;DECLARE @Chunk				varchar(8000)	-- chunk within input text&lt;br /&gt;DECLARE @ChunkPos			integer			-- current position within chunk&lt;br /&gt;DECLARE @DelimPos			integer			-- position of delimiter&lt;br /&gt;DECLARE @ChunkLen			integer			-- chunk length&lt;br /&gt;DECLARE @DelimLen			integer			-- delimiter length&lt;br /&gt;DECLARE @ItemBegPos		integer			-- item starting position in text&lt;br /&gt;DECLARE @ItemOrder		integer			-- item order in list&lt;br /&gt;DECLARE @DelimChar		varchar(1)		-- first character of delimiter (simple delimiter)&lt;br /&gt;&lt;br /&gt;-- create table to hold list items&lt;br /&gt;-- actually their positions because we may want to scrub this list eliminating bad entries before substring is applied&lt;br /&gt;CREATE TABLE #list_items ( item_order integer, item_begpos integer, item_endpos integer )&lt;br /&gt;&lt;br /&gt;-- process list&lt;br /&gt;IF @list_text IS NOT NULL&lt;br /&gt;   BEGIN&lt;br /&gt;&lt;br /&gt;	-- initialize&lt;br /&gt;   SET @InputLen = DATALENGTH(@list_text)&lt;br /&gt;   SET @TextPos = 1&lt;br /&gt;	SET @DelimChar = SUBSTRING(@Delimiter, 1, 1)&lt;br /&gt;	SET @DelimLen = DATALENGTH(@Delimiter)&lt;br /&gt;   SET @ItemBegPos = 1&lt;br /&gt;   SET @ItemOrder = 1&lt;br /&gt;   SET @ChunkLen = 1&lt;br /&gt;&lt;br /&gt;   -- cycle through input processing chunks&lt;br /&gt;   WHILE @TextPos &lt;= @InputLen AND @ChunkLen &lt;&gt; 0&lt;br /&gt;      BEGIN&lt;br /&gt;&lt;br /&gt;      -- get current chunk&lt;br /&gt;      SET @Chunk = SUBSTRING(@list_text, @TextPos, 8000)&lt;br /&gt;&lt;br /&gt;      -- setup initial variable values&lt;br /&gt;      SET @ChunkPos = 1&lt;br /&gt;      SET @ChunkLen = DATALENGTH(@Chunk)&lt;br /&gt;      SET @DelimPos = CHARINDEX(@DelimChar, @Chunk, @ChunkPos)&lt;br /&gt;&lt;br /&gt;      -- loop over the chunk, until the last delimiter&lt;br /&gt;      WHILE @ChunkPos &lt;= @ChunkLen AND @DelimPos &lt;&gt; 0&lt;br /&gt;         BEGIN&lt;br /&gt;&lt;br /&gt;			-- see if this is a full delimiter&lt;br /&gt;         IF SUBSTRING(@list_text, (@TextPos + @DelimPos - 1), @DelimLen) = @Delimiter&lt;br /&gt;            BEGIN&lt;br /&gt;&lt;br /&gt;				-- insert position&lt;br /&gt;	         INSERT INTO #list_items (item_order, item_begpos, item_endpos)&lt;br /&gt;	         VALUES (@ItemOrder, @ItemBegPos, (@TextPos + @DelimPos - 1) - 1)&lt;br /&gt;	         &lt;br /&gt;	         -- adjust positions&lt;br /&gt;	         SET @ItemOrder = @ItemOrder + 1&lt;br /&gt;	         SET @ItemBegPos = (@TextPos + @DelimPos - 1) + @DelimLen&lt;br /&gt;	         SET @ChunkPos = @DelimPos + @DelimLen&lt;br /&gt;&lt;br /&gt;				END&lt;br /&gt;         ELSE&lt;br /&gt;            BEGIN&lt;br /&gt;&lt;br /&gt;            -- adjust positions&lt;br /&gt;            SET @ChunkPos = @DelimPos + 1&lt;br /&gt;&lt;br /&gt;            END&lt;br /&gt;      &lt;br /&gt;         -- find next delimiter      &lt;br /&gt;         SET @DelimPos = CHARINDEX(@DelimChar, @Chunk, @ChunkPos)&lt;br /&gt;&lt;br /&gt;         END&lt;br /&gt;&lt;br /&gt;      -- adjust positions&lt;br /&gt;      SET @TextPos = @TextPos + @ChunkLen&lt;br /&gt;&lt;br /&gt;      END&lt;br /&gt;&lt;br /&gt;	-- handle last item&lt;br /&gt;   IF @ItemBegPos &lt;= @InputLen&lt;br /&gt;      BEGIN&lt;br /&gt;&lt;br /&gt;      -- insert position&lt;br /&gt;      INSERT INTO #list_items (item_order, item_begpos, item_endpos)&lt;br /&gt;      VALUES (@ItemOrder, @ItemBegPos, @InputLen)&lt;br /&gt;&lt;br /&gt;      END&lt;br /&gt;&lt;br /&gt;	-- delete the bad items&lt;br /&gt;   DELETE FROM #list_items&lt;br /&gt;   WHERE item_endpos &lt; item_begpos&lt;br /&gt;&lt;br /&gt;   -- return list items&lt;br /&gt;	SELECT SUBSTRING(@list_text, item_begpos, (item_endpos - item_begpos + 1)) AS item_text, item_order, item_begpos, item_endpos&lt;br /&gt;   FROM #list_items&lt;br /&gt;   ORDER BY item_order&lt;br /&gt;&lt;br /&gt;   END&lt;br /&gt;&lt;br /&gt;DROP TABLE #list_items&lt;br /&gt;&lt;br /&gt;RETURN&lt;br /&gt;&lt;br /&gt;/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;SET QUOTED_IDENTIFIER OFF &lt;br /&gt;GO&lt;br /&gt;SET ANSI_NULLS ON &lt;br /&gt;GO&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 24 Feb 2006 04:12:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1563</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>work days between two dates without cycling through dates</title>
      <link>http://snippets.dzone.com/posts/show/808</link>
      <description>I was thinking about how to optimize figuring out the work days between two dates and came up with this function.  It doesn't take into account holidays.  You would have to take out the workdays for holidays from the number if you want to take into account holidays, but that should be easy enough.&lt;br /&gt;&lt;br /&gt;4GL Version&lt;br /&gt;&lt;code&gt; &lt;br /&gt;# workdays&lt;br /&gt;# returns the number of working days between two dates&lt;br /&gt;FUNCTION workdays( dt_begin, dt_end )&lt;br /&gt;&lt;br /&gt;DEFINE&lt;br /&gt;   dt_begin             DATE,&lt;br /&gt;   dt_end               DATE,&lt;br /&gt;   dt_first_sunday      DATE,&lt;br /&gt;   dt_last_saturday     DATE,&lt;br /&gt;   int_workdays         INTEGER&lt;br /&gt;&lt;br /&gt;   # get first sunday&lt;br /&gt;   LET dt_first_sunday = dt_begin + ((7 - WEEKDAY(dt_begin)) MOD 7)&lt;br /&gt;&lt;br /&gt;   # get last saturday&lt;br /&gt;   LET dt_last_saturday = dt_end + ((-1 * (WEEKDAY(dt_end) + 1)) MOD 7)&lt;br /&gt;&lt;br /&gt;   # get work weeks between first sunday and last saturday&lt;br /&gt;   LET int_workdays = (((dt_last_saturday - dt_first_sunday) + 1) / 7) * 5&lt;br /&gt;   &lt;br /&gt;   # if first sunday is not begin date&lt;br /&gt;   IF dt_first_sunday &lt;&gt; dt_begin THEN&lt;br /&gt;&lt;br /&gt;      # assume first sunday is after begin date&lt;br /&gt;      # add workdays from begin date to first sunday&lt;br /&gt;      LET int_workdays = int_workdays + (6 - WEEKDAY(dt_begin))&lt;br /&gt;&lt;br /&gt;   END IF&lt;br /&gt;&lt;br /&gt;   # if last saturday is not end date&lt;br /&gt;   IF dt_last_saturday &lt;&gt; dt_end THEN&lt;br /&gt;&lt;br /&gt;      # assume last saturday is before end date&lt;br /&gt;      # add workdays from last saturday to end date&lt;br /&gt;      LET int_workdays = int_workdays + WEEKDAY(dt_end)  &lt;br /&gt;  &lt;br /&gt;   END IF&lt;br /&gt;&lt;br /&gt;   # return working days&lt;br /&gt;   RETURN int_workdays&lt;br /&gt;&lt;br /&gt;END FUNCTION&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;VBA Version&lt;br /&gt;&lt;code&gt;&lt;br /&gt;' WorkDays&lt;br /&gt;' returns the number of working days between two dates&lt;br /&gt;Public Function WorkDays(ByVal dtBegin As Date, ByVal dtEnd As Date) As Long&lt;br /&gt;&lt;br /&gt;   Dim dtFirstSunday As Date&lt;br /&gt;   Dim dtLastSaturday As Date&lt;br /&gt;   Dim lngWorkDays As Long&lt;br /&gt;&lt;br /&gt;   ' get first sunday in range&lt;br /&gt;   dtFirstSunday = dtBegin + ((8 - Weekday(dtBegin)) Mod 7)&lt;br /&gt;&lt;br /&gt;   ' get last saturday in range&lt;br /&gt;   dtLastSaturday = dtEnd - (Weekday(dtEnd) Mod 7)&lt;br /&gt;&lt;br /&gt;   ' get work days between first sunday and last saturday&lt;br /&gt;   lngWorkDays = (((dtLastSaturday - dtFirstSunday) + 1) / 7) * 5&lt;br /&gt;&lt;br /&gt;   ' if first sunday is not begin date&lt;br /&gt;   If dtFirstSunday &lt;&gt; dtBegin Then&lt;br /&gt;&lt;br /&gt;      ' assume first sunday is after begin date&lt;br /&gt;      ' add workdays from begin date to first sunday&lt;br /&gt;      lngWorkDays = lngWorkDays + (7 - Weekday(dtBegin))&lt;br /&gt;&lt;br /&gt;   End If&lt;br /&gt;&lt;br /&gt;   ' if last saturday is not end date&lt;br /&gt;   If dtLastSaturday &lt;&gt; dtEnd Then&lt;br /&gt;&lt;br /&gt;      ' assume last saturday is before end date&lt;br /&gt;      ' add workdays from last saturday to end date&lt;br /&gt;      lngWorkDays = lngWorkDays + (Weekday(dtEnd) - 1)&lt;br /&gt;&lt;br /&gt;   End If&lt;br /&gt;&lt;br /&gt;   ' return working days&lt;br /&gt;   WorkDays = lngWorkDays&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Oct 2005 23:24:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/808</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
  </channel>
</rss>
