Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please bear with me, I am coming from a VB environment to Visual C# (2010 express).
I am having a problem with understanding how to call a class if a radio button is checked then a cmdRun_Click is pressed. Can it be called/instantiated this way?

See the else if (rdoBDS.Checked) line.

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            //_items.Add("MicroStation");
            //_items.Add("Road");
            //_items.Add("Photo");
            //_items.Add("Field");
            //_items.Add("BDS");

            //listBox1.DataSource = _items;
        }
        private void cmdExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        List<string> _items = new List<string>();

        private void cmdRun_Click(object sender, EventArgs e)
        {
            if (rdoMicroStation.Checked)
                _items.Add("MicroStation - Edit Icon Properties to switch departments, Bridge is the default.");

            //MessageBox.Show("Mstn Selected");
            else if (rdoRoad.Checked)
                _items.Add("Road Design Icons V7V8, V8, and Modeler");

            else if (rdoPhotoSurvey.Checked)
                _items.Add("Photos and Survey Icons V7V8, V8 and Land Surveyor");

            else if (rdoField.Checked)
                _items.Add("Field = Road and Photo-Survey and Land Surveyor Icons");

            else if (rdoBDS.Checked)
                _items.Add("Bridge Deck Survey Icons and database setup");
            BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();

            listBox1.DataSource = _items;
            //Change the DataSource
            listBox1.DataSource = null;
            listBox1.DataSource = _items;
        }

        private void rdoBDS_CheckedChanged(object sender, EventArgs e)
        {

        }

    }
}

public class BridgeDeckSurvey

{
    public static void BDSReg(string[] args)
    {
        string filePath = "O:\\cad_std\\configs\\_Select_A_setup\\Setup_08_11_XP_Win7\\bds_odbc_xp.reg";
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = filePath;
        proc.Start();
        goto AppendIni;

    AppendIni:
        try
        {
            StreamWriter sw = new StreamWriter("C:\\Windows\\odbc.ini");
            sw.WriteLine("BDS=Microsoft Access Driver (*.mdb, *.accdb) (32 bit)");
            sw.Close();
        }
        catch (IOException e)
        {
            Console.WriteLine("An IO Exception Occurred:" + e.Message);
        }
        finally
        {
            Console.WriteLine("Finished");
        }
    }

}
Posted
Comments
Sergey Alexandrovich Kryukov 30-Apr-12 18:13pm    
What do you mean by "call a class"? Only a method or a property can be called (I mean property getter or setter, which are also methods).
And what's the problem?
--SA

I used part of the solution from Thilina but my question was as Mazen explained it. Here is what I ended up using which does call the class now. The last line was commented out as it produced an error. I was missing the string on my attempts, I was using BridgeDeckSurvey.BDSReg(); which never worked.

Thank you for your help! Awesome!

else if (rdoBDS.Checked)
    {
        _items.Add("Bridge Deck Survey Icons and database setup");
        string[] KickItOff = new string[1];
        BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();
        BridgeDeckSurvey.BDSReg(KickItOff);
        //bdsstuff.BDSReg(KickItOff);
    }
 
Share this answer
 
I think you mean that the class after if sentence is not called , right ?
well if that:
be aware that C# is take just one condition after 'if' If you don't add brackets '{ ...; }

so just change the add the brackets after last 'if'.

C#
else
{
 if (rdoBDS.Checked)
     {
     _items.Add("Bridge Deck Survey Icons and database setup");
     BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();
     }
}


Let me know if that is your question !
regards
 
Share this answer
 
try your else part like this

C#
else if (rdoBDS.Checked)
{
 _items.Add("Bridge Deck Survey Icons and database setup");
 BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();//this way you can instantiated
 BridgeDeckSurvey.BDSReg(your_string_array_name);//this way you can called a static method 
bdsstuff.BDSReg(your_string_array_name);//this way you can called a normal method 
}


In C# use open { and closing } correctly otherwise your expected solution will not come.

I hope this will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900