ASP - Writing to text files 22 September 2004 at 00:00
The following code will create a text file called testfile.txt in the root of the C: drive, overwriting an existing file with the same name.
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objStream = fs.CreateTextFile("c:\testfile.txt", True)
objStream.WriteLine("This is a test.")
Set objStream = Nothing
Set objFS = Nothing
Creating shortcuts using VB6 09 September 2004 at 00:00
In your VB Project, to create a shortcut you need to add a reference to the Windows Script Host Object Model - if this is not available find the file WSHOM.OCX.

Example: create a shortcut to your application on the desktop

    Dim wsShell As IWshShell_Class
    Dim wsShortcut As IWshShortcut_Class
    Set wsShell = New IWshShell_Class
    Set wsShortcut = wsShell.CreateShortcut(wsShell.SpecialFolders("Desktop") + "test.lnk")
    With wsShortcut
        .Arguments = "1 2 3"
        .Description = "test shortcut"
        .IconLocation = "app.exe,1"
        .TargetPath = "C:me.exe"
        .WindowStyle = 3
        .WorkingDirectory = "C:temp"
    End With
    Set wsShortcut = Nothing
    Set wsShell = Nothing
Commerce Server Pipeline Custom Components 08 September 2004 at 00:00

Getting your component running in an existing CS2K pipeline

  1. Install the Visual Basic Pipeline Component Wizard by running regsvr32 on the file
    "C:Program FilesMicrosoft Commerce ServerSDKToolsVB Pipe WizardPipelineCompWizard.dll"
    . Now when you create a new project you will have the option of a Commerce Server Order Pipeline Component.
  2. Create your new component Visual Basic - the code that is executed in your component must go in the IPipelineComponent_Execute method.
  3. Make the DLL.
  4. Run the Pipeline Component Registration Wizard located at
    "C:Program FilesMicrosoft Commerce ServerSDKToolsRegistration Tool" to register the component in the Pipeline Editor.
  5. Open the Pipeline Editor and open the pipeline you want to insert your component into.
  6. Add the stages and components you require and save the pipeline.

Adding custom information into the pipeline for your component

  • Adding information which is then available to your component is not straighforward or intuitive.
  • In the CS2K code you will find a call to RunMtsPipeline passing it a variable called mscsOrderGrp
  • this variable is an Order Group, and contains all the information required for (for example) the ordering process
  • This group contains OrderForm objects which contain header information for an order form.
  • OrderForm objects contain a SimpleList object called Items which contains all the Item dictionaries holding the line item information.
  • to retrieve this SimpleList object :
      Dim objList
      Set objList = mscsOrderGrp.Value.Orderforms("default").Items
  • to add information that your component could use, you could add a simple list item to the OrderForm object:
    Dim objDict
    Dim objList
    Set objList = Server.CreateObject("Commerce.SimpleList")
    Set objDict = Server.CreateObject("Commerce.Dictionary")
    objDict.cc_number = "5222 7676"
    objList.Add objDict
    Set mscsOrderGrp.Value.Orderforms("default").CCInfo = objList
  • then to retrieve the dictionary from inside your VB component:
    Dim objList
    Dim objDict
    Dim strCCNumber
    Set objList = objOrderForm.Value("CCInfo")
    Set objDict = objList(0)
    strCCNumber = objDict.cc_number

Removing custom components from the pipeline

When you remove components from the machine you are running the pipeline on, remember to unregister it first using regsvr32. If you do not do this it will not get removed from the list of available components.
Increasing shell environment space in Windows 9x 08 September 2004 at 00:00
In Windows 9x, the default amount of environment space provided to MS-DOS windows is often too small to run many batch files. To increase the amount of environment space available, do the following:
  1. Click Start, Run and enter sysedit
  2. In the C:CONFIG.SYS window, add the line:
  3. Reboot your system. This should be enough to run most batch files.
HTTP Requests with Java 23 September 2004 at 00:00
import java.util.*;

