|
Hello everyone,
I'm trying to make an questionnaire and I want to do this with enums.
For example:
enum Color{ Black, White }
enum Height{ cm_10, cm_20 }
With this information I want to show each enum in a panel, where you first have to answer the color and then the height, and it has to be extendable. But I don't get it working.
Can you help me, I would like to do it something as following:
private void askQuestion(Enum e)
{
String[] ss = Enum.GetNames(typeof(e));
putOnScreen(ss);
}
private void overall()
{
ArrayList ar = new ArrayList();
ar.Add(Color);
ar.Add(Height);
foreach(Enum e in ar)
{
askQuestion(e);
}
}
I guess it should be possible, but I don't know how.
|
|
|
|
|
If you put your questions inside enumerations, you haven't got an extensible mechanism. When I've developed this type of application in the past, I've always used a database. Roughly, this breaks down into:
Topics
Questions
Answers
AnswerTypes (textbox, multi-select, etc)
Scores for answer
This makes for a much more extensible questionnaire application.
|
|
|
|
|
You are totaly right about that. I'm going to make it with a database.
But if we asume that I would do it the way I described above (just to learn something), is this possible or possible but not done or something else?
|
|
|
|
|
It's possible - but not advisable. BTW - using ArrayList isn't a good idea. I assume you're not saddled with developing in .NET 1 or 1.1.
|
|
|
|
|
I'm used to developing in .NET 2.0 and 3.5
ArrayList was just a suggestion, I prefer just arrays, like Enum[] e = { enum1, enum2 };
But that didn't work.
If you say I shouldn't use it, I'll just go and work with a database.
|
|
|
|
|
|
Good afternoon all,
I'm learning to work with 'Lists'
I've set up a list of 'zooAnimals' and in the list i've added objects as they have been created.
zooAnimals = new List<Animal>();
newcat1 = new Cat(cat1, catPen, fircat);
newcat2 = new Cat(cat2, catPen, seccat);
newtig1 = new Tiger(tiger1, tigerPen, firtig);
newtig2 = new Tiger(tiger2, tigerPen, sectig);
zooAnimals.Add(newcat1);
zooAnimals.Add(newcat2);
zooAnimals.Add(newtig1);
zooAnimals.Add(newtig2);
I would like to now step through the list to perform certain actions when a button is pressed.
For example - the form has a number of buttons on it - 1 being for individual groups of animals to eat().
I tried with
foreach (Cat thisCat in zooAnimals)
{
if (thisCat.hunger == 7)
{
thisCat.hunger = thisCat.hunger - 5;
}
}
but this code throws an InvalidCast Exception......
Unable to cast object of type 'Zoo_Animals.Tiger' to type 'Zoo_Animals.Cat'.
Is there a way of stepping through the list to do this ?
Thanks in advance !
Neil
|
|
|
|
|
If you're using .NET 3.5 you can use
foreach(Cat thisCat in zooAnimals.OfType<Cat>())
{
...
}
otherwise you'll have to check each item
foreach(Animal animal in zooAnimals)
{
if(animal is Cat)
{
...
}
}
|
|
|
|
|
Thank you very much indeed - worked a treat !
|
|
|
|
|
J4amieC wrote: foreach(Cat thisCat in zooAnimals.OfType<cat>())
That's neat - and my trigger to start looking at 3.5 finally...
Knowledge is hereditary, it will find its way up or down.
Luc Pattyn
and since what every time when i want to add button to this control one add two times
posted in C# forum
|
|
|
|
|
Yeah, didn't know about the OfType extension too, looks really useful in this situation.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi
I have done a project on .Net using SQL compact edition ...once i take the build i am getting the Exception Memory corrupted ..Do any one have idea regarding this...Can anyone help me out
|
|
|
|
|
Hi,
I've a problem using VC++ 6.0 dlls in C#.net, I'm using dllimport
dlls consists of classes and I want to call functions contained in classes but they are not static functions.
I tried this code
[DllImport("XYZ.dll", EntryPoint = "?XYZ@XYZ@@XYZ")]
public static extern int XYZ();
when I tried to call XYZ function I got this exception:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
How can I do this?
thanks in Advance,
Akram
|
|
|
|
|
I was able to send mail via simple smtp server
the problem is that as i understood gmail needs ssl authentication.
this is my code but it fails with the following message :
530 5.7.0 Must issue a STARTTLS command first
btw this project is done in vs2003 so im using only System.Net.Sockets and I cant use System.Net.Mail
mailSubject = ModifyMailContent(mailSubject);
mailBody = ModifyMailContent(mailBody);
int code;
using(TcpClient smtpSocket = new TcpClient(smtpServer, mailServerPort))
using(NetworkStream ns = smtpSocket.GetStream())
{
code = GetSmtpResponse(ReadBuffer(ns));
WriteBuffer(ns, "ehlo\r\n");
string buffer = ReadBuffer(ns);
code = GetSmtpResponse(buffer);
if(buffer.IndexOf("AUTH=LOGIN") >= 0)
{
WriteBuffer(ns, "auth login\r\n");
code = GetSmtpResponse(ReadBuffer(ns));
WriteBuffer(ns, System.Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username)) + "\r\n");
code = GetSmtpResponse(ReadBuffer(ns));
WriteBuffer(ns, System.Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(password)) + "\r\n");
code = GetSmtpResponse(ReadBuffer(ns));
}
WriteBuffer(ns, "mail from: <" + mailSender + ">\r\n");
code = GetSmtpResponse(ReadBuffer(ns));
string[] splitRecipient = mailRecipient.Split(',');
foreach(string sEmailTo in splitRecipient)
{
WriteBuffer(ns, "rcpt to:<" + sEmailTo + ">\r\n");
code = GetSmtpResponse(ReadBuffer(ns));
}
WriteBuffer(ns, "data\r\n");
code = GetSmtpResponse(ReadBuffer(ns));
WriteBuffer(ns, "from:<" + mailSender + ">\r\n");
foreach(string sEmailTo in splitRecipient)
{
WriteBuffer(ns, "to:<" + sEmailTo + ">\r\n");
}
WriteBuffer(ns, "Subject:" + mailSubject + "\r\n");
WriteBuffer(ns, "\r\n" + mailBody + "\r\n.\r\n");
code = GetSmtpResponse(ReadBuffer(ns));
WriteBuffer(ns, "quit\r\n");
}
|
|
|
|
|
Hi Guys,
does anyone know how to add a trackbar into a menustrip?
Many thanks,
Phil
|
|
|
|
|
lane0p2 wrote: how to add a trackbar into a menustrip?
I didn't get you . can you be more specific ?
Thanks in advance !!
cheers,
Abhijit
|
|
|
|
|
Hi,
sorry for being vague.
if you add a menuStrip with the standard items, say within the Tools button you add another item called Opactiy, once you've clicked on this anther menu opens but this is a trackBar. so you could change the opacity by sliding the trackbar.
does this make sense?
Many thanks,
Phil
|
|
|
|
|
Sorry !!! I am still Confused . Can you please give any link of some screenshots.
cheers,
Abhijit
|
|
|
|
|
I need to aquire the bitrate(kps) for wmv files without the use of the media player, attempts to Parsing an ASF Stream in C#, C++ and VB have failed, including the examples/articles post on his site. My C++ is not that great but the example provided within the VS documentation will not compile.
Any assistance appreciated.
dotman1
|
|
|
|
|
hi. i was able to successfully place my table on the crystal report viewer however, I have too many columns that are crowded in. I want to make them fit on the page and make the text visible. How do I do that? Some column names also have quite long labels like, "Registered Address" or "Registered City Code". How do you make this visible and fit in one page. Say I have 12 columns?
|
|
|
|
|
Throw some columns out, use a very small font, change the layout..?
|
|
|
|
|
I already have set the font size to 7 but still its the same. They overlap. I can't omit the other columns because they are required information. For the layout, how do you set that? Are you referring to the list of layouts of the crystal report like "Drop Table?"
|
|
|
|
|
Hey,
I now this i kind of a broad question, if not completly trivial, but how would one program a c sharp application that would only need to open a sqlconnection once. For example:
SqlConnection mySqlConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=cache;Integrated Security=SSPI;");
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlConnection.Open();
This works fine and all but i can only access the Sql command inside that class and have to open a new sql connection if i am to use this command again... Hope this is explain good enough...
|
|
|
|
|
You do exactly that, Create the SQL connection only once, and pass the object around as a parameter to wherever you need to use it.
Or you could use the singleton pattern[^] to make it available globally (but this would be considered quite bad practise)
SQL server actually pools it's connections internally, so you will find that even if your app creates a new connection every time it needs data, SQL server will most likely be reusing the same connection every time, so if it's performance you are worried about, don't worry, it's probably already being taken care of.
Simon
|
|
|
|
|
Ok, so how would i for example make use of my "mySqlCommand" command in another class?
modified on Thursday, November 27, 2008 9:24 AM
|
|
|
|