Click to See Complete Forum and Search --> : help in multi D array using c#


eteq
February 17th, 2007, 02:08 PM
i need to do a simple project with c# using win forms.
my projects is about teaching children ABC by spelling word from given randomly alphabets(A to Z) whenever they were given any image. the children need to drag and drop the words in the text label and fill it in the text box given to complete their exercise.
here are the examples.

e.g:
1. given picture shown Bear image in the picture box
1.then in the label under given randomly alphabets : R, E, A, B
3. so the children need to drag and drop the words given to the text box to spell it correctly
4. every time they start or refresh the exercise, the alphabets for the BEAR always differ.

the problems is:
1. how to random the alphabets so that every time they do the exercise, the alphabets always differ.
2. how to use mouse drag and drop event(the coding)

*please help me because i'm new in this C#

Talikag
February 17th, 2007, 02:58 PM
I didn't use the drag & drop so far, but I can tell you how to random alphabets: Make a string called randChar with the chars you need:

string randChar = "abcdefghijklmnopqrstuvwxyz";

Now, random a number between 0 and 25 and do that:

for(int i = 1; i<=4; i++)
{
Random rnd = new Random;
int num = rnd.Next(26);
this.Controls["textBox" + i].Text = randChar[num];
}

One more things you need to do is the real answer, one possible way is:

for(int i = 0; i<4; i++)
{
do
{
Random rnd = new Random;
int num = rnd.Next(26);
}
while(randChar[num] != currectImg.Tag);
this.Controls["textBox" + i].Text = randChar[num];
}
this.textBox5.Text = currectImg.Text;
Random rnd = new Random;
int num = rnd.Next(1,5);
int temp;
temp = this.Controls["textBox" + num].Left;
this.Controls["textBox" + num].Left = this.textBox5.Left;
this.textBox5.Left = temp;

The Tag of the currectImage will contain the answer (for example: Bear - B).
The right answer will be in the same textbox, but not in the same place.
BTW: If you don't understand the code, say that and Ill explain :P

TheCPUWizard
February 17th, 2007, 04:14 PM
for(int i = 1; i<=4; i++)
{
Random rnd = new Random;
int num = rnd.Next(26);
this.Controls["textBox" + i].Text = randChar[num];
}


This code will duplicate characters, and is not going to use each character once and only once.....

eteq
February 17th, 2007, 10:15 PM
tanx a lot.the coding helps..

eteq
February 17th, 2007, 10:32 PM
for(int i = 1; i<=4; i++)
{
Random rnd = new Random;
int num = rnd.Next(26);
this.Controls["textBox" + i].Text = randChar[num];
}


tanx for the help.but i still did not understand one certain thing.
so how i need to compare the length for every word that e.g Elephant, crocodile
to call the randchar because what u give is only for 4 char (BEAR)....
(for(int i = 1; i<=4; i++)).and can i use counter for this solution?

does i need to define 1 temp like Length to compare every length of the words.
i hope u can understand what i mean because i dunno how to explain it here.

Talikag
February 18th, 2007, 09:22 AM
As I said, there will be 5th TextBox, when there will be the real answer. The real answer will be located in the same TextBox, but this textbox will change his location each time:

string randChar = "abcdefghijklmnopqrstuvwxyz";
for(int i = 0; i<4; i++)
{
do
{
Random rnd = new Random;
int num = rnd.Next(26);
}
while(randChar[num] != currectImg.Tag);
this.Controls["textBox" + i].Text = randChar[num];
}
this.textBox5.Text = currectImg.Text;
Random rnd = new Random;
int num = rnd.Next(1,5);
int temp;
temp = this.Controls["textBox" + num].Left;
this.Controls["textBox" + num].Left = this.textBox5.Left;
this.textBox5.Left = temp;

There won't appear the real answer twice, but this mode is possible:
B, B, B, B, S (S is the currect answer). If you want to block that, you can either use do while(which will be slow and unuseful) or use linked list (structs of chars that each struct contains a pointer to the next char), but it will be hard a bit :S

Good luck.

eteq
February 18th, 2007, 11:15 AM
ok.tanx.i've try it and it works...tanx a million