public class Mine {
  public static void main(String args[]) {

    ObjectInputStream is = null;
    URL url = null;
    String  uri = "http://servername:port/yourservlet";
    HashMap hash = new HashMap();
    try {
      // calling the servlet by passing params
      url = new URL(uri + "?pm1=val1&pm2=val2");
      // open input stream and read the hashmap
      // returned by the servlet
      is = new ObjectInputStream(url.openStream());
      hash = (HashMap) is.readObject();
      // print it out
    catch (Exception e) {
Sending HTTP Requests with .NET 16 September 2004 at 00:00
This code will send a web request via a proxy server and save it to a text file:
  byte[] buf = new byte[8192];
  int count = 0;
  // send the http request
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");
  NetworkCredential cred = new NetworkCredential("username", "password", "DOMAIN");
  request.Proxy.Credentials = cred;
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  Stream resStream = response.GetResponseStream();
  // create the new text file
  FileInfo f = new FileInfo("C:TempTest.txt");
  StreamWriter sw = f.CreateText();
  // read contents of stream into text file
  while ((count = resStream.Read(buf, 0, buf.Length)) > 0) {
    string s = Encoding.ASCII.GetString(buf, 0, count);
  // close streams

Remote authorisation

If your request requires remote authorisation, all you need to do is add the network credentials to the request, for example:

  request.Credentials = new NetworkCredential("username", "password");

Handling response codes

With the above method, anything other than a status of OK (200) will raise an error. If you want to check response codes, do the following:

HttpStatusCode statusCode;
HttpWebResponse response = null;
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/default.asp");
  response = (HttpWebResponse)request.GetResponse();
  statusCode = response.StatusCode;
catch (WebException ex)
  statusCode = ((HttpWebResponse)ex.Response).StatusCode;
  if (response != null) response.Close();

if (statusCode != HttpStatusCode.OK) 
  throw new Exception("Error!");
Automatic Labelling with Visual Source Safe 09 September 2004 at 00:00
Run the following code in a batch file as a scheduled task to automate the labelling of your VSS projects.
REM REMOVE %mytime% if you only want the label to include the date

REM To test on command line only use 1 %
REM =========================================
REM Get the current date (without the Day name)
for /F "tokens=2" %%i in ('date/t') do set mydate=%%i

REM Get the current time
for /F "tokens=1" %%i in ('time/t') do set mytime=%%i

REM echo "Labelling Portal Project:" "%mydate% %mytime%"

REM =========================================

REM Set sourcesafe directory
Set ssdir=\\ctsfps02\Systems\vss

REM Run the sourcesafe labelling command on the Portal Project
"C:\Program Files\Microsoft Visual Studio\VSS\win32\SS.exe" Label -L"%mydate% %mytime%" -C -I- $/<Your Project Name> -Y<username>,<password>
JavaScript setTimeout 16 September 2004 at 00:00
The setTimeout method can be used to create your own running threads in a web document.

For example, to create update a text box every second with a new date/time:

<script language="javascript">
function setDateTime() {
  document.myForm.txtDateTime.value = new Date();
  setTimeout("setDateTime()", 1000);


<body onload="setDateTime()">

Adding parameters

You can add parameters to functions called by setTimeout as follows:

function myFunc(p1, p2) {

var val1 = 'p1value';
var val2 = 'p2value';
setTimeout('myFunc("' + val1 + '","' + val2 + '")', 1000);
Oracle : Converting Hex Strings to Binary 22 September 2004 at 00:00
  @hexstr varchar(1000),
  @binValue binary(8) OUTPUT
  DECLARE @index tinyint,
          @result bigint,
          @digit int,
          @convstr varchar(15)
  SELECT  @index = LEN(@hexstr),
          @result = 0,
          @convstr = '123456789ABCDEF'
  WHILE (@index > 2)
    SELECT @digit = CHARINDEX(SUBSTRING(@hexstr,@index,1),@convstr)
    SELECT @result = @result + @digit * POWER(CONVERT(numeric, 16), LEN(@hexstr) - @index)
    SELECT @index = @index - 1

  SELECT @binValue = CONVERT(binary(8),@result)
Write to a text file using Visual Basic 09 September 2004 at 00:00
The easiest way to write to a text file is the following:
  Dim iFile as Integer
  iFile = FreeFile
  Open "C:tempmyfile.txt" For Append Shared As #iFile
  Print #iFile, "Line one"
  Print #iFile, "line 2"
  Close #iFile

Alternatively, you can use the FileSystemObject, which can be used in your project by creating a reference to the "MicroSoft Scripting Runtime" library.

  ' declare FileSystemObject and TextStream objects
  Dim fsObj As FileSystemObject
  Dim fsStream As TextStream
  ' create new instance of FileSystemObject
  Set fsObj = New FileSystemObject
  ' using FileSystemObject, create a new text stream to your file (specified in strPath)
  Set fsStream = fsObj.CreateTextFile(strPath)
  ' write contents to the file
  fsStream.WriteLine "I am a text file"
  ' close the TextStream and clean up
  Set fsStream = Nothing
  Set fsObj = Nothing
Dynamic WHERE and ORDER BY Clauses in SQL Server 24 September 2004 at 00:00
    FROM MyTable
    Col1 LIKE 
      CASE Col2
        WHEN '1' THEN 'X'
        WHEN '2' then 'Y'
        ELSE 'Z'
    @ColName varchar(100) 
    SELECT Col1, Col2
    FROM Employees
        WHEN @ColName='X' THEN CONVERT(char(50), Col1) + CONVERT(char(50), Col2)
        WHEN @ColName='Y' THEN CONVERT(varchar(50), Col1)
        WHEN @ColName='Z' THEN Z
Solving the Out of environment space issue 08 September 2004 at 00:00
In Windows 9x, the default amount of environment space provided to MS-DOS windows is often too small to run many batch files. To increase the amount of environment space available, do the following:
  1. Click Start, Run and enter sysedit
  2. In the C:CONFIG.SYS window, add the line:
  3. Reboot your system. This should be enough to run most batch files.