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
227 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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