Click here to Skip to main content
16,005,056 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
Thanks Guys. i just discovered my problem.
i Declared decimal Price = .00m;
for the txtTotalSales.Text to be parsed, the .00 becomes a problem. am just grateful for the coperation u guys have shown me so far.

Now am unto the next level and this is about the second question i posed before. Please check the code below and tell me what to do.


***************************************************************
*********************************************************************

<pre>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 &amp;lt; 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 &amp;lt; this._dataArray.Count; i++)
{
string name = this._names[i];
Table.Columns.Add(name);
List&amp;lt;object&amp;gt; objectNumbers = new List&amp;lt;object&amp;gt;();
foreach (string number in this._dataArray[i])
{
objectNumbers.Add((object)number);
}
while (Table.Rows.Count &amp;lt; objectNumbers.Count)
{
Table.Rows.Add();
}
for (int a = 0; a &amp;lt; objectNumbers.Count; a++)
{
Table.Rows[a][i] = objectNumbers[a];
}
}
return Table;
}
</pre>
Thanks
Posted
Updated 15-Jun-11 21:14pm
v7
Comments
Sergey Alexandrovich Kryukov 13-Jun-11 2:53am    
Tag it! WPF, Forms, ASP.NET, what?!
--SA
Morl99 14-Jun-11 5:14am    
For future reference, put your code inside a code block (<pre></pre>) that makes it readable to us!
Morl99 15-Jun-11 17:44pm    
Are you at all able to learn? Use a code block or don't expect any help. My 1
Valentine 2 16-Jun-11 3:17am    
PLEASE AM SORRY FOR NOT SEEING YOUR FIRST COMMENT, BUT AM TOTALLY NEW TO THIS SITE. EVEN AS I HIGHLIGHTED THE WHOLE CODES AND CLICKED ON THE CODE BLOCK, IT APPEARED THE SAME.

Firstly, you need to keep TotalPrice not as a string, but as a number of some form: int, float, decimal - one of those is probably what you want. You can then add the new ordered item price into it, and set the TextBox appropriately:
txtTotalPrice.Text = TotalPrice.ToString();


Secondly, you need to explain in better detail what you are trying to do - I can't work out from that description what you are trying to achieve.
 
Share this answer
 
Hello Dear
Sorry,i read your question but i did not understand it,i think this is a very very easy problem , if you send a more complete question and code i can answer you easily
 
Share this answer
 
Comments
Valentine 2 13-Jun-11 13:10pm    
i just want to continually add new price values to old one in a TotalPrice textBox as the new items are being bought, not concatenating or appending to the old value. thanks.
Your information is still confusing, I give it a shot though:
C#
Price += Check[i];
//TotalPrice = Price.ToString("c"); //seems unnessecary now
//Parse the Price in the textbox
double dOldTotalPrice = Double.Parse(txtTotalPrice.TextTotalPrice);
//Add the new price to the old total
double dNewTotalPrice = dOldTotalPrice + Price; //Assuming Price is a number?
//Print the price into the TextBox
txtTotalPrice.Text = dNewTotalPrice.ToString("c")



I guess you have to adapt this a little, but I hope it helped push you in the right direction. Follow up questions are of course welcome (add a Comment under this for quick questions, if you have new code, please edit your original question and post a comment about it so I get notified).
 
Share this answer
 
Hi
you can use Convert.ToDouble("price") Then add the new price.
 
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