Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
243 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 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