none
to get value from 1 form to another RRS feed

  • Question

  • i need a variable u_n of form1 in form2!!!

    i tried makin the variable public durin its decleration
    also i tried makin object of form1 in form2 and callin d var usin it still cant i'l gettin d varialbe value as null!!!!
    how do i cal it?

    Tuesday, August 4, 2009 9:00 AM

Answers

  • i did it!
    by creatin a public variable in form 2!
    and in form 1 makin an object of form 2 and assignin d value of d var to the obj. public variable!
    • Marked as answer by fathatsme Tuesday, August 4, 2009 10:37 AM
    Tuesday, August 4, 2009 10:37 AM
  • hi
    I m a beginner in c#

    you need a static class,statci member :
    Add a new class.cs file to the project

    static class GlobalClass
        {
            private static string m_globalVar = "";

            public static string GlobalVar
            {
                get { return m_globalVar; }
                set { m_globalVar = value; }
            }

        }

    Use it anywhere as :-
    GlobalClass.GlobalVar = "Some value";

    retrieve it anywhere like this:
    myFormLabel.Text = GlobalClass.GlobalVar;


    Or

    Static members are accessible without creating an instance of the
    class, and constants are obviously static. So just have a class called
    'Consts', and say:

    public class consts
    {
    public const string APP_NAME = "TheApp";
    }

    public class Class1
    {
    [STAThread]
    public static void Main(string[] args)
    {
    Console.WriteLine("I'm {0}", Consts.APP_NAME);
    }
    }

    refer this link for additional info
    http://msdn.microsoft.com/en-us/library/79b3xss3.aspx

    Hope this helps :-)
    anliS

    Regards anliS www.businessinsightsconsulting.com Please remember to mark the correct replies as answers
    • Edited by silna Friday, August 7, 2009 12:30 PM
    • Marked as answer by fathatsme Friday, August 7, 2009 1:23 PM
    Friday, August 7, 2009 12:14 PM

All replies

  • i did it!
    by creatin a public variable in form 2!
    and in form 1 makin an object of form 2 and assignin d value of d var to the obj. public variable!
    • Marked as answer by fathatsme Tuesday, August 4, 2009 10:37 AM
    Tuesday, August 4, 2009 10:37 AM
  • hi
    A better approach would be...
    I hope Form 1 and Form 2 are in the Same Solution Project of Visual Studio
    Assuming u r building a vb.net project

    Declare a Module
    and the Variable as Friend
    Example

     

     

    Module Global
    Friend var_Form1Value As String = "Value For Form 1"
    Friend var_Form2Value As String = "Value For Form2"
    End Module
    

    Also for next time post ur Programming related queries to appropriate Forum
    This is .Net Framework Related Queries Forum

    Assuming u r using vb language
    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads

    U get faster replies

    Hope this helps :-)

    Thanks
    anliS


    Regards anliS www.businessinsightsconsulting.com Please remember to mark the correct replies as answers
    • Edited by silna Friday, August 7, 2009 8:05 AM
    Friday, August 7, 2009 8:01 AM
  • thanx!!!!

    dats a new info to me!

    but here i need c# code!!!
    if u kno it dat wud b gr8!
    Friday, August 7, 2009 8:21 AM
  • hi
    I m a beginner in c#

    you need a static class,statci member :
    Add a new class.cs file to the project

    static class GlobalClass
        {
            private static string m_globalVar = "";

            public static string GlobalVar
            {
                get { return m_globalVar; }
                set { m_globalVar = value; }
            }

        }

    Use it anywhere as :-
    GlobalClass.GlobalVar = "Some value";

    retrieve it anywhere like this:
    myFormLabel.Text = GlobalClass.GlobalVar;


    Or

    Static members are accessible without creating an instance of the
    class, and constants are obviously static. So just have a class called
    'Consts', and say:

    public class consts
    {
    public const string APP_NAME = "TheApp";
    }

    public class Class1
    {
    [STAThread]
    public static void Main(string[] args)
    {
    Console.WriteLine("I'm {0}", Consts.APP_NAME);
    }
    }

    refer this link for additional info
    http://msdn.microsoft.com/en-us/library/79b3xss3.aspx

    Hope this helps :-)
    anliS

    Regards anliS www.businessinsightsconsulting.com Please remember to mark the correct replies as answers
    • Edited by silna Friday, August 7, 2009 12:30 PM
    • Marked as answer by fathatsme Friday, August 7, 2009 1:23 PM
    Friday, August 7, 2009 12:14 PM