-
May 23rd, 2012, 11:20 AM
#1
using variables within 2 different methods
Code:
private void timerAlarm_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (comboBoxItemsforAlarm.SelectedItem == null)
stopWatch.Stop();
else
{
int hours = stopWatch.Elapsed.Hours, minutes = stopWatch.Elapsed.Minutes;
labelStopWatch.Text = hours + ".";
if (minutes < 10)
labelStopWatch.Text += "0" + minutes;
else
labelStopWatch.Text += minutes;
double doubleStopWatch = Convert.ToDouble(labelStopWatch.Text);
}
}
====================================================================
private void btnAddTimer_Click(object sender, EventArgs e)
{
if (comboBoxItemAlarm.Items.Count == 0 && maskedTime.Text == null)
{
MessageBox.Show("select an item");
}
else
{
if (comboBoxItemAlarm.SelectedItem != null)
{
comboBoxItemsforAlarm.Items.Add(comboBoxItemAlarm.SelectedItem + "-" + maskedTime.Text);
}
string str = comboBoxItemAlarm.SelectedItem.ToString();
string[] into = str.Split('-');
double timeAllocated = Convert.ToDouble(into[1]);
double timeAlarm = Convert.ToDouble(maskedTime.Text);
if(timeAlarm > timeAllocated)
{
MessageBox.Show("eheheh");
}
}
}
I want to use if statement for variables in these 2 methods, to compare the timeAlarm with the doubleStopWatch, because of their declaration scope, it seems imposible and if I declare it outside their method it will not pick the right argument, like this:
if(timeAlarm==doubleStopWatch)
//do something
-
May 23rd, 2012, 12:58 PM
#2
Re: using variables within 2 different methods
What do you mean with "it will not pick the right argument"?
-
May 23rd, 2012, 03:53 PM
#3
Re: using variables within 2 different methods
Thanks. It's may be a mis-use of language. What I mean is if I declare them outside the the methods they are now, I'll not be able to assign value to them. Thanks.
-
May 23rd, 2012, 04:02 PM
#4
Re: using variables within 2 different methods
But you should be able to do so.
There's no reason why you couldn't do that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|