|
Hello,
trying to build a Windows programm, I 've declared an object in Fornm1.cs by typing
Person[] P = new Person[10];
after a class Person I 've created on another file called Person.cs
Then on the function that is being activated after clicking on a button inside the Form I pass simple numerical values to a member attribute like below:
private void btnObjectAdd_Click(object sender, EventArgs e)
{
lbltest_i.Text = i.ToString();
P[i] = new Person();
P[i].category = i;
i++;
if (i == 10)
{
for (i = 0; i < 10; i++)
P[i] = null;
i = 0;
}
}
Thus I get P[0]=0, P[1]=1, ... P[9]=9.
Then I try to call a value of an object on another function like
private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
int value = P[2].category;
}
and I get value = 2.
This works perfect.
But if I change
int value = P[2].category;
into
int value = P[i].category;
then I get an error that I should create an object with 'new'.
Variable i is declared as
int i = 0;
outside the functions but inside the
public partial class Form1 : Form
Is that the problem?
modified on Monday, February 7, 2011 1:14 PM
|
|
|
|
|
There seems to be something very wrong with your design. But if "i" is declared in the same class as your showToolStripMenuItem_Click code then there should be no reason why that is the problem. Perhaps you need to post more of your code - and please you the PRE tags to format is more readably.
return 5;
|
|
|
|
|
Thanks for the 'pre' tip, i was looking for s'thing like that.
I got rid of the confusing 0 by changing the array into
new Person[11] instead of a 10 dimension. After all, we 've got plenty of memory nowdays
As a result everything worked fine! It must have been some other mistake, as the one I thought of.
|
|
|
|
|
How is it possible to make a dynamic system so that everytime a new setting is added to the app.config file, the system can take that into consideration?
For example, my present system, looks in the app.config file and gets the value of a key i.e.
<add key="AllowedTime" value="5"/>
<add key="MyValue" value="10"/>
and the system does checks based on this figures. For example if the retrieved value i.e. 5 is less than the MyValue in the app.config file...
I can go on and add more settings in the app.config file and add the logic to the c# code, but I wonder if there is a generic way so that as long as the setting is entered in such a manor so that the c# code can analyse that without me adding to the c# code each time there is a new setting in the config file.?
What do you think?
Thanks
|
|
|
|
|
Just a quick thought. There may be built in functionality for this kind of thing I don't know of...
<add key="NumberOfValues" value="3"/>
<add key="MyValue1" value="1"/>
<add key="MyValue2" value="2"/>
<add key="MyValue3" value="3"/>
Then in code...
int count = int.Parse(ConfigurationManager.AppSettings["NumberOfValues"]);
for(int i = 1; i <= count; i++)
{
string setting = ConfigurationManager.AppSettings["MyValue" + i];
}
...of course, it depends what you actually plan on doing with these kind of values. I have not needed this functionality before and I imagine the closest thing I would need would probably result in me creating an XML file of some sort
return 5;
|
|
|
|
|
Before doing anything with the settings, you can call the Load() method on the settings object to make sure you're using the latest settings, or you can setup a thread that watches the file, and reloads it when the file changes, or even setuup a thread that loads it every X minutes.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
how to create own DB emails to used in own messenger
|
|
|
|
|
Nope, sorry.
I understand all of the individual words.
It's just the whole sentence that makes no real sense.
Please, try to give us more information on what problem you are having.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
the problem is create db
this db contains emails that will
used i messenger how to create email
in this db and how make email appear
as offline and online to other members
|
|
|
|
|
I'm sorry, I can't understand your question.
N2 @ <= 77K & > 63K.
|
|
|
|
|
Keith Barrow wrote: N2 @ <= 77K & > 63K.
I'm sorry, I can't understand your question.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
Abut you do know the correct answer, at least around here
|
|
|
|
|
Keith Barrow wrote: N2 @ <= 77K & > 63K.
Do you mean it should be liquid and cold?
But 77K (-196 centigrades) is too cold for my taste...
|
|
|
|
|
5'd for getting there and not mentioning the exact phrase
|
|
|
|
|
|
|
om_metab wrote: what appropriate way
By code would be my choice. Of course, you may choose to implement it by tickling shrimps, but I prefer the old fashioned way.
|
|
|
|
|
Pete O'Hanlon wrote: tickling shrimps
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
Pete O'Hanlon wrote: you may choose to implement it by tickling shrimps,
Now you made me look silly in the office again. I let out a verbal giggle reading this and now my coworkers are going to be giving me "the look" all day.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Tell me that you didn't get a mental image there.
|
|
|
|
|
I'll tell you whatever you want to hear at this point.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
|
Despite the fact you asked the same question 4 weeks ago, and you obviously didn´t make your assignment, the answer is in your question:
1. You will have to maintain an DB Server (doesn´t matter if MSSQL, MySQL, MariaDB, whatever you want ...)
2. You will have to write the program code for your "messenger" client:
2.1. Logon to DB
2.2. Set state to "online" (you need more than one table in your DB .... think about it)
2.3. code the features you want in your messenger.
if a problem with a single part occurs, you can ask again, and then, maybe, someone can help you.
But I say to you positivly, NOBODY will do your assignment for you.
I cannot remember: What did I before google?
|
|
|
|
|
Frnds,
I have a desktop application(c# and SQL) which tries to get image from URL.
What I did
string imgg = PictureBoxImageAdding(dr.GetValue(0).ToString());
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Size = new System.Drawing.Size(142, 190);
pictureBox1.Image = new Bitmap(imgg);
It work fine with local path ie. d:/images/pics/xyz.jpg but not with http://www.xyz.com/images/pics/xyz.jpg
Whats the SOLUTION.
|
|
|
|
|
Download the picture to a local (temporary) file, e.g. using HttpWebRequest from the System.Net namespace. Then load the temp file.
|
|
|
|