Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

661 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