|
hello, thanks -
Iam trying to get the values of all textboxes and then adding it in totaltextbox but currently it takes only current textbox and when it leaves to 2nd it forgets the first one.
Any help please?
private void textBoxes_TextChanged(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if (tb != null)
{
decimal temp = 0;
if (decimal.TryParse(tb.Text, out temp))
{
if (temp > 1)
MessageBox.Show("Please enter the nnumber between 0 and 1.");
}
}
}
private void textBoxes_Leave(object sender, System.EventArgs e)
{
decimal total = 0;
TextBox tb = sender as TextBox;
if (tb != null)
{
decimal temp = 0;
if (decimal.TryParse(tb.Text, out temp))
{
total += temp;
totalTimetxtBox.Text = total.ToString();
}
}
}
|
|
|
|
|
None of this code should be in the event handlers.
This stuff should be in its own method, called by the events handlers so you're not duplicating code all over the place.
Your addition code should be getting the values of all the textboxes it needs to and adding them together, not just the one where the focus left the textbox or had the textbox value changed.
It's "forgetting" the previous value because your total value is being reset to 0 every time the event handlers are called. Variables declared in a method only exist in that method and are destroyed when execution leaves the method.
|
|
|
|
|
Hi All,
I'm reading back some data from a board most of the time it gives it back correctly and I am displaying in a rich text box. On the odd occasion I get a blank line appearing not a problem! (the end user will not see it) the issue comes when I save the data out. I am
doing the following
Unit_Reply = Unit_Reply.Replace(" ", "");
to get rid of the spaces and
Unit_Reply = Unit_Reply.Replace("\r", "");
to get rid of stray carriage returns, the data is terminated by a \r\n and as this is being output I use the \n to get to a new line. Could there be an extra \r or \n or some other unprintable creeping in?
Glenn
|
|
|
|
|
glennPattonWork wrote: Could there be an extra \r or \n or some other unprintable creeping in?
Very possibly. You could always iterate over the data character by character to see what's in there. A simple test would be to write the index and ascii value of anything with an ascii value lower than the space character.
|
|
|
|
|
When you say iterate the data character, I'm using the ReadExisting() to get all the data coming in up to a New Line so if use lblIncomingData to show this (a label I already had invisible) for this purpose. I just need to convert to int? the value of the first character ( Convert.ToInt16(text) ) & run a simple int place counter right?
Glenn
|
|
|
|
|
Or, use a simple for loop like this:
for (int i = 0; i < myText.Length; i++)
{
if (myText[i] < ' ')
{
}
} It's that simple.
|
|
|
|
|
|
They all say that the first time.
|
|
|
|
|
Sorry it appears the rtb wasn't wide enough for the text!!
Sorry!!!
Glenn
|
|
|
|
|
I'm pretty sure he didn't mean that. That would be silly.
glennPattonWork wrote: I'm using the ReadExisting()
I would more likely use Read(Byte[], Int32, Int32) , but ReadExisting should be OK unless you find it isn't (in the past I've had trouble with some communication equipment inserting NULLs that weren't sent by the device).
Anyway, once you have the incoming string, you can iterate the characters:
e.g. foreach ( char c in s ) ...
and only pass along the ones you need. Personally I would write a class that would do all this and fire events for incoming strings/lines:
0) Instantiate a StringBuilder
1) Loop until told to stop:
1.1) Read incoming data
1.2) Iterate the incoming data
1.2.1) If printing character (or TAB), append to StringBuilder
1.2.2) If Carriage Return, Raise event to send contents of StringBuilder, clear StringBuilder
You may want to look at my TelnetSocket[^] for a similar technique (I thought I had a Serial Port version too).
|
|
|
|
|
I had more of a look the problem appears to be in the save command, but I will have a look at TelnetSocket.
Thanks
|
|
|
|
|
Okay I appear to have solved my problem in a silly way.
I just made the rich text box wider! Looking back into the code I was taking out all the stuff that could cause this kind of grief I just made the box too thin to take a long reading....(hangs head in shame!!! )
Thanks
Glenn
|
|
|
|
|
Do you mean that the text was wrapping?
|
|
|
|
|
I think so, I had made the box wide enough for the longest reading and tried to trim out all non-essential character,but it looks like that was the problem. Ah well testing time today!
Glenn
|
|
|
|
|
Well, that's cured that problem WordWrap to False.
|
|
|
|
|
I need to create a routine that reads all the excel files saved from sql DB.
If I have 40 excel files in my DB. I need to extract all one at a time then read the content of the excel file, save it to a grid for reporting.
Excel is in standard template with only 4 columns.
Hope you could enlighten this.
Regards
Dabuskol
Dabsukol
|
|
|
|
|
dabuskol wrote: Hope you could enlighten this.
Open the Excel-file (using ADO.NET, or any other library), read the content in a loop, write it to a database. Grids aren't a storage-point, they're used for displaying.
What exactly do you need enlightenment with? How to read Excel, how to save it, or the complete task?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
excel files are saved in a database for every record created.
What I need is to read this files of every record let say 10 records per run then automatically read the content of each file to a grid for display purposes.
In the end all the contect of 10 excel files is displayed in the grid for viewing.
no human intervention, automatic with a single button.
Regards
Dabsukol
|
|
|
|
|
dabuskol wrote: What I need
Who is saving the Excel files, what database? Sql Server? Oracle? Sqlite? Are they saved as a BLOB, or is it a real import? Do you want to "show" 10 excel-files (and their content) in a single grid? How?
You'll have to formulate your question with a bit more detail to get a decent answer. And that's what we do, answer questions - that's a bit different from "providing codez". Like your question is standing now, I'm very inclined to explain how to add a button to the form.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
In a C# 2010 desktop/console appplication, I would to know how to accomplish my tasks (or at least part of my taks) listed below working with xml:
1. I want to parse out specific nodes so that I can access the various level of nodes I am working with.
2. I would like to place various data elements in a collection/array that I can work with like an array.
3. I would like to take the xml file and add certain sections to a sql server 2008 r2 database.
**Note: The xml contains the various kind of stuctures:
a. There is an occurence of 0 to 50 customer names.
b. There is a node is just unique elements.
c. There is an occurences of 0 to 25 elements that contain the
following 4 items in each occurence:
customer number, customber address, customer city state and zip,
contact name, contact number.
Thus can you tell me and/or point to to references that will show me how to accomplish my goals (or at least part of the goals)? If I have at least an example or two to look at, I can figure out how to accomplish the rest of the goals.
|
|
|
|
|
sc steinhayse wrote: 1. I want to parse out specific nodes so that I can access the various level of
nodes I am working with.
An easy way to do this is to use Linq for XML. Take a look at this[^].
sc steinhayse wrote: 2. I would like to place various data elements in a collection/array that I can
work with like an array.
Using XLinq this is trivial. Read up on it and see how you can use things like ToList() or ToArray() .
|
|
|
|
|
Can you show mne more code examples than the link you pointed to?
|
|
|
|
|
Sure. You can find examples of querying XML here[^]. If you were to post a simplified sample of the data structure you are talking about, I could show you a sample query or two that would mean more in the context of what you're trying to do.
|
|
|
|
|
I have a process to print my sql database Id in zebra printing machine with Barcode using c# i am confused i dint use zebra printing machine before . Help
BigHeart
|
|
|
|
|
Unsurprisingly, I was able to find a C# implementation of printing to this device with a simple Google search. Here's[^] one result. In future, you should really try to search Google before posting here because you are going to wait for an answer here.
|
|
|
|