| | |
some help please.
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2009
Posts: 16
Reputation:
Solved Threads: 0
//Code Written By S Barratt
i would like my button display to - out put all the values of the arrayList.
------------------------------------------------------------------------------------------
i would very much like some information about key pressing so when the use presses the key enter return ( char 13).
i did try - but my key press_ down just does not work.
-----------------------------------------------------------------------------------------------
finally i would like someone to show me how to format a number into dollars or pounds and how to round a decimal to two points
i know it goes string("00.00.00"" but where do i put String(Fomat type)?? - eg. at start of value i am using to store data input at the end when i am doing data output?
------------------------------------------------------------------------------------------------
finally i need some help with dates and the addition of dates
any help or refrencing to other material would be greatly apprechiated.
This is A program storing scores etc.
i would like my button display to - out put all the values of the arrayList.
------------------------------------------------------------------------------------------
i would very much like some information about key pressing so when the use presses the key enter return ( char 13).
i did try - but my key press_ down just does not work.
-----------------------------------------------------------------------------------------------
finally i would like someone to show me how to format a number into dollars or pounds and how to round a decimal to two points
i know it goes string("00.00.00"" but where do i put String(Fomat type)?? - eg. at start of value i am using to store data input at the end when i am doing data output?
------------------------------------------------------------------------------------------------
finally i need some help with dates and the addition of dates
any help or refrencing to other material would be greatly apprechiated.
This is A program storing scores etc.
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; namespace Exercise13 { public partial class FrmCalculateAverageScore : Form { ArrayList StoreValueOfScores = new ArrayList(); int Numberofscores; int TotalOfScore; int i; int ValueScore; bool DTrueOrFalse; public FrmCalculateAverageScore() { InitializeComponent(); } private void BtnCalculate_Click(object sender, EventArgs e) { int AverageScore; DTrueOrFalse = false; try { ValueScore = int.Parse(TbValueOfScore.Text); } catch (FormatException) { MessageBox.Show("Enter a number into Score Below 101"); TbValueOfScore.Clear(); TbValueOfScore.Focus(); DTrueOrFalse = true; } catch (OverflowException) { MessageBox.Show("Enter a number into Score Below 101"); TbValueOfScore.Clear(); TbValueOfScore.Focus(); DTrueOrFalse = true; } if (ValueScore > 101) { DTrueOrFalse = true; MessageBox.Show("Enter a number into Score Below 101"); TbValueOfScore.Clear(); TbValueOfScore.Focus(); } if (ValueScore < 0) { DTrueOrFalse = true; MessageBox.Show("Enter a number into score Above 0"); TbValueOfScore.Clear(); TbValueOfScore.Focus(); } if (DTrueOrFalse == false) { Numberofscores = Numberofscores + 1; LblNumberOfScores.Text = Numberofscores.ToString(); StoreValueOfScores.Add(ValueScore); TbValueOfScore.Clear(); TbValueOfScore.Focus(); for (int i = 0; i < StoreValueOfScores.Count; i++) { TotalOfScore = TotalOfScore + ValueScore; LblScoreTotal.Text = TotalOfScore.ToString(); AverageScore = TotalOfScore / Numberofscores; LblAverageScore.Text = AverageScore.ToString(); } } } private void BtnExit_Click(object sender, EventArgs e) { Close(); } private void BtnClear_Click(object sender, EventArgs e) { for (i = 0; i < StoreValueOfScores.Count; i++) { StoreValueOfScores.Remove(ValueScore); LblNumberOfScores.Text = 0.ToString(); LblAverageScore.Text = 0.ToString(); TbValueOfScore.Focus(); LblScoreTotal.Text = 0.ToString(); Numberofscores = 0; TotalOfScore = 0; ValueScore = 0; } } private void BtnDisplay_Click(object sender, EventArgs e) { for (i = 0; i < StoreValueOfScores.Count; i++) { MessageBox.Show(StoreValueOfScores[i].ToString()); } } } } //Code Written By S Barratt
Last edited by brightsolar; 17 Days Ago at 6:08 pm.
1
#2 16 Days Ago
Hi,
Few suggestions for your questions;
i would like my button display to - out put all the values of the arrayList.
-- Sorry, not much clear to me.
i would very much like some information about key pressing so when the use presses the key enter return ( char 13).
i did try - but my key press_ down just does not work.
-- Use from KeyDown event, Keys.Enter
here is a piece of code
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
SendKeys.Send("{Tab}");
break;
case Keys.Escape:
btnCancel_Click(this,e);
break;
}
finally i would like someone to show me how to format a number into dollars or pounds and how to round a decimal to two points
Please have a look at
http://blog.stevex.net/?page_id=33
finally i need some help with dates and the addition of dates
any help or refrencing to other material would be greatly apprechiated.
DateTime dt1 = new DateTime();
dt1.AddDays(1);
The above code will add a day to the date. similarly it provide multiple options to add time, month,...etc. Did this solve your problem?
Good luck
Few suggestions for your questions;
i would like my button display to - out put all the values of the arrayList.
-- Sorry, not much clear to me.
i would very much like some information about key pressing so when the use presses the key enter return ( char 13).
i did try - but my key press_ down just does not work.
-- Use from KeyDown event, Keys.Enter
here is a piece of code
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
SendKeys.Send("{Tab}");
break;
case Keys.Escape:
btnCancel_Click(this,e);
break;
}
finally i would like someone to show me how to format a number into dollars or pounds and how to round a decimal to two points
Please have a look at
http://blog.stevex.net/?page_id=33
finally i need some help with dates and the addition of dates
any help or refrencing to other material would be greatly apprechiated.
DateTime dt1 = new DateTime();
dt1.AddDays(1);
The above code will add a day to the date. similarly it provide multiple options to add time, month,...etc. Did this solve your problem?
Good luck
0
#3 16 Days Ago
•
•
•
•
i would very much like some information about key pressing so when the use presses the key enter return ( char 13).
i did try - but my key press_ down just does not work.
-----------------------------------------------------------------------------------------------
C# Syntax (Toggle Plain Text)
namespace Exercise13 { public partial class FrmCalculateAverageScore : Form { public FrmCalculateAverageScore() { InitializeComponent(); this.button1.KeyPress+=new KeyPressEventHandler(button1_KeyPress); }
If you create the event handler through the Visual Studio designer this code is created in the Form1.Designer.cs partial file. This is the code that calls your method when the assigned event is raised.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
•
•
Join Date: May 2009
Posts: 16
Reputation:
Solved Threads: 0
0
#4 16 Days Ago
Thanks everyone 
my first question rephased- to better english construction
But if i input say 22, 33 and 44 into an arraylist (dynamic array)
how would i display all 3 values in one message box instead of 3 indivual ones. As done by using the for loop.
and how would i sort the array to appear in order?.
More help would Strongely improve my understanding and it would be apprechiated.
-----------------------------------------------------------------------------------

my first question rephased- to better english construction
But if i input say 22, 33 and 44 into an arraylist (dynamic array)
how would i display all 3 values in one message box instead of 3 indivual ones. As done by using the for loop.
and how would i sort the array to appear in order?.
More help would Strongely improve my understanding and it would be apprechiated.
-----------------------------------------------------------------------------------
•
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
1
#5 16 Days Ago
Here is an example for your messagebox question in which the ArrayList is cast to an Array, which the
In order to sort the array:
You may wish to consider using
string.Format method can then use to format a string with individual placeholders (eg. {0}, {1}, etc.): C# Syntax (Toggle Plain Text)
ArrayList ary = new ArrayList(); ary.Add("one"); ary.Add("two"); ary.Add("three"); string s = string.Format("{0}\r\n{1}\r\n{2}\r\n", ary.ToArray()); MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);
In order to sort the array:
ArrayList.Sort . If you need to sort complex items, you need to provide an IComparer .You may wish to consider using
List<> (eg. List<int>) instead of an ArrayList in the future. •
•
Join Date: May 2009
Posts: 16
Reputation:
Solved Threads: 0
0
#6 15 Days Ago
thanks everyone.
string s = string.Format("{0}\r\n{1}\r\n{2}\r\n", ary.ToArray());
MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);
these lines seem intresting but how would you do it for an index - which can constantly get bigger by the users input? . for example 3 values one time , 4 values another time or X values another time.
it has to be in an array or arraylist which is kinda of a shame as list<> is easier no dought.
-----------------------------------------------------------------
string s = string.Format("{0}\r\n{1}\r\n{2}\r\n", ary.ToArray());
MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);
these lines seem intresting but how would you do it for an index - which can constantly get bigger by the users input? . for example 3 values one time , 4 values another time or X values another time.
it has to be in an array or arraylist which is kinda of a shame as list<> is easier no dought.
-----------------------------------------------------------------
•
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
1
#7 15 Days Ago
•
•
•
•
thanks everyone.
string s = string.Format("{0}\r\n{1}\r\n{2}\r\n", ary.ToArray());
MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);
these lines seem intresting but how would you do it for an index - which can constantly get bigger by the users input? . for example 3 values one time , 4 values another time or X values another time.
it has to be in an array or arraylist which is kinda of a shame as list<> is easier no dought.
-----------------------------------------------------------------
object type before casting it to a string . This is because ArrayList is not a "strongly typed" container and treats its items simply as object types. Unfortunately, this also means you could store mixed types in the array, which would cause an error if you try to cast it to the wrong type. C# Syntax (Toggle Plain Text)
string s2 = string.Empty; foreach (object oString in ary) s2 += (string)oString + "\r\n"; MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);
Last edited by DdoubleD; 15 Days Ago at 9:41 am.
1
#8 15 Days Ago
•
•
•
•
This is because ArrayList is not a "strongly typed" container and treats its items simply as object types. Unfortunately, this also means you could store mixed types in the array, which would cause an error if you try to cast it to the wrong type. object myString = new object(); :pBy using strongly typed collections you can avoid a lot of InvalidCastExceptions. You can check that the data is of the correct type when entering it into the collection then you know what you are working with any time you retrieve an item from the collection.
Also, when you create a variable/collection an area of memory is set aside to store it. Because an object can contain almost ANY type of data the memory set aside may be much larger than is needed. By using a strongly typed collection you only use what memory you ened
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
![]() |
Other Threads in the C# Forum
- Previous Thread: Creating a C#.net program using layers..
- Next Thread: speech recognition using C#?
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset datetime degrees development dll draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update upload usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml





