Letters to the Editor

Year 2000 Fix
by Justin Gale

Listing One
Private Sub Command1_Click()
Dim Test_Date As Date
Dim Test_Text As String
    Test_Date =3D Now
    Label1.Caption =3D Format(Date, "Long Date")
    Test_Text =3D Format(Date, "Short Date")
    Test_Date =3D CDate(Test_Text)
    Label2.Caption =3D Format(Date, "Short Date")
    Label3.Caption =3D Date
    Label4.Caption =3D Format(Now, "Long Date")
    Label5.Caption =3D Format(Now, "Short Date")
    Label6.Caption =3D Now
    Label7.Caption =3D Format(Test_Date, "M/d/yyyy")
    Label8.Caption =3D DateDiff("m", "10/08/1998", Test_Date)
End Sub
Private Sub Form_Load()
    txt1 =3D "Format(Date,Long Date)"
    txt2 =3D "Format(Date,Short Date)"
    txt3 =3D "Date"
    txt4 =3D "Format(Now,Long Date)"
    txt5 =3D "Format(Now,Short Date)"
    txt6 =3D "Now"
    txt7 =3D "Variable set Long Date-yyyy format"
    txt8 =3D "DateDiff(m,10/08/1998," & Test_Date & ")"
    Command1_Click
End Sub

DebugAPI
by Robert Stafford

Listing Two
int threadMain()
{
 DbgPrint dbg;
    ...
 dbg << "Thread[" << std::setw(4) << ::GetCurrentThreadId() << "] Starting.";
    ...
}

Listing Three
#ifndef DBGPRINT
#define DBGPRINT
// A simple class to wrap calls to OutputDebugString(). It can be used
// like a stream--it understands how to format anything you can pass to
// cout. The dtor flushes the accumulated string. If you wish to put
// several messages using the same object, the flush() member function
// will output the accumulated string and start again with an empty
// one. The clear() member function will discard any pending string.

#if defined(_DEBUG) || defined(DEBUG)

#ifndef _WINDOWS_
#include <windows.h>
#endif

#include <iostream>
#include <sstream>
#include <iomanip>

class DbgPrint
{
        // Don't allow these
        DbgPrint(const DbgPrint &rhs);
        DbgPrint& operator=(const DbgPrint &rhs);
        std::ostringstream* myStream;
        void out()
        {
                std::string s = myStream->str();
                OutputDebugStringA(s.c_str());
        }
public:
        DbgPrint() {myStream = new std::ostringstream;}

        void clear() {delete myStream;myStream = new std::ostringstream;}
        void flush()
        {
                out();
                clear();
        }
        template<class I>
        DbgPrint& operator << (const I& i)
       {
                (*myStream) << i;
                return *this;
        }
        ~DbgPrint()
        {
                out();
                delete myStream;
        }
};
#else
class DbgPrint
{
        DbgPrint(const DbgPrint &rhs);
        DbgPrint& operator=(const DbgPrint &rhs);
        void out() {}
public:
        DbgPrint() {}
        void clear() {}
        void flush() {}
        template<class I>
        DbgPrint& operator << (const I&) {return *this;}
        ~DbgPrint() {}
};
#endif
#endif


DDA and Fast Image Scaling
Oleg Kiselyov

Example 1:

Initialize the differential to 1/scale;
Initialize the accumulated_differential to 0;
Get the first original pixel;
Do
  Copy original_pixel to next_resized_pixel;
  if (int)(accumulated_differential + differential) > 
    (int)accumulated_differential then
       Get next original pixel;
  accumulated_differential += differential;
while there are unprocessed original pixels.

Example 2:

Initialize the differential to the_number_of_original_pixels;
Initialize the accumulated_differential to 0;
Get the first original pixel;
Do
  Copy original_pixel to next_resized_pixel;
  accumulated_differential += differential;
  if all pixels are processed exit;
  while accumulated_differential >= the_number_of_output_pixels do
     accumulated_differential -= the_number_of_output_pixels;
     Get next original pixel;
  done
done


1


