Hello hi,
My program is like this,
PLEASE ENTER DESTINATION NUMBER:
( THEN USER INPUTS A SERIES OF NUMBERS LIKE 238947864)

How do i play wav files of dtmf tones corresponding to the numbers given?
i have used swith case, but it doesnt work. Only if one number is entered it plays the corresponding dtmf wav file and exits.

But if i were to enter a series of number like 2873649, the program exits without playing at all.

thanks.
Trinetra

Trin,

You would need to use the same switch concept but store the numbers in an array and loop through each number in the array running the switch statement.

This would allow all numbers to be processed :)

So 238947864 would be processed as:

2 - 3 - 8 - 9 - 4 - 7 - 8 - 6 - 4

The issue lies with the fact the switch currently treats 238947864 as one big number instead of breaking it down into its actual values

Have Wav Files Near The EXE File With Names "1.wav", 2.wav ...

Please Check the Attached zip added for reference..

using System;
using System.IO;
using System.Media;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        SoundPlayer sp = new SoundPlayer();

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            foreach (char c in textBox1.Text)
            {
                listBox1.Items.Add(c);
            }
            listBox1.SelectedIndex = 0;
        }

        private void play(string item)
        {
            try
            {
                sp.SoundLocation = Path.GetFullPath(item + ".wav");
                sp.Play();
            }
            catch (Exception)
            {
                MessageBox.Show("File Not Found");
            }
            listBox1.SelectedIndex++;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                play(listBox1.SelectedItem.ToString());
            }
            catch (Exception)
            {
                MessageBox.Show("Over");
            }
        }
    }
}

Hi all,
thank you so much for the reply. Didnt realise my previous message to thank you didnt get through. so once again thanks Pri and MIkey. lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.