TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Felice Massaro
NA
17
8.1k
How can I access a variable in a private void?
Apr 26 2013 8:02 AM
I have a windows application that sends and receives messages to/from a microprocessor using the serial port.
The application is working fine and does what is supposed to do. Now, I need to make some elaboration with the data I receive back from serial and I would like to access the variable "value" in SetText method. How can I access the content of that variable from another method or class? Thanks for helping.
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if (this.txtOutput.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.BeginInvoke(d, new object[] { text });
}
else
{
txtOutput.AppendText(text);
}
// capture messages from serial port
if (txtOutput.Text.Length > 0)
{
MatchCollection mc = Regex.Matches(txtOutput.Text, @"(\+|-)?\d+");
if (mc.Count > 0)
{
long value = long.Parse(mc[mc.Count - 1].Value);
if (value > 1 && value < 1000)
{
textBox2.Text = value.ToString();
}
else if (value < 2000 && value > 1000)
{
value = value - 1000;
textBox3.Text = value.ToString();
}
}
}
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
SetText(serialPort1.ReadExisting());
}
catch (Exception ex)
{
SetText(ex.ToString());
}
}
Reply
Answers (
2
)
how can show the text in the datagridview cell
how to fetch all contact from my facebook account?