|
There's probably more than 10,000 error messages possible in the .NET Framework. There is no method that will give you a list of all of those messages.
|
|
|
|
|
Hi!
I have an interesting problem. I have an application that contains two textboxes. The user enters his StartTime in one textbox and his EndTime in the other.
I have a calculation method that calculated the total Hours between these two variables. The problem I am having is that when the user inserts the starttime say 8:00 and finish time say 7:00 you will get a -1 hour.
How can I prevent users from entering negative values??
My method looks like this:
private void CalculateHoursWorked()
{
string startTime = Convert.ToDateTime(txtStartTime.Text).ToShortTimeString();
DateTime startDate = Convert.ToDateTime(startTime);
string endTime = Convert.ToDateTime(txtEndTime.Text).ToShortTimeString();
DateTime endDate = Convert.ToDateTime(endTime);
TimeSpan ts = endDate.Subtract(startDate);
HoursWorked = ts.Hours.ToString();
MinutesWorked = ts.Minutes.ToString();
}
Illegal Operation
|
|
|
|
|
Illegal Operation wrote: How can I prevent users from entering negative values??
First: you should use dateTimePicker(s) instead of text boxes
(a masked textBox could do the job but => more work)
As for negative result create a function to swap dates. Something like:
private void SwapDates(){
if(start.CompareTo(end)<0)
{
DateTime tmp = start;
start=end;
end=tmp;
}
}
|
|
|
|
|
You should check if the time is negative. If so show an error that clearly explains that negative time is not allowed and why the time the user entererd was negative. Then highlight one of the times in red
|
|
|
|
|
Hello Sirs,
How to find the compression type of jpeg, when we give one sample input jpeg file the output result is this image contains (ex.) xxxx compression type. How to identify it .?
please replay
Failure is Success If we learn from it!!
|
|
|
|
|
I am very new to C# I have taken two classes on Java. But they were not the best classes. I am wanting to learn as much as I can about linking up Access Databases to Combo boxes in C#. I am wanting to create a database that I can select an item using a combo box then * a number input in a different text box and have it display in a different text box.
So for instance I would select in the combo box a food name. Then in my 1st text box I would put a number this would then * buy number of calories that is linked to the food name. And display the results in the last text box.
food Q total
Any suggestion on this or links that would give visual examples of how to get this to work?
|
|
|
|
|
What are you trying to say using * instead of words? In this context, * means a placeholder to select all records, or to multiply two numbers. Neither has much value in describing what you're trying to accomplish. Please elaborate.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
When I used * I mean multiply. Sorry about that.
|
|
|
|
|
mmjf9696 wrote: I am very new to C# I have taken two classes on Java.
If you have taken Java classes, why are you trying to write code in C#?
"No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
The reply is not really relevant to my question. But since you seem to be interested I want to learn this language.
|
|
|
|
|
I am able now to get my data from the column in my database that I want into my combo box. However I want one thing to display in the combo box and when that item is selected I would like the value from a different column but same row to show up in a text box. I can get this to work sometimes I just don't understand how it is working. I am using data binding and I would like a tutorial that walks me through how this works.
Now that I have my combo box displaying the data I want from my database and that I have my text box displaying the correct data from my database when an item is selected in the combo box. I would like to take the number showing in my text box and multiply it by a number I input in a text box I will call "quantity". Then have the calculation show up in a separate text box called "total".
Do you have any advice on this or examples?
|
|
|
|
|
The combobox shows the selection now, if I understand you correctly, so you are able to access the data you wanted. And if I recall, you have an associated value of calories displayed in the textbox. Is that correct? Now you want to enter a quantity of the item in another box, multiply them, and display the total calories. Have I got that right?
Since a textbox only holds text data, the first thing you'll need to do is cast their contents to numeric values:
Int32 Cals = System.Convert.ToInt32(txtCals.Text);<br />
Int32 Qty = System.Convert.ToInt32(txtQuantity.Text);
Then you need to perform the calculation and convert the result to text to store it in the result textbox:
txtResult.Text = System.Convert.ToString(Cals * Qty);
I make no guarantees, since I'm new to C# and .Net, but I believe this will get you on your way again. Let me get a few chapters ahead of you and I might be able to help with the database part.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
That is right I will give this a try thanks. Do you know of any good C# help sites that might have videos or code examples?
|
|
|
|
|
As a matter of fact, I do! You're already a member.
Spend a bunch of time in the Articles section here; there's a lot of excellent code examples, many with clear, informative explanations. I haven't seen any better resource.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Great I will start my search today. I just want to get better at the basics before I move up to the big boy stuff. Thanks for you advice and help.
|
|
|
|
|
Hi? I have a problem. I got the file which has dvi extension. Of course i can use some application but problem is i want to create my own application.
Please help me and guide me how to read the binary file with dvi extension.
|
|
|
|
|
|
You need to research the file format so you can parse it correctly. This[^] may help
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I have an application where the user sets-up a workspace. The workspace has a variety of elements including arrays, bitmaps, generic lists, etc. When the user is done working he/she can save the workspace. The application saves the elements in a sequenced, binary file. When the user comes back, he starts the application and loads the workspace through an “open” menu item. It works.
Now, some users instinctively navigate to the file and double-click to both start the application and load the file. I’m all set with setting the default app for the extension and all that. But, what is the standard procedure for instructing the application to load the selected file if it has opened by way of a file double-click?
|
|
|
|
|
when you double-click a file in Windows Explorer, it will launch the application associated with the file extension, and pass the full path as the first command line parameter (or several if several files were selected). So let your app look for command line arguments, and if there are any, open them.
Either use the optional parameters of the Main() method, or use the Environment class to get the command line.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Spuose your app displayes images. You set the default "open with and all that" to your app.
Then in program.cs inside Main after Application.Enable.... do something like this:
if(args!=null){
Application.Run(new MyCoolImageViewer(args[0]);
}
else{
Application.Run( new MyCoolImageViewer(null);
}
And of course in your ctor check for null before opening the image.
|
|
|
|
|
|
I have this function that is called from the constructor of the main form:
private void InitNet()
{
listener= new TcpListener(localAddress, portNo);
listenForConnection = new Thread(StartListening);
listenForConnection.Start();
Control.CheckForIllegalCrossThreadCalls = false;
}
The StartListening function is defined as follows:
private void StartListening()
{
listener.Start();
while (true)
{
Networks user = new Networks(listener.AcceptTcpClient());
}
}
When i close the program, it does not get out of memory, possible because of the thread. I have tried to abort the thread in the FormClosing Event but this did not work, how can i close this application competely (Of course not using task manager! )
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
Wamuti wrote:
CheckForIllegalCrossThreadCalls = false;
Evil
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
You need to tell the thread to stop so that it can cleanup its resources and exit:
[RE-EDIT]
bool runListener = true;
private void StartListening()
{
listener.Start();
while (runListener)
{
if (listener.Pending())
{
Networks user = new Networks(listener.AcceptTcpClient());
}
else
{
Thread.Sleep(250);
}
}
listener.Stop();
}
then in the FormClosing event (or wherever you're doing cleanup) set runListener to false.
Also, if you set the thread's IsBackground property to true then the thread won't cause the program to remain alive even if it isn't terminated before the form closes.
Control.CheckForIllegalCrossThreadCalls = false; And that's just completely uncalled for.
|
|
|
|