|
Complete Programming Problem #1, Distance Calculator, on page 337 of the textbook.
(using the "starting out with Visual C#" 4th edition Author tony Gaddis, and using visual studios 2015)
The ADDITIONAL REQUIREMENTS described below MUST also be implemented:
Assume the value of Vehicle Speed in MPH may store whole or floating-point numbers (non-monetary).
Assume the value of Hours Traveled can only store whole numbers.
Prevent data conversion exception for the Vehicle Speed in MPH text box by using the appropriate TryParse method. If the data entered is invalid display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
Validate the input for the Vehicle Speed in MPH to make sure the data entered is greater than zero and does not exceed 180. If not, display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
Prevent data conversion exception for the Hours Traveled text box by using the appropriate TryParse method. If the data entered is invalid display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
Validate the input for Hours Traveled to make sure the data entered is greater than zero and not more than 50. If not, display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
Implement the following fields:
Total Distance which accumulates the distance for each entry (i.e., as shown in the ListBox control)
Total Hours Traveled which accumulates the hours traveled for each entry (i.e., as entered in the Hours Traveled TextBox control)
Total Trips which counts each entry (i.e., incremented each time the user clicks the Calculate Button control)
Display appropriate output to the ListBox control as shown in the sample input-output document attached.
Display Total Distance as a number with two-decimal places.
Display Total Hours Traveled and Total Trips as a number with no decimal places.
Calculate and display the Average Distance which is the Total Distance divided by the Total Trips (recall, average distance is not an accumulator or counter) formatted as a number with two-decimal places.
The program MUST include standard features of a Windows application including:
Change the default Text property of the form to something descriptive
Appropriate naming conventions for all controls (i.e., buttons, labels, text boxes, list). The standard naming convention is descriptive name including control type using camelCase notation. For example: hoursTraveledTextBox, distanceListBox, totalHoursTraveledLabel, exitButton. The exception is controls not referenced in the code-behind of Form1. For example, Label controls used for descriptive purposes only or PictureBox controls used for aesthetic purposes only.
Calculate, Clear, and Exit buttons with appropriate name and keyboard access key
AcceptButton and CancelButton properties should be appropriately assigned to the Calculate button and Clear button, respectively
Ensure tab order for form is logical
When Clear button is clicked the controls outside of the Summary GroupBox control should be cleared (i.e. using the Clear method or assigning an empty string) and the focus set back to the first TextBox control for entering data. The controls inside the Summary GroupBox control should NOT be cleared (i.e., using the Clear method or assigning an empty string). Do NOT reset the values of the fields to zero.
Appropriate naming conventions and data type declarations for variables and fields.
Remove all unused event handlers from the program code.
|
|
|
|
|
Carefully.
Next!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
C#NoobHelpMe wrote: on page 337 of the textbook Start there.
|
|
|
|
|
|
Who needs to read textbooks when CodeProject is free?
|
|
|
|
|
Nobody who uses four question marks together is allowed to read a text book. It's probably a law, like "you can't put anything interesting on TV on a Saturday".
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
People have been making an assumption (very probably valid) that you want us to write your code for you. That would be doing you a disservice though as the question you ask is "How do I do this assignment????" and that's the question I'm going to answer, even though it's probably not the answer that you were wanting.
What you have here are a set of requirements. Some are explicitly stated and some require you to apply a little bit of problem solving. You start your task by working out what you already know. For instance, you have a vehicle speed and you know that it can store whole or floating point numbers (non-monetary). With a little bit of thought, you realise that the speed property is not going to be a whole number so it can't be a long, short or an int. This doesn't leave you with much in the way of data types so you need to do a little bit of research and find out which data types are available in C# that aren't monetary either.
That's how you solve the problem. By breaking big problems down into little problems. You have all the information you need in this question and the related book, so make use of them.
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: What you have here are a set of requirements Requirement rarely come in that form, unless we are reverse-engineering. What he has is an exact specification of the properties for the components that the teach desires.
Student does not need knowledge on why those properties exist, or why it would be preferred over the alternative. It is not an assignment, it's a joke.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi experts,
I have a WinForm app, with form that build Background Workers in code.
The trigger is a local timer which kill the current BGW if he finished and create it again.
I need in this specific time (between the kill and create - clear all the resources (mainly - memory).
The app uploading files (each above 100MB) using Arrays & Memory Streams.
without clear the memory - it grows with each file ( 3 files can easily get above 1G)
|
|
|
|
|
There are problems here.
1) If you kill a task, it's dead. It can't be asked to recycle it;s resourced after you kill it as the thread itself is terminated, which automatically recycles the stack. So you have no access to the variables that thread was using! To recycle, you need to tell the thread itself it's not needed and let it handle disposal as necessary before it terminates itself by returning from its startup method.
2) There is no specific Array.Dispose in .NET - which means you have no direct control over when the memory allocated to an array is released, even if you are in the task that created it.
The only way to do this is clumsy: tell the task to die via a semaphore so it can intelligently release what resources it has acquired; then when it is complete call GC.Collect to reclaim all unused memory.
Do note that this will not reduce the memory footprint of your overall application, as memory once allocated to a process is not released back to the OS once it is recycled by the CG.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
As Griff explained, you can't have the GC collect "part" of the garbage. There's an easy way to cheat; instead of having the download-code in a BGW, put it inside a complete process (a separate executable). You could report progress easily by writing/reading stdout, and if you terminate the process, all resources for that process are cleaned up.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm facing an issue , while populating data within datagridview control.
If datagridview's scroll bar is present, then it's showing a flickering and the scroll bar is not movable.
I have implemented solutions for handling double buffering, but could n't find any luck.
My working code:
<pre> public RxnDetailSelectionForm()
{
InitializeComponent();
this.ClientSize = Properties.Settings.Default.RxnImportFormSize;
this.groupBoxSelSectionType.Enabled = false;
this.groupBoxSelExptType.Enabled = false;
this.groupBoxSelExptType.Visible = false;
this.radioButtonSameSectionSameExpt.Checked = true;
this.dataGridView1.Focus();
PopulateData();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
public void PopulateData()
{
this.dataGridView1.Rows.Clear();
DataTable dataTable = new DataTable("t");
BindingSource bindingSource = new BindingSource();
for (int i = 0; i < dataGridView1.ColumnCount; ++i)
{
dataTable.Columns.Add(new DataColumn(dataGridView1.Columns[i].Name));
dataGridView1.Columns[i].DataPropertyName = dataGridView1.Columns[i].Name;
}
dataTable.ReadXml("SampleData.xml");
bindingSource.DataSource = dataTable;
dataGridView1.DataSource = bindingSource;
this.dataGridView1.Rows[0].Selected = true;
}
private void RxnDetailSelectionForm_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.RxnImportFormSize = (sender as Form).ClientSize;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
|
|
|
|
|
You're using databinding; during the binding-process, the UI will stop responding for a very short time. All applications "flicker" like that when processing a lot, and it is not a problem.
If it is a problem to you and you want to eliminate it, then have your gridview virtualized. That's the "fastest" way to show a DGV and its contents.
How to: Implement Virtual Mode in the Windows Forms DataGridView Control | Microsoft Docs[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Tried
this.dataGridView1.VirtualMode = true; , but did n't work.
|
|
|
|
|
That's correct. It requires a bit more than simply toggeling a boolean.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
Thanks, have tried it and didn't help.
|
|
|
|
|
I see the software to charge credit card swipe, samsung pay, ... I want to find out how the swipe card works and write code to get payment information in the software sales. how ? You can share the code for me with.
|
|
|
|
|
Start here: Magnetic stripe card - Wikipedia[^]
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Many magnetic stripe readers are keyboard emulators - they decode the data on the stripe and then fed it in to the keyboard buffer as if it has been typed.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Given that development recently in C# and even less on HTML. I a trying to use the webbrowser control from the GeckoWebBrowser Ver 45 32bit C# library to execute inserts on a website input.
I tried to use the version Gecko Ver 60 32bit but nothing. I can not pass on ASP.net I absolutely have to solve it by the end of the month. I ask for help and immensely thank you.
source with input name:
<input name="propNome" class="ui-widget-content ui-corner-all jq-lovpersone jq-lovpersone-field ui-autocomplete-input" role="textbox" aria-haspopup="true" aria-autocomplete="list" size="80" autocomplete="off">
my working code:<pre lang="cs"> if (!nomeproprietario)
{
foreach (GeckoHtmlElement hetxtnomeproprietario in webBrowser1.Document.GetElementsByName("propNome"))
{
hetxtnomeproprietario.SetAttribute("type", "text");
hetxtnomeproprietario.SetAttribute("value", "MARIO");
//hetxtnomeproprietario.InvokeMember("click");
//SendKeys.Send("{ENTER}");
nomeproprietario = true;
break;
}
} if instead I use this source with input id:
<input id="durataTrt" name="durataTrt" class="jq-text ui-widget-content ui-corner-all " value="" size="3" maxlength="3" type="text"> my code 1) is not working
if (!durata)
{
foreach (GeckoHtmlElement hetxtdurata in webBrowser1.Document.GetElementsByName("durataTrt"))
{
hetxtdurata.SetAttribute("type", "text");
hetxtdurata.SetAttribute("value", "10");
durata = true;
break;
}
}
I also tried with the .InnerHtml, .Value, .SettAttribute property but nothing
my code 2) is not working
var hetxtdurata1= new Gecko.DOM.GeckoInputElement(webBrowser1.Document.GetHtmlElementById("durataTrt").DomObject);
if (hetxtdurata1== null)
{
return;
}
else
{
hetxtdurata1.Value = "10";
}
I also tried with the .InnerHtml, .Value, SettAttribute property but nothing
my code 3) is not working
Gecko.GeckoHtmlElement hetxtdurata2= (Gecko.GeckoHtmlElement)webBrowser1.DomDocument.GetElementById("durataTrt");
if (hetxtdurata2== null)
{
return;
}
else
{
if (hetxtdurata2!= null)
{
hetxtdurata2.Click();
hetxtdurata2.SetAttribute("type", "text");
hetxtdurata2.SetAttribute("value", "10");
}
} I do not understand why with input name I have no problem while with input id instead.
[edit]Code blocks added - OriginalGriff[/edit]
Andrea Russo
modified 24-Oct-18 14:18pm.
|
|
|
|
|
hi ,
how can I setup automatic mail function which gets triggered by dateTimePicker?
I basicly want to send email when at time that dateTimePicker shows.
modified 13-Feb-19 21:02pm.
|
|
|
|
|
What have you tried ?
Have you created a TaskService, have you researched/tried using a Trigger ? Have you worked with the SmtpClient.SendMailAsync method ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I will search for SmtpClient.SendMailAsync method and TaskService creation.thank you.
modified 13-Feb-19 21:02pm.
|
|
|
|
|
Two ways:
1) Have an application running which knows what time to send it, and which checks the time often enough to be accurate.
2) Use Scheduler to add a task that runs at a specific time. The task sends your email.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|