A form passing a parameter to another form


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: A form passing a parameter to another form

Hybrid View

  1. #1
    Bill Gaddam Guest

    A form passing a parameter to another form


    Please Help,

    I am new VB programmer and would like to do the following things in VB6:

    1. I want to pass a parameter from one form to anothr form. How would I
    do this? Can I use the .Text value of a text control and have the second
    form use this control .Text value? How will I pass this value to a stored
    procedure of the second forms's ADO data control?

    2. I would like to pop up a Modal form and select a row from a data grid
    of this form, and bring some values to the calling form?

    3. I have two data combo controls on a form that will allow the user to
    select parts of General Ledger account numbers. The first control (dtcCostCenter)will
    allow me to select the Cost Center of the Chart of Accounts. The second
    control (dtcAccount) should allow the user to select only the Accounts that
    belong to the Cost Center that was selected in the dtcCostCenter control.
    The dtcCostCenter control is bound to an ADO Data Control which in turn
    is bound to a Cost Center Table. The dtcAccount control is bound to another
    ADO control that uses a Stored Procedure with a Where clause (Select CostCenter,
    AccountNum from Accounts_T Where CostCenter = @CostCenter). How will I pass
    this parameter to this stored procedure from the dtcCostCenter.Text and refresh
    the ADO control that is bound to the dtcAccount contnrol?

    I have about 5 books on VB6 but none of them show me the solution to these
    problems.

    Thanks for your help!

    Bill
    After modifying the SQL statement of the ADO data control how will I refresh
    the contents of the

  2. #2
    Andrew Grillage Guest

    Re: A form passing a parameter to another form

    In your books you should find some information on scope of variables.
    Variables or object properties that are declared public can be read by other
    modules/forms.

    If you need to use a modal form, do not unload it until you get the
    information you need from it. In the modal form, call me.hide and then
    unload it from the parent form after you finish collecting the information
    you need.

    --
    Andrew Grillage
    http://vbdata.iwarp.com


    "Bill Gaddam" <williamg@bytes-intl.com> wrote in message
    news:38fe31f2$1@news.devx.com...
    >
    > Please Help,
    >
    > I am new VB programmer and would like to do the following things in VB6:
    >
    > 1. I want to pass a parameter from one form to anothr form. How would I
    > do this? Can I use the .Text value of a text control and have the second
    > form use this control .Text value? How will I pass this value to a stored
    > procedure of the second forms's ADO data control?
    >
    > 2. I would like to pop up a Modal form and select a row from a data grid
    > of this form, and bring some values to the calling form?
    >
    > 3. I have two data combo controls on a form that will allow the user to
    > select parts of General Ledger account numbers. The first control

    (dtcCostCenter)will
    > allow me to select the Cost Center of the Chart of Accounts. The second
    > control (dtcAccount) should allow the user to select only the Accounts

    that
    > belong to the Cost Center that was selected in the dtcCostCenter control.
    > The dtcCostCenter control is bound to an ADO Data Control which in turn
    > is bound to a Cost Center Table. The dtcAccount control is bound to

    another
    > ADO control that uses a Stored Procedure with a Where clause (Select

    CostCenter,
    > AccountNum from Accounts_T Where CostCenter = @CostCenter). How will I

    pass
    > this parameter to this stored procedure from the dtcCostCenter.Text and

    refresh
    > the ADO control that is bound to the dtcAccount contnrol?
    >
    > I have about 5 books on VB6 but none of them show me the solution to these
    > problems.
    >
    > Thanks for your help!
    >
    > Bill
    > After modifying the SQL statement of the ADO data control how will I

    refresh
    > the contents of the




  3. #3
    Liam Grossmann Guest

    Re: A form passing a parameter to another form


    You should really use properties. The code below should help you.

    Liam
    http://www.vbexpress.com


    '// Call the child form like this.
    Private cmdChild_Click()

    Dim f as frmChild

    Set f = New frmChild
    f.Show vbModal
    if f.RC = vbOK then
    Msgbox 'Selected Grid Id is' & f.Id
    end if

    Set f = Nothing

    End Sub


    '// In the child form, you'll have 2 properties. RC tells
    '// what the user pressed and id tells you the id of the
    '// record selected on the grid.

    Private mRC As VbMsgBoxResult '// RC property.
    Private mId As Long '// Id property.

    Public Property Let RC(ByVal vRC As VbMsgBoxResult)
    mRC = vRC
    End Property

    Public Property Get RC() As VbMsgBoxResult
    RC = mRC
    End Property

    Public Property Let Id(ByVal vId As Long)
    mId = vId
    End Property

    Public Property Get Id() As Long
    Id = mId
    End Property

    Private Sub cmdOK_Click()
    RC = vbOK
    Id = SelectedIdonGrid()
    End Sub

    Private Sub Command1_Click()
    RC = vbCancel
    Id = -1
    End Sub



    "Andrew Grillage" <andrew@iishvara.com> wrote:
    >In your books you should find some information on scope of variables.
    >Variables or object properties that are declared public can be read by other
    >modules/forms.
    >
    >If you need to use a modal form, do not unload it until you get the
    >information you need from it. In the modal form, call me.hide and then
    >unload it from the parent form after you finish collecting the information
    >you need.
    >
    >--
    >Andrew Grillage
    >http://vbdata.iwarp.com
    >
    >
    >"Bill Gaddam" <williamg@bytes-intl.com> wrote in message
    >news:38fe31f2$1@news.devx.com...
    >>
    >> Please Help,
    >>
    >> I am new VB programmer and would like to do the following things in VB6:
    >>
    >> 1. I want to pass a parameter from one form to anothr form. How would

    I
    >> do this? Can I use the .Text value of a text control and have the second
    >> form use this control .Text value? How will I pass this value to a stored
    >> procedure of the second forms's ADO data control?
    >>
    >> 2. I would like to pop up a Modal form and select a row from a data grid
    >> of this form, and bring some values to the calling form?
    >>
    >> 3. I have two data combo controls on a form that will allow the user

    to
    >> select parts of General Ledger account numbers. The first control

    >(dtcCostCenter)will
    >> allow me to select the Cost Center of the Chart of Accounts. The second
    >> control (dtcAccount) should allow the user to select only the Accounts

    >that
    >> belong to the Cost Center that was selected in the dtcCostCenter control.
    >> The dtcCostCenter control is bound to an ADO Data Control which in turn
    >> is bound to a Cost Center Table. The dtcAccount control is bound to

    >another
    >> ADO control that uses a Stored Procedure with a Where clause (Select

    >CostCenter,
    >> AccountNum from Accounts_T Where CostCenter = @CostCenter). How will

    I
    >pass
    >> this parameter to this stored procedure from the dtcCostCenter.Text and

    >refresh
    >> the ADO control that is bound to the dtcAccount contnrol?
    >>
    >> I have about 5 books on VB6 but none of them show me the solution to these
    >> problems.
    >>
    >> Thanks for your help!
    >>
    >> Bill
    >> After modifying the SQL statement of the ADO data control how will I

    >refresh
    >> the contents of the

    >
    >



  4. #4
    Join Date
    Nov 2007
    Posts
    5
    Hi!

    Very good example Liam! But, what about the inverse process?

    I mean, let's suppose we have a parent form with an array. We want to populate the array picking up one value at a time from a child form.

    In the child form cmdOK_click() event we need to check if the value to be added is already present in the parent form array. If so, an error message box is displayed, the value is not added and the child form is not hidden, letting the user select another value.

    In this scenario, the child form must be aware of the values present in the parent form array.

    I found two solutions, but they both seem not so "professional":

    1) I can declare a
    Code:
    "Public ParentArray() as ..."
    variable in the child form.
    Then, I pass the array to the child form:
    Code:
    dim f as New frmChildForm
    f.ParentArray() = MyArray()
    f.Show 1, vbModal
    This solves the problem, but doubles the memory needed to store MyArray. This may be a problem with very large arrays, and I think it's not conceptually correct.

    2) I can refer directly to MyArray from frmChild. In the cmdOK_click() event I write something like

    Code:
    dim i
    for i = 0 to ubound(frmParent.MyArray)
       if frmParent.MyArray(i) = ValueToAdd then .......
    next
    This is even worse than 1).

    Can someone please provide a good solution to this?

    ciao!
    Last edited by disti; 11-06-2007 at 08:32 AM.

  5. #5
    Join Date
    Nov 2007
    Posts
    5
    I found that solution 1) is not working because arrays can't be declared as public in forms.

    Help me please!

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What did you try that isn't working?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  7. #7
    Join Date
    Nov 2007
    Posts
    5
    if you declare for example:
    Code:
    Public ParentArray() as Integer
    on top of the child form, you get the following compile error:

    "Constants, fixed length strings, arrays, user-defined types and declare statements not allowed as public members of object modules."

    So, to solve my problem, you can't use
    Code:
    dim f as New frmChildForm
    f.ParentArray() = MyArray()
    f.Show 1, vbModal
    beacuse f.ParentArray can't be declared.

  8. #8
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Try putting your declaration in a module.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  9. #9
    Join Date
    Nov 2007
    Posts
    5
    Try putting your declaration in a module.
    Of course this would work, but the array declared in the module would be global to the entire project.

    I just wonder if there is a better solution.

  10. #10
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    It would be exposed for use to the entire project, but that does not mean you would have to use it anywhere else.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  11. #11
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    and the array declared in the form too

    what about using a public function :

    Code:
    function returnArray(ByRef ExternalArray() as myType)
    ExternalArray = MyArray
    end function
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center