PDA

Click to See Complete Forum and Search --> : Passing parameters between forms...


Darren
Dec 13th, 2001, 03:35 AM
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.

Bananafish
Dec 13th, 2001, 09:57 AM
a) In the Form you wish to pass parms to, set up a property/varible for each property



Private mstrParam As String
Property Param1() As String
Get
Param1 = mstrParam
End Get
Set(ByVal Value As String)
mstrParam = Value
End Set
End Property



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



Dim objForm As New frmTwo()
With objForm
.Param1 = "Passing a string"
.Show()
End With
objForm = Nothing



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

karen17
Dec 13th, 2001, 07:15 PM
Thank you Darren and Bananafish,

I'll go try it out...

Thank you both alot.

Regards,
Karen17

wu7up
Dec 21st, 2001, 12:27 AM
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

karen17
Dec 21st, 2001, 03:13 AM
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

wu7up
Jan 8th, 2002, 07:38 PM
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

carlblanchard
Sep 19th, 2003, 11:00 AM
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

Edneeis
Sep 19th, 2003, 11:41 AM
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:

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

Public Sub ShowSingleInstance(ByVal childType As Type)
ShowSingleInstance(childType, Nothing)
End Sub

'syntax for no args
ShowSingleInstance(GetType(frmChildReplace))

'syntax with args
ShowSingleInstance(GetType(frmChildAdd), New Object() {"Testing..."})

hellswraith
Sep 19th, 2003, 01:08 PM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchworkingwithmultipleformsinvisualbasicnetupgradingtonet.asp

Required reading....

carlblanchard
Sep 22nd, 2003, 04:22 AM
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

Edneeis
Sep 22nd, 2003, 10:00 AM
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:

'in the form to be created

'have a private variable to hold the local reference
Private _RecordId As String

'make the constructor
Public Sub New(recordID As String)
'call the default constructor so that all your controls still get created
Me.New()
'assign the passed in string to the local one for later use
_RecordId=recordID
End Sub

carlblanchard
Sep 23rd, 2003, 06:18 AM
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

Edneeis
Sep 23rd, 2003, 09:54 AM
What don't you understand specifically? If you it doesn't work what happens? The same error as before? Post more code.