0

Sorry for the noob question, I am teaching myself c#.

I want to be able to call a class into a form but it requires some form of parameter and I am not sure what it means.

public partial class AtpTester2 : Form
{
    TestLauncher tLaunch = new TestLauncher();
    OpenFileDialog openFileDialog = new OpenFileDialog();
    string browser;

    public AtpTester2()
    {
        InitializeComponent();
    }

    private void UrlFilePickerBtn_Click(object sender, EventArgs e)
    {
        var fileContent = string.Empty;
        var filePath = string.Empty;

        openFileDialog.InitialDirectory = Application.StartupPath;
        openFileDialog.Filter = "txt files (*.txt)|*.txt|All Files (*.*)|*.*";
        openFileDialog.FilterIndex = 2;
        openFileDialog.RestoreDirectory = true;

        if(openFileDialog.ShowDialog() == DialogResult.OK)
        {
            filePath = openFileDialog.FileName;

            var fileStream = openFileDialog.OpenFile();
            StreamReader reader = new StreamReader(fileStream);
            fileContent = reader.ReadToEnd();
        }
        MessageBox.Show(fileContent, "URLs to test:", MessageBoxButtons.OK);
        tLaunch.OpenBrowser();
    }

    
}

This is the error message I am getting:

CS7036 There is no argument given that corresponds to the required formal parameter 'browserType' of 'TestLauncher.TestLauncher(string)' AtpSelenium C:\Coding\ATP\AtpSelenium2\AtpSelenium\AtpTester2.cs

I have tried adding browserType into the = new TestLauncher() section but it still gives an error.

1
  • Can you post the error you get when you add the browserType into the TestLauncher constructor? Commented Aug 28, 2020 at 17:07

2 Answers 2

1

TestLauncher class has a TestLauncher method which was defined with a parameter browserType variable is of type string. When this method is called again it would expect a string to passed in the method when its called. Ex: TestLauncher.TestLauncher(chrome); If you don't want this parameter to be passed everytime; method overloading could be setup for the method where its defined.

More resources about method overloading could found here:

-https://www.c-sharpcorner.com/UploadFile/0c1bb2/method-oveloading-and-overriding-C-Sharp/

-https://www.geeksforgeeks.org/c-sharp-method-overloading/

In your case; you could have another constructor for Testlauncher method inside the class file for Testlauncher. Ex: public Testlauncher() { /* Have the same method as previous testlauncher method or modified method definition */ }

Sign up to request clarification or add additional context in comments.

1 Comment

To keep the terms clean: this is not a method, it is a constructor
1

Constructor of your class TestLauncher need argument "BrowserType"

public partial class AtpTester2 : Form
{
   
   TestLauncher tLauncher = new TestLauncher(browserType.name);

}

or

public partial class AtpTester2 : Form
{
   
   TestLauncher tLauncher = new TestLauncher(someString);

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.