Try adding '{ }' and 'return':
. . .
if (cmbPort.Text == "")
{
MessageBox.Show("Please Select Port");
return;
}
. . .
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello to All Helper I make a small project that runs windows form with a serial port select and run a command all good but when I add if and else to this form I get error
this is the project
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO.Ports;
namespace Daniel_Mouyal____Ultimate_Tool
{
public partial class Samsung_Factory_Reset : Form
{
public Samsung_Factory_Reset()
{
InitializeComponent();
getallports();
}
void getallports()
{
string[] ports = SerialPort.GetPortNames();
cmbPort.Items.AddRange(ports);
}
private void guna2Button1_Click(object sender, EventArgs e)
{
cmbPort.Text = "";
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnFactoryReset_Click(object sender, EventArgs e)
{
if (cmbPort.Text == "")
MessageBox.Show("Please Select Port");
else
{
}
System.IO.Ports.SerialPort sport = new System.IO.Ports.SerialPort(cmbPort.Text, 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
try
{
sport.Open();
sport.Write("AT+FACTORST=0,0\r\n");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
sport.Close();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
this is the error that I get
Try adding '{ }' and 'return':
. . .
if (cmbPort.Text == "")
{
MessageBox.Show("Please Select Port");
return;
}
. . .
Thanks it's work you are really help me