( Index )
Month

Brief Information about the Sept '04 CSIG Meeting

A Simple Mailing List

B. Arnold

Mailing List

Welcome back to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a discussion about the MFC Programming using Microsoft Visual C++ version 6.0.

A friend asked me about a program that I had written about 10 years ago. He wanted to use it to collect names and addresses for his organization. After a little digging, I found the 16 bit DOS program which used DOS Paradox (Remember?) libraries to create the database. I decided to rewrite the program using MFC, Microsoft Foundation Classes, and Visual C++.

The program creates a fixed block text file ( maillist.txt ) that can be imported into any spread sheet program such as Excel as well as any database program. The application basically has only two functions:

a) you may step through the database without editing
b) you may add records at the end

The file record format is "fixed block with CR/LF". See DoDataExchange() for size definitions. When program starts, read DATABASEFILE from the current folder. If it doesn't exist, create it. Then read the records and parse the last record into fields. Finally, display the last record with it's record number.

Respond to data entry and NEXT and PREVIOUS buttons. If "dirty" flag, go to data location on disk and write record. Hit the NEW button to create a blank record.

The beginning of the evening (starting at 7:30pm) will be a RANDOM ACCESS discussion. The main presentation will present the program.

As always, you can download this month's code from the ACGNJ ftp server at [ftp://ftp.acgnj.org/pub/acgnj/cug]. The ftp site has code and programs from past meetings too.

Sample Code

void CMl1Dlg::DoReadData()
    {
    int len[] = { 25,25,30,30,25,2,10,30 };     int offset = 0;
    CString sLine;
    mFile.Seek(currentRecord * recSize, CFile::begin);
    mFile.ReadString(sLine);
    m_curRec.Format("%lu",currentRecord+1);
    m_lastname  = sLine.Mid(offset,len[0]);     offset += len[0];
    m_firstname = sLine.Mid(offset,len[1]);     offset += len[1];
    m_addr1     = sLine.Mid(offset,len[2]);     offset += len[2];
    m_addr2     = sLine.Mid(offset,len[3]);     offset += len[3];
    m_town      = sLine.Mid(offset,len[4]);     offset += len[4];
    m_state     = sLine.Mid(offset,len[5]);     offset += len[5];
    m_zipcode   = sLine.Mid(offset,len[6]);     offset += len[6];
    m_email     = sLine.Mid(offset,len[7]);
    UpdateData(FALSE);      // Move data to the screen
    }
	
void CMl1Dlg::OnRecordPrev() 
    {
    if (dirty)  { DoWriteData();  dirty = FALSE; }
    if (currentRecord > 0) --currentRecord;
    DoReadData();   
    m_nextButton.EnableWindow(TRUE);
    if (currentRecord == 0) m_prevButton.EnableWindow(FALSE);
    }

void CMl1Dlg::OnRecordNew() 
    {
    if (dirty)  { DoWriteData();  dirty = FALSE; }
    currentRecord = nRecords;
    ++nRecords;
    dirty = TRUE;
    m_curRec.Format("%lu",currentRecord+1);
    DoBlankRecord();
    m_prevButton.EnableWindow(TRUE);
    m_nextButton.EnableWindow(FALSE);
    m_lastname_c.SetFocus();
    }

void CMl1Dlg::DoBlankRecord()
    {
    m_lastname.Empty();
    m_firstname.Empty();
    m_addr1.Empty();
    m_addr2.Empty();
    m_town.Empty();
    m_state.Empty();
    m_zipcode.Empty();
    m_email.Empty();
    UpdateData(FALSE);      // Move data to the screen
    }

"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page