OK THIS IS WHAT HAPPENED:
decimal Price = 0m;
string TotalPrice = "";
if (boxes[i].Checked == true)
{
select += SecondMenuList[i].ToString() + " : " + "\t\t" +
Check[i].ToString("c") + "\r\n";//THIS GOES TO THE MESSAGE BOX
Price += Check[i];
TotalPrice = Price.ToString("c");//THIS ONLY SHOWS CURRENT PRICE VALUES
TotalSales.Text = TotalPrice;//THIS IS NOT NECESSARY, DON'T EVEN DO IT YET.
txtTotalPrice.Text = (String.IsNullOrEmpty(txtTotalPrice.Text)? Price:
(Int32.Parse(txtTotalPrice.Text) + Price)).ToString("DON'T ADD CURRENCY
FORMAT");//SO THAT THE STRING CAN BE CONVERTED BACK TO DECIMAL
//TO ADD THE NEW Price TO IT, RECONVERT TO STRING AND DISPLAY IN THE
//TotalSales TEXTBOX
}
WHEN YOU DECLARE DECIMALS WHOSE VALUES WOULD BE ASSIGNED TO EACH OTHER, LEAVE
ALL OF THEM IN THE SAME FORMAT. EG: decimal TotalPrice = 0m; decimal Price = 0m;
NOT decimal TotalPrice = .00m; AND decimal Price = 0m;
*****PLEASE THE SECOND QUESTION IS STILL HANGIN**************
sealed class SerialPortDataRead//for serial port communication
{
// Create the serial port with basic settings
private readonly SerialPort port = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
private readonly Form1 form1;
public SerialPortDataRead(Form1 form1)
{
// TODO: Complete member initialization
this.form1 = form1;
}
public SerialPortDataRead()
{
// TODO: Complete member initialization
}
private void Serial()
{
//beep the default system sound to indicate an incoming data
SystemSounds.Beep.Play();
// Attach a method to be called when there is data waiting in
//the port's buffer
port.DataReceived += port_DataReceived;
// Begin communications
port.Open();
// Enter an application loop to keep this thread alive
Application.Run();
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{ // Arrange the incoming data in an array
string[] PortVal = { port.ReadExisting() };
double[] Check = new double[6]
{120, 120, 100, 100, 150, 100};//this is the price array
string[] SecondMenuList = new string[6]
{"Screw Driver", "Tape", "Glue", "Marker", "Halogen"};//this the mainarray
string FirstSelection = "";
string value = "";
using (Form1 frm = new Form1())
{
string[] c = { "1", "2", "3", "4" };
for (int i = 0; i < 3; i++)
if (PortVal[i] == SecondMenuList[i])//this is where the
//problem lies
// I want to only compare the first three letters of each elements in PortVal at
//any index with the first three letters of the elements in the
//SecondMenulist array. but i can only compare the elements
//what should i do here PLEASE?
{
FirstSelection += String.Format("{0}\t:{1:c}\r\n",
SecondMenuList[i], Check[i]);
value = Check[i].ToString("c");
if (PortVal.Contains(c[i]))
{
//after the comparison, if there is any match, add the matched element
//in the SecondMenuList array to the DataGrid Table (named Table)
this.form1._names.Add("TABLE");
this.form1._dataArray.Add(new string[] { c[i] });
}
this.form1._names.Add("ITEM");
this.form1._dataArray.Add(new string[] { SecondMenuList[i] });
this.form1._names.Add("PRICE");
this.form1._dataArray.Add(new string[] {
Check[i].ToString("c") });
}
frm.txtTotalSales.Text = value;
}
DateTime Date = new DateTime();
Date = DateTime.Now;
PrinterHelper.SendStringToPrinter(String.Format("Order(s)\r\n\n\t{0}\t:{1}
\r\n\n\t{2}",
FirstSelection,
value,
Date));
}
}
public Form1()
{
InitializeComponent();
dataGridView1.DataSource = GetResultsTable();
}
public Form1(TextBox txtTotalSales)
{
// TODO: Complete member initialization
this.txtTotalSales = txtTotalSales;
}
private static SerialPortDataRead port_DataReceived()
{
throw new NotImplementedException();
}
public DataTable GetResultsTable()
{
DataTable Table = new DataTable();
for (int i = 0; i < this._dataArray.Count; i++)
{
string name = this._names[i];
Table.Columns.Add(name);
List<object> objectNumbers = new List<object>();
foreach (string number in this._dataArray[i])
{
objectNumbers.Add((object)number);
}
while (Table.Rows.Count < objectNumbers.Count)
{
Table.Rows.Add();
}
for (int a = 0; a < objectNumbers.Count; a++)
{
Table.Rows[a][i] = objectNumbers[a];
}
}
return Table;
}
try this