Click here to Skip to main content
15,890,123 members
Articles / Programming Languages / Visual Basic

Phone Index

Rate me:
Please Sign up or sign in to vote.
2.00/5 (1 vote)
21 Feb 2011CPOL1 min read 24.3K   507   8   6
This is a program for phone index to see how we can use the alphabetical English characters (A..Z) to search a customer name which begin with any character.

Introduction

I wrote an article earlier to create Array of PictureBox and wrote another article to create Array of Label and TextBox controls. You can also read the easy code to create Array of twenty-six buttons for alphabetical English characters A..Z. Now, in this article, I shall use the twenty-six buttons idea to write a program for phone index to see how we can use the alphabetical English characters (A..Z) to search a customer name which begins with any character, also you can read about some methods of ADO.NET.

Background

I create two projects, I write code of one under C# and write another under VB. The code in this article will be under C#, you can read my two projects after you expand the files:

  • MyPhone_C#.zip
  • MyPhone_VB.zip

Using the Code

C#
// Create and set (26) buttons for English Characters:

private void CreateButtons()
{
    int xPos = 0;
    int yPos = 0;
    // assign number of buttons = 26
    btnArray = new System.Windows.Forms.Button[26]; 
    // Create (26) Buttons:
    for (int i = 0; i < 26; i++)
    {
        // Initialize one variable
        btnArray[i] = new System.Windows.Forms.Button(); 
    }
    int n = 0;
    while(n < 26)
    { 
        btnArray[n].Tag = n + 1; // Tag of button
        btnArray[n].Width = 24; // Width of button
        btnArray[n].Height = 20; // Height of button
        if(n == 13) // Location of second line of buttons:
        {
            xPos = 0;
            yPos = 20;
        }
        // Location of button:
        btnArray[n].Left = xPos; 
        btnArray[n].Top = yPos; 
        // Add buttons to a Panel:
        panel1.Controls.Add(btnArray[n]); // Let panel hold the Buttons
        xPos = xPos + btnArray[n].Width; // Left of next button
        // Write English Characters:
        btnArray[n].Text = ((char)(n + 65)).ToString();
        // the Event of click Button:
        btnArray[n].Click += new System.EventHandler(ClickButton);
        n++;
    }
}
C#
// Result of the event click Button, get the text of button and find record: 

private void ClickButton(Object sender, System.EventArgs e)
{
    Button btn = (Button) sender;
    string strFind = btn.Text + "%";
    string strSql = "SELECT * FROM Phone WHERE [Name] LIKE " + 
       "'" + strFind + "'" + " Order by Name";

    FindAnyName(strSql); //using (DataReader) to find records
}

Remarks

After you extract the files (*.zip), you can read the remaining code about using ADO methods and see the result when running the program.

Final Words

I hope this article is useful. If you have any ideas, please tell me. Thanks to CodeProject and thanks to all.

Mostafa Kaisoun
m_kaisoun@hotmail.com

History

  • 21st February, 2011: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Egypt Egypt
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionTip/Trick Pin
Aydin Homay16-Sep-13 2:33
Aydin Homay16-Sep-13 2:33 
QuestionSql Server version? Pin
Member 96591405-Jan-13 12:51
Member 96591405-Jan-13 12:51 
GeneralParameters. Pin
jw12321-Feb-11 22:30
jw12321-Feb-11 22:30 
GeneralRe: Parameters. Pin
Mostafa Kaisoun22-Feb-11 11:54
Mostafa Kaisoun22-Feb-11 11:54 
GeneralLayout. Pin
Jefis21-Feb-11 22:09
Jefis21-Feb-11 22:09 
GeneralRe: Layout. Pin
Mostafa Kaisoun22-Feb-11 11:54
Mostafa Kaisoun22-Feb-11 11:54 

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.