CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2000
    Posts
    49

    How to return value from a Form

    How can I return a value or a set of values from a Modally loaded form?
    Any help will be highly appreciated.
    (I don't want to use global Variables)


  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: How to return value from a Form

    Firstly, the variable must be declared public on the form. You can reference this variable using the form name on which it resides.

    Ex.
    On form2

    Public strYourString as string
    strYourString = "A form2 variable"


    on form1 you can use this variable like this

    text1 = form2.strYourString

    'text1 will now show "A form2 variable"

    David Paulson

  3. #3
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: How to return value from a Form

    write this in the form you want to return a value:

    property get MyProp() as string
    MyProp = "My Returned Value" 'set your value
    'here
    End property




    and then you can access it from another form by using:
    MyReturnedValue=form2.MyProp (form2 is the form that returns the value)

    ----------
    The @host is everywhere!
    ----------

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to return value from a Form


    'Here another way to do it (retrieve a value from your modally loaded form)

    'two forms: form1 and form2
    'on each, one commandbutton (= Command1)

    'form1 code
    option Explicit
    Dim withevents f as Form2
    private Sub Command1_Click()
    set f = new Form2
    Load f
    f.Show vbModal
    set f = nothing
    End Sub

    private Sub f_myevent(byval strMystring as string)
    MsgBox strMystring
    End Sub


    '-----------------
    'form2 code
    option Explicit
    Event myevent(byval strMystring as string)
    private Sub Command1_Click()
    RaiseEvent myevent("ThisIsMyStringValue")
    End Sub





    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: How to return value from a Form

    In From 1 - Parent form:

    Private Sub cmdCallChild_Click()
    dim strReturn
    call frmChild.ShowForm(strReturn)
    End Sub

    In form 2 - Child form:
    Public Sub ShowForm(ByRef strReturn as String)
    Me.Show
    'Return value after closing
    strReturn ="Test string from the child form."
    End Sub


    Regards,

    Michi
    MCSE, MCDBA

  6. #6
    Join Date
    Jul 2001
    Posts
    2

    Re: How to return value from a Form

    hi,

    More simple is you can use the "Tag" property of Form.

    'in the Form1
    form2.show vbModal
    strVariable=Form2.Tag


    'in the form2 u can store value
    form2.Tag="Return Message"

    regards,
    Govind


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured