|
thanks for the replies.
i have made changes to the code however still facing problem i dont get the output and there is still this error "Index was outside the bounds of the array." when the last loop is being executed.
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
int numvalues = 20 ;<br />
int [] values = { -3, 2, -2, 4, 5, 4, 2, 5, 4, 5, -1, 2, 3, 4, 7, 4, 2, 0, 7, -3 } ;<br />
<br />
int i = 0;<br />
int maxval = 0 ;<br />
for (i = 0; i < numvalues; i++)<br />
{<br />
if (values[i] > maxval) <br />
maxval = values[i] ;<br />
}<br />
int minval = maxval ;<br />
for (i = 0 ; i < numvalues ; i++) {<br />
if (values[i] < minval) <br />
minval = values[i] ;<br />
}<br />
int freqsize = maxval - minval + 1 ;<br />
int[] frequency = new int[freqsize];<br />
for (i = 0 ; i < freqsize ; i++) {<br />
frequency[i] = 0 ;<br />
}<br />
<br />
for (i = 0 ; i < numvalues ; i++) {<br />
int index = values[i] - minval ;<br />
frequency[index]++ ;<br />
}<br />
<br />
for (i = 1; i <= freqsize; i++)<br />
{<br />
label1.Text += (i + minval).ToString() + " | ";<br />
for (int j = 0; j < frequency[i]; j++)<br />
{<br />
label1.Text += "*";<br />
}<br />
label1.Text += ("\n");<br />
}<br />
<br />
<br />
}
|
|
|
|
|
I feel like I'm helping someone do his homework...
Take a look at your last loop around freqsize and see if you find anything suspicious...
Also, if you cannot see it, throw it in the debugger and you'll find the issue pretty quickly, maybe you can step through the code. Try using a values array with 0 numbers, 1 number, 2 numbers.
|
|
|
|
|
i got it right alrdy. thanks.
|
|
|
|
|
I use the WebClient to download file to local disk, but it cannot write the data to file. I see that the file is created by program, but its size is still zero. Then the file is deleted by the program. I debug the program, and the URL is right. I can open the image using the IE.
why?
|
|
|
|
|
yu-jian wrote: I see that the file is created by program, but its size is still zero.
That sounds a bit strange, as creating a file is more critical than writing to a file. Either you simply forgot to write to the file, or your observation is wrong and the file has been there for some time already.
Check the datetimes of your file, make sure for all operations that return a status the status gets checked, do not swallow exceptions, etc. Use your debugger to look at the program flow, and watch intermediate results. If you can't locate the problem, show us the relevant piece of your code.
|
|
|
|
|
sorry, my other post wasn't clear ...
hello, i want to create a more complex highscore board that displays the playname and score in labels!
currently i have a datagrid which is displaying my data as a test, here is my code for that:
OLEDataConnector Dat = new OLEDataConnector("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"Highscore.accdb\";Persist Security Info=False;");
DataTable Dt = new DataTable();
Dat.dataSelect("select Playername, Score, LevelNumber from score order by score desc", ref Dt);
dataGridView1.DataSource = Dt.DefaultView;
its a microsoft access database and i need to get around 10 rows if they are in the database to be put onto my highscore board ...
So what i want is the playername of the record to be put into one label and the other as a score in another label, obviosuly they will move around using the query, :P
Any help? as i can't find anything on this that is of any use.... Thanks
|
|
|
|
|
Why use labels at all? Why not just get the data and draw the text on a panel yourself?
You can't bind a list of data to automatically create an array of labels for you. You have to copy the text from each record from the database to each label where it belongs. It's easier to just draw it yourself.
|
|
|
|
|
Well the DataTable that you have created in your code has a Rows[^] property.
What you can do is iterate over this collection (there is an example in the link above) and for each DataRow , create your two Labels and add them to your form. You will have to keep track of the X and Y coordinates so that you can position them properly.
I could write the code out for you, but that really wouldn't help you learn. Have a go and if you get stuck, or you don't understand, please come back to me.
Good luck.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you i shall try that :P
|
|
|
|
|
hello, i can't get it to work and i have spent another 3 hours trying differant ways lol, can you help me ?
|
|
|
|
|
Something like:
Label nameLabel = null;
Label scoreLabel = null;
int nameX = 10;
int nameY = 10;
readonly int nameWidth = 70;
int scoreX = 85;
int scoreY = 10;
int listCount = 1;
foreach(DataRow row in dt.Rows)
{
nameLabel = new Label();
nameLabel.Width = nameWidth;
nameLabel.Text = row["PlayerName"].Value.ToString();
nameLabel.Location = new Point(nameX, nameY);
this.Controls.Add(nameLabel)
nameY += nameLabel.Height + 5;
........................
........................
........................
........................
listCount++;
if (listCount > 10)
{
break;
}
}
That is roughly right but I'm doing it off the top of my head and it is very late here, so forgive any syntax errors.
Good luck.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you ever so much :P
|
|
|
|
|
I have an app that I'm workin on on 3 different computers. Each has it's own connection string. It's a pain to try to get the rigt conn string plugged in. What's the right way to deal with this?
Everything makes sense in someone's mind
|
|
|
|
|
Look at your project in VS, and open "Properties" in the Solution Explorer (It should be just above "Resources").
Double click on "Settings.Settings", and create a string called "ConnectionString".
In your app:
Properties.Settings.Default.Reload();
string connString = Properties.Settings.Default.ConnectionString; To write a changed one, use:
Properties.Settings.Default.ConnectionString = myNewConnectionString;
Properties.Settings.Default.Save(); This can be different for each PC, and can be set as part of the setup installation - it is in an XML file in the App .EXE directory.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Ya but what about from a development standpoint? I would like my app to "know" what PC I'm on and just find the right conn string.
Everything makes sense in someone's mind
|
|
|
|
|
What makes it the "right" connection string?
Either there is something which identifies the PC and says "My connection string is 'xxx'" or you have to create a string on the fly. Or store a different string on each PC, either via the settings or via the registry - settings is easier and more modern.
There are various things you can read on the PC to identify it as "this pc", or "this user", but what says "this connection string"?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
This does:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Office"
connectionString="Data Source=(local);Initial Catalog=TDC;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="Home"
connectionString="Data Source=(local);Initial Catalog=TDC;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="Clients_PC"
connectionString="Data Source=(local);Initial Catalog=TDC;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
What I was considering doing was poping up an simple UI with a list of the 3 key names. Then IO can pick one and it's used for the duration of that session. When I'm done with the app, disable the UI and use the Client's connstring.
Everything makes sense in someone's mind
|
|
|
|
|
Provided you have a property, or method, that returns the connection string you could have something like:
private string ConnectionString
{
get
{
#IF DEBUG
if(System.Environment.MachineName == ???)
return Configuration.ConnectionString["Home"];
...
#ELSE
return Configuration.ConnectionString["Client_PC"];
#END
}
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Taking a closer look your connection strings they are all the same so why do you need to switch anything?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I write my own configuration files.
|
|
|
|
|
please i need this information for a work school.
|
|
|
|
|
Not sure what you mean - you question is not very clear.
If you mean "how do I execute a method automatically at some point in the future?" then look at a Timer:
Timer t = new Timer();
t.Interval = 10000;
t.Tick += new EventHandler(t_Tick);
t.Start();
...
void t_Tick(object sender, EventArgs e)
{
MyMethod(myParameters);
}
Would activate MyMethod every ten seconds.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Have an app that runs forever, and have it use either Thread.Sleep() or a timer to execute the same operation repeatedly.
Or have an app that does it once, and use Windows Scheduler to schedule its invocation.
|
|
|
|
|
Luc Pattyn wrote: Or have an app that does it once, and use Windows Scheduler to schedule its invocation.
At least the teacher would be amazed .
Greetings - Jacek
|
|
|
|
|
Hi,
msaez wrote: i need this information for a work school
Your question doesn't contain much information. An example of what it is that you're looking for is always helpful.
There's multiple ways to interpret the question, and even when taken at it's most literal, there'd be still multiple possible solutions. If it's a fixed set of methods, I'd recommend to encapsulate each in it's own executable. You could then use the Windows Task Scheduler to plan the activation of these executables. That would mean that half of your solution would depend on a well-tested part of Windows, and the other half would consist of executables. Modular, maintenance-friendly, can easily be extended.
The question would be whether that passes the requirements set by the teacher - he might be expecting something fancy that loads an assembly on a backgroundthread and which uses reflection to execute a specific method, complete with a dynamic inputscreen for the parameters
I are Troll
|
|
|
|