BuiltWithNOF
Code Samples

One of the most important parts of any technical solution is the internal coding documentation and consistent coding practice of the software company.  Reservoir Software has an internal coding convention that ensures that programs in different languages have the same look in feel.

During the first introductory programming course, a developer is asked to write the words “hello world” to a pipe deliminted file.  Listed below are solutions to this problem using the following languages: visual basic, vb script, c language, and java script.  This is a tiny example of the proficiency that are consultants have using these languages.

Visual Basic for Applications

'******************************************************
' Name:    Ms_Access_File()
' Design:
'    Author:  John Miner
'    Date:    01/01/1999
'    Purpose: Create a pipe delimited file.
'******************************************************
'
Public Function Ms_Access_File()

   ' Declare variables
   Dim sPath As String
   Dim iHandle As Integer
      
   ' Delete existing file
   sPath = "c:\ms-access-file.txt"
   If Len(Dir(sPath)) > 0 Then
       Kill sPath
   End If
      
   ' Open output file
   iHandle = FreeFile
   Open sPath For Output Shared As #iHandle
  
   ' Write out data
   Print #iHandle, "Hello|World"
  
   ' Close output file
   Close #iHandle
      
End Functio
n

VB Script

'******************************************************
' Name:    Vb_Script_File()
' Design:
'    Author:  John Miner
'    Date:    01/01/1999
'    Purpose: Create a pipe delimited file.
'******************************************************
'
Sub Vb_Script_File(filespec)
  
   ' Declare variables
   Dim fso
   Dim file
   Dim ForWriting

   ' Create fso object
   Set fso = CreateObject("Scripting.FileSystemObject")

   ' Delete existing file
   If fso.FileExists(filespec) Then
     fso.DeleteFile(filespec)
   End If

   ' Open output file
   ForWriting = 2
   Set file = fso.OpenTextFile(filespec, ForWriting, TRUE)

   ' Write out data
   file.write("hello|world") & vbcrlf

   ' Close output file
   file.close

   ' Release objects
   Set file = nothing
   Set fso = nothing

End Sub

'
' Call the script
'
Vb_Script_File "c:\vb-script-file.txt
"

C Language

//******************************************************
// Name:     C_Lang_File()
// Design:
//     Author:   John Miner
//     Date:     01/01/1999
//     Purpose:  Create a pipe delimited file.
//******************************************************
//

#include <stdlib.h>
#include <stdio.h>

//
// The main function
//

int main()
{
   char data[] = "Hello|World";
   FILE *stream;
  
   // Remove the output file
   if ((input = fopen("c:\\c-lang-file.txt", "r")) != NULL)                         
     x();

   // Open the ouput file, Write to the output file
   if((stream = fopen("c:\\c-lang-file.txt", "w")) == NULL) {
     fprintf(stream, data);
  
   // Close the output file
   fclose(stream);

}
 

Java Script

//******************************************************
// Name:     Java_Script_File()
// Design:
//     Author:   John Miner
//     Date:     01/01/1999
//     Purpose:  Create a pipe delimited file.
//******************************************************
//

function Java_Script_File(FileName)
{
   // Declare Constants
   var TristateFalse = 0;
   var ForWriting = 2;

   // Invoke file system object
   fsObject = new ActiveXObject("Scripting.FileSystemObject");
   fsObject.CreateTextFile(FileName);
   file = fsObject.GetFile(FileName);

   // Create text file
   text = file.OpenAsTextStream(ForWriting, TristateFalse);
   text.Write("Hello|World");
   text.Close();
};

//
// Call the script
//
Java_Script_File ("c:\\js-script-file.txt");

 

[Home] [Services] [Products] [Partners] [Contact Us]

Last Updated 12.29.04