Solved

Getting the value returned from a method within a class library in a variable within a click event

Posted on 2006-10-31
2
224 Views
Last Modified: 2010-04-16
I have a method within a class library in this format in a project.


public system.string evaluate(string key, string value)
{
      return result
}

I call this method in my windows C# form in this format


**Windows form C# application

private void button1_Click(object sender, System.EventArgs e)
{
      
      try
      {
            string test = txted.Text;
            string testvalue = txtvalue.Text;
            string returnvalue;
            ClassLibProject cldp = new classLibProject
            returnvalue = gd.encrypt(test,testvalue);
      }
      
      catch(Exception ex)
      {
            MessageBox.Show(ex.ToString());
      }
}



I am unable to get any value in the returnvalue variable and all
I get is "Error:Identifier 'returnvalue' out of scope.


The method evaluate works very well and when I step through it,
it returns exactly what I want to see but by the time it gets
to the returnvalue value, I am not able to get the value.

Thanks.
0
Comment
Question by:Sirdots
2 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 17844853
Are you trying to access the returnvalue variable from outside the try block? if so, you need to declare the returnvalue variable outside the try block:

private void button1_Click(object sender, System.EventArgs e)
{
     string returnvalue = null;

     try
     {
          string test = txted.Text;
          string testvalue = txtvalue.Text;

          ClassLibProject cldp = new classLibProject
          returnvalue = gd.encrypt(test,testvalue);
     }
     catch(Exception ex)
     {
          MessageBox.Show(ex.ToString());
     }

     //can access returnvalue here
}
0
 

Author Comment

by:Sirdots
ID: 17844891
Thanks a lot Zephyr. It works for me. You are the man.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now