CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Is anybody capable of providing me with guidance, not opinions?

    First, an opinion is also guidance

    Second, have a look at this article :

    Working with Hashtables in .NET
    http://www.codeguru.com/columns/vb/w...es-in-.net.htm

    It explains how to use Hashtables

    Then, have a look at this code :

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    using System.Collections; //The System.Collections namespace contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hashtables and dictionaries.
    
    
    namespace CellNumber_Converter
    {
        public partial class Form1 : Form
        {
            private Hashtable htPhoneNumbers = new Hashtable(); //hashtable to store keys + numbers
            private string strNumber;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                strNumber = textBox1.Text.ToUpper(); //convert entered text to uppercase
    
                foreach (char c in strNumber) //Loop through entered text
                {
                    string digit = c.ToString(); //Convert to string
    
                    if (htPhoneNumbers.ContainsKey(digit)) //if Entered text is any of the keys
                    {
                        label1.Text += htPhoneNumbers[digit]; //add to label
                       
    
                    }
                }
            }
    
            private void Form1_Load(object sender, System.EventArgs e)
            {
                htPhoneNumbers["A"] = "2"; //Store the word "2" inside the hashtable at location "A"  etc.
                htPhoneNumbers["B"] = "2";
                htPhoneNumbers["C"] = "2";
    
                htPhoneNumbers["D"] = "3";
                htPhoneNumbers["E"] = "3";
                htPhoneNumbers["F"] = "3";
    
                htPhoneNumbers["G"] = "4";
                htPhoneNumbers["H"] = "4";
                htPhoneNumbers["I"] = "4";
    
                htPhoneNumbers["J"] = "5";
                htPhoneNumbers["K"] = "5";
                htPhoneNumbers["L"] = "5";
    
                htPhoneNumbers["M"] = "6";
                htPhoneNumbers["N"] = "6";
                htPhoneNumbers["O"] = "6";
    
                htPhoneNumbers["P"] = "7";
                htPhoneNumbers["Q"] = "7";
                htPhoneNumbers["R"] = "7";
                htPhoneNumbers["S"] = "7";
    
                htPhoneNumbers["T"] = "8";
                htPhoneNumbers["U"] = "8";
                htPhoneNumbers["V"] = "8";
    
                htPhoneNumbers["W"] = "9";
                htPhoneNumbers["X"] = "9";
                htPhoneNumbers["Y"] = "9";
                htPhoneNumbers["Z"] = "9";
            }
        }
    }
    Fourth, have a lookm at the attachment.

    Fifth, Read the abovementioned article properly, else, this post helps you nothing - yes, it gives you the answer, but you will not learn anything from it if you don't do some research...
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured