Results 1 to 13 of 13

Thread: Passing parameters between forms...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    Berkshire
    Posts
    121
    Is .NET a whole lot different from VB6 on this one then?
    I don't have .NET, just browsing the forum, but i know in VB6 you could either use a module with globally declared variables to pass stuff between forms, or you could just call a particular subroutine on another form:

    eg. Call Form1.Test

    and on Form1 you would have

    Private Sub Test()
    WhatYouWantToPass = 5
    End Sub

    Now use that variable.

  2. #2
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    a) In the Form you wish to pass parms to, set up a property/varible for each property

    VB Code:
    1. Private mstrParam As String
    2.     Property Param1() As String
    3.         Get
    4.             Param1 = mstrParam
    5.         End Get
    6.         Set(ByVal Value As String)
    7.             mstrParam = Value
    8.         End Set
    9.     End Property

    b) then you can pass the paramater using the new property,
    for example

    VB Code:
    1. Dim objForm As New frmTwo()
    2.         With objForm
    3.             .Param1 = "Passing a string"
    4.             .Show()
    5.         End With
    6.         objForm = Nothing

    Well - thats how I would have done it in vb6 anyway...

  3. #3
    Junior Member
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    24
    Thank you Darren and Bananafish,

    I'll go try it out...

    Thank you both alot.

    Regards,
    Karen17

  4. #4
    Junior Member
    Join Date
    Jan 2001
    Location
    Shanghai China
    Posts
    20

    How to transfer parameters in a form in vb.net web application

    Hi,
    Do you know how to transfer parameters in a form in vb.net web application?
    I can do it by defining a global variable in the module,but I want to define a variable with the scope is in one form not globally.I have tried defining a variable in the form like following:
    '--------------------------------
    Public Class ProductGroup
    Inherits System.Web.UI.Page
    Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents ddForms As System.Web.UI.WebControls.DropDownList

    public strTest as string
    '-------------------------------------

    But , after I set the value in one sub, I can't get the value of strTest in other sub.

    Can you help me?

    Thanks

    wu7up

  5. #5
    Junior Member
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    24
    wu7up,

    for this problem, i solve it by saving the arguements into sessions.
    Sessions worked just like a global variable.

    Here are some samples....

    to save ur values into sessions:
    Session("Name") = labelName.text

    To retrieve values:
    labelValue.text = Session("Name")

    Hope this can help you solve your problem.

    Regards
    Karen17

  6. #6
    Junior Member
    Join Date
    Jan 2001
    Location
    Shanghai China
    Posts
    20

    about session

    Hi,karen17

    I think the session variable will die until the session ends. Then there will be a lot of session variables which should origianly be form-class variables in my program, and some of them have the same names, it will be confusing.

    By the way, your suggestion has thrown light on my mind that I can define a session variable which is the connection to database.

    Do you know, how can I define the session variable as SqlConnection ?


    Thanks

    wu7up

  7. #7
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Thumbs up ummm

    ok not sure what the last couple of messages are about but the first couple will answer my question of passing stuff between forms however what about MDI forms i have this code on the MDIParent

    Public Sub ShowSingleInstance(ByVal childType As Type)
    For Each child As Form In Me.MdiChildren
    If child.GetType Is childType Then
    'already loaded so bring to foreground
    child.Activate()
    Return
    End If
    Next
    'not loaded yet so create
    Dim frm As Form = Activator.CreateInstance(childType)
    frm.MdiParent = Me
    frm.Show()
    End Sub

    this basically allows opening of a child mdi from a child mdi very nice script to
    its called by this

    parent.ShowSingleInstance(GetType(AppointmentDetails))

    Ive tried to make the two merge together how ever im really really new to VB so havnt a clue really

    any of you got a clue of mixing them both together
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: ummm

    Originally posted by carlblanchard
    ok not sure what the last couple of messages are about but the first couple will answer my question of passing stuff between forms however what about MDI forms i have this code on the MDIParent

    Public Sub ShowSingleInstance(ByVal childType As Type)
    For Each child As Form In Me.MdiChildren
    If child.GetType Is childType Then
    'already loaded so bring to foreground
    child.Activate()
    Return
    End If
    Next
    'not loaded yet so create
    Dim frm As Form = Activator.CreateInstance(childType)
    frm.MdiParent = Me
    frm.Show()
    End Sub

    this basically allows opening of a child mdi from a child mdi very nice script to
    its called by this

    parent.ShowSingleInstance(GetType(AppointmentDetails))

    Ive tried to make the two merge together how ever im really really new to VB so havnt a clue really

    any of you got a clue of mixing them both together
    What is it you are trying to merge to this? You should probably start your own thread since the question is different enough.

    If you just want to pass constructor arguments to the single instance then this is how you do it:
    VB Code:
    1. Public Sub ShowSingleInstance(ByVal childType As Type, ByVal args() As Object)
    2.         For Each child As Form In Me.MdiChildren
    3.             If child.GetType Is childType Then
    4.                 'already loaded so bring to foreground
    5.                 child.Activate()
    6.                 Return
    7.             End If
    8.         Next
    9.         'not loaded yet so create
    10.         Dim frm As Form = Activator.CreateInstance(childType, args)
    11.         frm.MdiParent = Me
    12.         frm.Show()
    13.     End Sub
    14.  
    15.     Public Sub ShowSingleInstance(ByVal childType As Type)
    16.         ShowSingleInstance(childType, Nothing)
    17.     End Sub
    18.  
    19. 'syntax for no args
    20. ShowSingleInstance(GetType(frmChildReplace))
    21.  
    22. 'syntax with args
    23. ShowSingleInstance(GetType(frmChildAdd), New Object() {"Testing..."})

  9. #9
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

  10. #10
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Thumbs up hey Edneeis cheers mate

    Hey Edneeis IM having a problem i keep getting this msg
    ========================================
    Additional information: Constructor on type ProjectName.AppointmentDetails not found.
    ========================================
    It's breaking around the point of

    Dim frm As Form = Activator.CreateInstance((childType), args)

    -----------------------------------------------------------------------------
    this is what i have

    Main MDI Parent

    Public Sub ShowSingleInstance(ByVal childType As Type, ByVal args() As Object)
    For Each child As Form In Me.MdiChildren
    If child.GetType Is childType Then
    'already loaded so bring to foreground
    child.Activate()
    Return
    End If
    Next
    'not loaded yet so create
    Dim frm As Form = Activator.CreateInstance((childType), args)
    frm.MdiParent = Me
    frm.Show()

    End Sub

    -------------------------------------------------------------------------------
    call the sub as you said

    parent.ShowSingleInstance(GetType(AppointmentDetails), New Object() {strRecordId})
    -------------------------------------------------------------------------------

    Also when this works how would i grab hold of the agrument in the appointmentdetails form

    Sorry im only 2 weeks old in VB.net before i used to program asp so im a bit thick at the moment
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well you should probably read up on constructors, but basicalyy a constructor is the method that gets called when an object is created (or constructed). Which in VB is the New method. The IDE adds a default constructor (meaning it takes no parameters) for you and in it adds all the controls and what not that you add at designtime. You can see it hidden in the auto generated code of the form. You can add your own constructors that take parameters elsewhere in your code. So in order for you to pass 'strRecordId' to the form it must already have a constructor (or New method) that takes a parameter of 'strRecordId's type. Otherwise you get the error that you did because it can't find a constructor to match.

    Here is an example of adding a constructor to a form:
    VB Code:
    1. 'in the form to be created
    2.  
    3. 'have a private variable to hold the local reference
    4. Private _RecordId As String
    5.  
    6. 'make the constructor
    7. Public Sub New(recordID As String)
    8.    'call the default constructor so that all your controls still get created
    9.    Me.New()
    10.    'assign the passed in string to the local one for later use
    11.    _RecordId=recordID
    12. End Sub

  12. #12
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    dur

    hi sorry i cant see how you make this work ???

    so how would i code my mdi stuff with your constructor stuff ?
    Ive read up about it but dont understand it sorry
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What don't you understand specifically? If you it doesn't work what happens? The same error as before? Post more code.

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