Click here to Skip to main content
15,892,737 members
Home / Discussions / C#
   

C#

 
GeneralRe: filter datagrid bound to arraylist Pin
Drew McGhie15-Nov-06 9:55
Drew McGhie15-Nov-06 9:55 
GeneralRe: filter datagrid bound to arraylist Pin
zamillia zuma15-Nov-06 9:56
zamillia zuma15-Nov-06 9:56 
GeneralRe: filter datagrid bound to arraylist Pin
Drew McGhie15-Nov-06 10:50
Drew McGhie15-Nov-06 10:50 
GeneralRe: filter datagrid bound to arraylist Pin
zamillia zuma17-Nov-06 0:23
zamillia zuma17-Nov-06 0:23 
QuestionMaster pages and menus Pin
lsugirljte15-Nov-06 3:37
lsugirljte15-Nov-06 3:37 
AnswerRe: Master pages and menus Pin
Stefan Troschuetz15-Nov-06 6:04
Stefan Troschuetz15-Nov-06 6:04 
AnswerRe: Master pages and menus Pin
lsugirljte15-Nov-06 6:07
lsugirljte15-Nov-06 6:07 
Questioncalculating with measurements Pin
Yustme15-Nov-06 3:35
Yustme15-Nov-06 3:35 
Hi,

I'm trying to make a project which "converts" for example from meters to centimeters. I fill 20 labels with a random generated question containing a "fromUnit" and "toUnit" object.

Here is my code:

public partial class Metrics : Form
{
private double[] _answer;
private TextBox[] _textBox;
private Label[] _labels;

public Metrics()
{
InitializeComponent();
this._answer = new double[20];
this._textBox = new TextBox[20];
this._labels = new Label[20];
this.label1.Text = this.getQuestion(1, 10);
}

private string[][] lengths = new string[][]
{
new string[] {"kilometer", "1000"},
new string[] {"hectometer", "100"},
new string[] {"decameter", "10"},
new string[] {"meter", "1"},
new string[] {"decimeter", ".1"},
new string[] {"centimeter", ".01"},
new string[] {"millimeter", ".001"}
};

public string[] getUnit(int index)
{
return lengths[index];
}

private string getQuestion(int minLength, int maxLength)
{
// Create Random object
Random rand = new Random((int)DateTime.Now.Ticks);

int length = rand.Next(minLength, maxLength); // Gets the length to convert
int randNumber1 = rand.Next(0, 6); // gets the first unit random number
int randNumber2 = rand.Next(0, 6); // gets the second unit random number

while (randNumber1 == randNumber2) // loop ensure that units are not the same
{
randNumber2 = rand.Next(0, 6);
}

string[] fromUnit = getUnit(randNumber1); // gets the unit details from class
string[] toUnit = getUnit(randNumber2); // gets the unit details from class

// gets the answer (i.e. (23 * .(01 / .001)) = 230)
this._answer = length * (Convert.ToDouble(fromUnit[1]) / (Convert.ToDouble(toUnit[1])));

//return the question string
return "How much is " + length.ToString() + " " + fromUnit[0] + "(s) in " + toUnit[0] + "(s)?";
}

private void btnCalculate_Click(object sender, EventArgs e)
{

}

private void FillLabelsWithQuestions()
{
foreach (Control label in this.Controls)
{
if (label is Label)
{
label.Text = getQuestion(1, 100);
}
}
}
}

The problem is, i don't know how to check if the answer is correct which is entered in a textbox and checks the answer when the button "calculate" is pressed, because there are strings involved too.

My labels are named like this:

label1
label2
label3
etc

And so are my textboxes:

textbox1
textbox2
.....

This is a screenshot of how my Form looks like:

http://i15.tinypic.com/49icglh.jpg

Anyone any suggestion?

Thanks in advance!

AnswerRe: calculating with measurements Pin
ednrgc15-Nov-06 3:42
ednrgc15-Nov-06 3:42 
GeneralRe: calculating with measurements Pin
Yustme15-Nov-06 3:49
Yustme15-Nov-06 3:49 
QuestionHow to Check for Serialport status...? Pin
IamHuM15-Nov-06 2:59
IamHuM15-Nov-06 2:59 
AnswerRe: How to Check for Serialport status...? Pin
Rey999917-Nov-06 4:39
Rey999917-Nov-06 4:39 
QuestionDetect and Read Pen drive Pin
Ravikumar Patra15-Nov-06 2:58
professionalRavikumar Patra15-Nov-06 2:58 
AnswerRe: Detect and Read Pen drive Pin
ejuanpp15-Nov-06 4:45
ejuanpp15-Nov-06 4:45 
QuestionHow to read an exact character from text file Pin
CodeItWell15-Nov-06 2:28
CodeItWell15-Nov-06 2:28 
AnswerRe: How to read an exact character from text file Pin
Tamimi - Code15-Nov-06 2:37
Tamimi - Code15-Nov-06 2:37 
AnswerRe: How to read an exact character from text file Pin
V.15-Nov-06 2:37
professionalV.15-Nov-06 2:37 
Questionhelp for enabled property Pin
vamsimohan2115-Nov-06 1:17
vamsimohan2115-Nov-06 1:17 
AnswerRe: help for enabled property Pin
stancrm15-Nov-06 2:25
stancrm15-Nov-06 2:25 
GeneralRe: help for enabled property Pin
vamsimohan2115-Nov-06 16:29
vamsimohan2115-Nov-06 16:29 
GeneralRe: help for enabled property Pin
vinSharp15-Nov-06 20:32
vinSharp15-Nov-06 20:32 
Questionneed to convert INSTR() INTO C# Pin
M Riaz Bashir15-Nov-06 0:58
M Riaz Bashir15-Nov-06 0:58 
AnswerRe: need to convert INSTR() INTO C# Pin
J4amieC15-Nov-06 1:11
J4amieC15-Nov-06 1:11 
GeneralRe: need to convert INSTR() INTO C# Pin
M Riaz Bashir15-Nov-06 1:27
M Riaz Bashir15-Nov-06 1:27 
AnswerRe: need to convert INSTR() INTO C# Pin
Guffa15-Nov-06 4:12
Guffa15-Nov-06 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.