Click here to Skip to main content
15,867,830 members
Articles / Programming Languages / C#
Article

FlashCard101

Rate me:
Please Sign up or sign in to vote.
2.43/5 (7 votes)
22 Oct 20031 min read 40.8K   801   11   1
A simple educational flash card program that uses xml files for its word source

Image 1

Introduction

I was taking a Conversational Spanish course last year and a Microsoft course that required a lot of memorization and decided that the best way to learn a little more about C# was to create a Flash card program. The problem with most flash card programs are that you are stuck with their dictionaries and you can not adjust the pace.

Background

The first thing was how would I store the data so that the maximum number of people could use the program with the least amount of software (aka: Access and SQL Server) so I decided to build the data schema in code and then save and open the DataSets as xml files.

This program demonstrates several useful techniques in using the System.Data namespace as well as the slider control and Timer.

Using the code

There are three forms frmAbout contains the version info and copyright notice, frmEditDict which is used to edit the dictionaries, and frmFlash which is the main form and displays the words and definitions.

To create the DataSet for the dictionary I used the following code.

C#
static void initDS()
    {
      //create our schema/table 
      ds=new DataSet("DataSet");
      DataTable dt=ds.Tables.Add("Dictionary");

      DataColumn dc=dt.Columns.Add("ID",typeof(Int32));
      dc.AutoIncrement=true;
      dc.AllowDBNull=false;
      dc.AutoIncrementStep=1;

      //create the primary key
      DataColumn[] keys=new DataColumn[1];
      keys[0]=dc;
      dt.PrimaryKey=keys;
      
      dc=dt.Columns.Add("Word",typeof( String));
      dc.AllowDBNull=false;
      
      dc=dt.Columns.Add("Def",typeof( String));
      dc.AllowDBNull=false;
      
    }

Each time the tick event of the Timer is fired we check a boolean value bDisplayWord if it is true then we select another random word from the dictionary and display it. Then we toggle the bDisplayWord to false and display the definition the next time the Timer is fired.

C#
private void timer1_Tick(object sender, System.EventArgs e)
    {
      
      if(bDisplayWord)
      {// display word
        DataTable dt=ds.Tables[0];
        System.Random rnd=new System.Random();
        currentIndex=(Int32) (rnd.NextDouble()*dt.Rows.Count);
        txtWord.Text=currentIndex.ToString();
        DataRow dr;
        dr=dt.Rows[currentIndex];
        txtWord.Text=dr.ItemArray[1].ToString();
        txtDefinition.Text="";
      }
      else
      {//else display Definition
        txtDefinition.Text = 
           ds.Tables[0].Rows[currentIndex].ItemArray[2].ToString();
      }

      //switch display component
      bDisplayWord = !bDisplayWord;
      
    }

To save and load the DataSet I simply use the save and open dialogs combined with the ReadXml and WriteXml Methods of the System.Data.DataSet class.

Points of Interest

This code was one of my first functional utilities written with C#. It demonstrates several objects of the .NET framework: DataSet, grids, sliders, xml files, Timers, and forms.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I have been programming since 1983 when I first programmed on a HeathKit 8088 Breadboard Computer in machine code. Since then I have dabbled with many things. I am extremely fluent with VB6, Access, Sql Server. I am currently programming a major project in C#.

I am also a system administrator for Unix, Linux, MS 4.0 - 2003 and also dabble with CISCO routers and firewalls.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Member 1104862231-Aug-14 5:25
Member 1104862231-Aug-14 5:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.