Hello everyone. I'm trying to write a phone number word generator. I have the basic form setup and a dialing pad. The dialing pad dials just like a phone, except it only has keys 2-9. I'm trying to print out all the possibilities a phone number could produce using streamwriter. I can write to a file, but not correctly. This is why I'm here. I'm needing help. I think I need to create an array from the textbox displaying my whole number and use that to write to the file, instead of when a button is clicked it shoots it's values(a,b,c) to the file. Here's my code, any thoughts on this would be greatly appreciated.

`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.IO;

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

    char[] arrayTwo = { 'a', 'b', 'c' };
    char[] arrayThree = { 'd', 'e', 'f' };
    char[] arrayFour = { 'g', 'h', 'i' };
    char[] arrayFive = { 'j', 'k', 'l' };
    char[] arraySix = { 'm', 'n', 'o' };
    char[] arraySeven = { 'p', 'r', 's' };
    char[] arrayEight = { 't', 'u', 'v' };
    char[] arrayNine = { 'w', 'x', 'y', 'z' };
    int[] userInput = new int[8];
    int[] numberInput =new int[8]{2,3,4,5,6,7,8,9};
    int maxLength = 7;

    private void GenerateButton_Click(object sender, EventArgs e)
    {

          // nothing here yet, because i'm currently just using the numbers dialed to generate                        //automatically as each number is dialed(thinking this is wrong to do)         

    }

    private void TwoButton_Click(object sender, EventArgs e)
    {

        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[0]); 
        }

        try
        {
            using (StreamWriter writer = new StreamWriter("F:\\GeneratedWords.txt", true))
            {
                for (int counter = 0; counter < maxLength; counter++)
                {
                    writer.WriteLine("A"); 
                }
                for (int counter = 0; counter < maxLength; counter++)
                {
                    writer.WriteLine("B");
                }
                for (int counter = 0; counter < maxLength; counter++)
                {
                    writer.Write("C");
                }
            }
        }
        catch (UnauthorizedAccessException uAEX)
        {
            MessageBox.Show("You don't have access to the system.");
        }
    }`
    // assume all other buttons are set up the same as above...except with their corresponding            //letters(3-DEF, 4-GHI, etc)

i didn't use my char arrays because i was simply testing the writer.

i think I've figured it out, thank you. If i have any more trouble I'll come back.

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.IO;

namespace TextFromNumbers
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
char[] number2 = { 'A', 'B', 'C' };
char[] number3 = { 'D', 'E', 'F' };
char[] number4 = { 'G', 'H', 'I' };
char[] number5 = { 'J', 'K', 'L' };
char[] number6 = { 'M', 'N', 'O' };
char[] number7 = { 'P', 'R', 'S' };
char[] number8 = { 'T', 'U', 'V' };
char[] number9 = { 'W', 'X', 'Y', 'Z' };

    int[] numberInput = new int[8] { 2, 3, 4, 5, 6, 7, 8, 9 };
    int maxLength = 7;
    Char[] phoneArray = new Char[7];


    //Convert phoneNumber string to array of characters
    public void ConvertNumber()
    {
        String phoneNumber = EnteredNumberTextBox.Text;
        for (int i = 0; i < phoneNumber.Length; i++)
        {
            phoneArray[i] = phoneNumber.ElementAt(i);
        }

    }

    private void GenerateButton_Click(object sender, EventArgs e)
    {
        try
        {
            using (StreamWriter writer = new StreamWriter("F:\\log.txt", true))
            {
                writer.WriteLine("");
            }
        }
        catch (UnauthorizedAccessException uAEX)
        {
            MessageBox.Show("You don't have access to the system.");
        }
            MessageBox.Show("Wrote to file");
    }

    private void TwoButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[0]);
        }
        else
        {
            //do nothing
        }
    }

    private void ThreeButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[1]);
        }
        else
        {
            //do nothing
        }
    }

    private void FourButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[2]);
        }
        else
        {
            //do nothing
        }
    }

    private void FiveButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[3]);
        }
        else
        {
            //do nothing
        }
    }

    private void SixButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[4]);
        }
        else
        {
            //do nothing
        }
    }

    private void SevenButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[5]);
        }
        else
        {
            //do nothing
        }
    }

    private void EightButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[6]);
        }
        else
        {
            //do nothing
        }
    }

    private void NineButton_Click(object sender, EventArgs e)
    {
        if (EnteredNumberTextBox.TextLength < maxLength)
        {
            EnteredNumberTextBox.Text += Convert.ToString(numberInput[7]);
        }
        else
        {
            //do nothing
        }
    }


}

}

this code still doesn't work, and I am still a bit lost, am I going in the right direction or am I really off base here?

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.