-3

I am trying to make a morse code for a college project, what I'm trying to do is use a 2 dimensional array to save the morse code people input to a text file and then be able to load it from the text file, my logic was to was that within the array was this array[morse name][morse input]. what I need to figure out first is how to send data from methods / buttons OBtn_Clicked , LBtn_Clicked, SBtn_Clicked and EndBtn_Clicked to NewMorseBtn_Clicked to add into the array which will then write it out to a text file I've created.

namespace FlashLightApp2018
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MorsePage : ContentPage
    {
        //bool exitLoop = false;
        public MorsePage()
        {
            InitializeComponent();
        }

        private async void NewMorseBtn_Clicked(object sender, EventArgs e)
        {
            bool isTextEmpty = String.IsNullOrEmpty(MorseName.Text);
            if (isTextEmpty)
            {

            }
            else
            {
                OBtn.IsEnabled = true;
                LBtn.IsEnabled = true;
                SBtn.IsEnabled = true;
                EndBtn.IsEnabled = true;

               // String morseName = MorseName.Text;

                //String[,] morseSave = new String[100,100];

            }
            //File.WriteAllText(morseName, text);
            //while (exitLoop != true)
            //{

            //}

        }

        private void LoadMorseBtn_Clicked(object sender, EventArgs e)
        {

        }

        private void PlayMorseBtn_Clicked(object sender, EventArgs e)
        {

        }

        private void OBtn_Clicked(object sender, EventArgs e)
        {

        }

        private void LBtn_Clicked(object sender, EventArgs e)
        {

        }

        private void SBtn_Clicked(object sender, EventArgs e)
        {

        }

        private void EndBtn_Clicked(object sender, EventArgs e)
        {

        }

    }
}
sedders123
  • 791
  • 1
  • 9
  • 19
danihano
  • 1
  • 1
  • your question is not very clear. What do you expect to happen when the different buttons are clicked? The names you are using - 0Btn, LBtn, etc - are not very descriptive. But in general you probably want your data declared at the class level, not locally to a single method. – Jason Dec 18 '18 at 16:26
  • the Obtn is for a . in morse code, the Lbtn is for a - in morse code and Sbtn is for space. – danihano Dec 18 '18 at 16:30

1 Answers1

0

first, declare you data at the class level (outside of a single method) so that it is accessible from throughout your class

string morseData = string.Empty;

then have your different button methods update the data

private void OBtn_Clicked(object sender, EventArgs e)
{
  morseData += ".";
}

private void LBtn_Clicked(object sender, EventArgs e)
{
  moreseData += "-";
}
Jason
  • 86,222
  • 15
  • 131
  • 146
  • I am not sure if my logic is gonna work this way because I don't know how I'm going to get the array to take in the button clicks into a text file. what I'm trying to do with this code is to give the user the option of inputting the morse code and then when they hit play it would do the equivalent of the morse code in flashes. – danihano Dec 18 '18 at 19:19
  • just read/write the string of dots/dashes to a text file. There is nothing complicated about that. – Jason Dec 18 '18 at 19:20
  • but should I use arrays to read em in? like I can't wrap my head around how I could implement the read into an array. (Sorry for the in-depth questions, its a college project for a module that is not taught by a teacher and this is worth 70%) – danihano Dec 18 '18 at 19:23
  • a string is technically just a byte array. I don't see any particular benefit to using an array if all you need to store is a sequence of "-" and "." – Jason Dec 18 '18 at 19:25
  • ok, ill leave the array then, but will I be able to create a new file everytime someone presses new morse code? So I can save them and call them back for later use. – danihano Dec 18 '18 at 19:27
  • You can create as many files as you want. You're the one writing the program. – Jason Dec 18 '18 at 19:30
  • Sorry, I worded that wrong, I mean is there a code to create a file once the new morse button is clicked so it can be saved in a different file every time? – danihano Dec 18 '18 at 19:32
  • you would need to write that – Jason Dec 18 '18 at 19:33
  • I presume u mean code, is there anywhere I could find the code for it or at least the logic for the code needed to create a file on a button click? – danihano Dec 18 '18 at 19:34