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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

20 Experts available now in Live!

Get 1:1 Help Now