jeudi 30 septembre 2021

All the if statements running in c#?

I have some code below which is a URL Parser and the if statement doesn't work instead of executing the code when it is true it executes all the code in all the if statements.

    public static class var
    { //Global variables
        public static string stre = System.Uri.UnescapeDataString(Environment.CommandLine);
        public static string[] str = stre.Remove(stre.Length - 1).Split(new string[] { "cmd:" }, StringSplitOptions.None);
    }
    public CMD()
    { //I suppose this class runs first so all my is statements are here
        AClsMsgBox.Show("Parsing...", "CMD Parser", 1000); //msgbox
        if (var.stre.Length > 5) { InitializeComponent();} //This executes even if I type "cmd:" which should trigger the statement below. (Always executes) This should run when typing "cmd:echo a command"
        if (var.stre.Length == 4) { Process.Start("cmd.exe"); } //This should run when typing "cmd:"(Never executes)
        else { AClsMsgBox.Show("This is a URL Parser use it by typing 'cmd:<command>' in the url field of a browser.","CMD Parser",60000); } //Always executes
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        string stra = var.str[1].Replace("&", "&&");
        label1.Text += stra;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Process.Start("cmd.exe", " /k " + var.str[1]);
        this.Close();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
    }
    private void label1_Click(object sender, EventArgs e) { }
}

This is C# GUI so I am running InitializeComponent() only if I need to display the rest of buttons and stuff. (I think it should stop the GUI)

And there are no errors! But appear after building the code.

Aucun commentaire:

Enregistrer un commentaire