By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

passing parameters between forms

P: n/a
How do I pass an argument from one form to another?
I do the following:
FormA:
dim strFilename as string ="Filename"
dim frmLayout1 as New frmLayout(strFilename)
frmLayout1.Show()

frmLayout:
Private strFilename as string
..
..
Sub New(Filename as string)
..
..strFilename = Filename
..
..
Private Sub frmLayout_Load(...)
dim strLayout as new Filestream(strFilename, FileMode.Open)

At this point I get an error because strFilename is empty (Nothing)

When I step thru the code, I can see that the parm is correctly passed to
and stored by the Sub New
What am I doing wrong?

Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You could either use a property (in a Module) and access the value there
(from any form) or

In Form A:

Private sub OpenNewForm()
Dim strValue as string
Dim frm as FormB
frm.GetDetails(strValue)
frm = nothing
End Sub
In Form B

Private mstrValue as string

Public Sub GetDetails(byval vstrValue as string)
mstrValue = vstrValue
me.show
end sub

Gerry

"Jan Warning" wrote:
How do I pass an argument from one form to another?
I do the following:
FormA:
dim strFilename as string ="Filename"
dim frmLayout1 as New frmLayout(strFilename)
frmLayout1.Show()

frmLayout:
Private strFilename as string
..
..
Sub New(Filename as string)
..
..strFilename = Filename
..
..
Private Sub frmLayout_Load(...)
dim strLayout as new Filestream(strFilename, FileMode.Open)

At this point I get an error because strFilename is empty (Nothing)

When I step thru the code, I can see that the parm is correctly passed to
and stored by the Sub New
What am I doing wrong?

Nov 21 '05 #2

P: n/a
Correction to my last post

Dim frm as FormB

should have read

Dim frm as New FormB

Gerry
"Jan Warning" wrote:
How do I pass an argument from one form to another?
I do the following:
FormA:
dim strFilename as string ="Filename"
dim frmLayout1 as New frmLayout(strFilename)
frmLayout1.Show()

frmLayout:
Private strFilename as string
..
..
Sub New(Filename as string)
..
..strFilename = Filename
..
..
Private Sub frmLayout_Load(...)
dim strLayout as new Filestream(strFilename, FileMode.Open)

At this point I get an error because strFilename is empty (Nothing)

When I step thru the code, I can see that the parm is correctly passed to
and stored by the Sub New
What am I doing wrong?

Nov 21 '05 #3

P: n/a
I tried it (I noticed your mistake) and it worked. Thanks a lot.
But I am still wondering why my original code did not work.

Regards, Jan Warning
"dotnetnewbie" <do**********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Correction to my last post

Dim frm as FormB

should have read

Dim frm as New FormB

Gerry
"Jan Warning" wrote:
How do I pass an argument from one form to another?
I do the following:
FormA:
dim strFilename as string ="Filename"
dim frmLayout1 as New frmLayout(strFilename)
frmLayout1.Show()

frmLayout:
Private strFilename as string
..
..
Sub New(Filename as string)
..
..strFilename = Filename
..
..
Private Sub frmLayout_Load(...)
dim strLayout as new Filestream(strFilename, FileMode.Open)

At this point I get an error because strFilename is empty (Nothing)

When I step thru the code, I can see that the parm is correctly passed to
and stored by the Sub New
What am I doing wrong?

Nov 21 '05 #4

P: n/a
Yeah.. Your original would have been better... Was it the real code
(copy/paste) ? If so can you reproduce this behavior in a new project ?

--
Best Regards
Yanick
"Jan Warning" <ja*********@wanadoo.nl> a écrit dans le message de
news:On*************@TK2MSFTNGP15.phx.gbl...
I tried it (I noticed your mistake) and it worked. Thanks a lot.
But I am still wondering why my original code did not work.

Regards, Jan Warning
"dotnetnewbie" <do**********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Correction to my last post

Dim frm as FormB

should have read

Dim frm as New FormB

Gerry
"Jan Warning" wrote:
How do I pass an argument from one form to another?
I do the following:
FormA:
dim strFilename as string ="Filename"
dim frmLayout1 as New frmLayout(strFilename)
frmLayout1.Show()

frmLayout:
Private strFilename as string
..
..
Sub New(Filename as string)
..
..strFilename = Filename
..
..
Private Sub frmLayout_Load(...)
dim strLayout as new Filestream(strFilename, FileMode.Open)

At this point I get an error because strFilename is empty (Nothing)

When I step thru the code, I can see that the parm is correctly passed to and stored by the Sub New
What am I doing wrong?


Nov 21 '05 #5

P: n/a
It had to replace a defective harddisk, so I could not reply any sooner.

I could reproduce this behavior in a small new project.
I also discobvered wahat I did wrong, although I still don't quite
understand it.

I passed the parameter from FormA to FormB as follows:
Private Parm as string
dim myFormb as New FormB(Parm)
FormB.Show

In FormB:
Private Filename as string
..

Public Sub New(byval Filename as string)
Filename = Filename
etc.

Public Sub Form2_Load .....
xxxx = Filename

Now filename appears to be empty (Nothing)

when I change the code to"
Private myFilename as string
..

Public Sub New(byval Filename as string)
myFilename = Filename
etc.

Public Sub Form2_Load .....
xxxx = myFilename

then everything is fine.

as I said, I don't quite understand, but it works.

Best regards, Jan Warning

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:ug******************@TK2MSFTNGP14.phx.gbl...
Yeah.. Your original would have been better... Was it the real code
(copy/paste) ? If so can you reproduce this behavior in a new project ?

--
Best Regards
Yanick
"Jan Warning" <ja*********@wanadoo.nl> a écrit dans le message de
news:On*************@TK2MSFTNGP15.phx.gbl...
I tried it (I noticed your mistake) and it worked. Thanks a lot.
But I am still wondering why my original code did not work.

Regards, Jan Warning
"dotnetnewbie" <do**********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
> Correction to my last post
>
> Dim frm as FormB
>
> should have read
>
> Dim frm as New FormB
>
> Gerry
>
>
> "Jan Warning" wrote:
>
>> How do I pass an argument from one form to another?
>> I do the following:
>> FormA:
>> dim strFilename as string ="Filename"
>> dim frmLayout1 as New frmLayout(strFilename)
>> frmLayout1.Show()
>>
>> frmLayout:
>> Private strFilename as string
>> ..
>> ..
>> Sub New(Filename as string)
>> ..
>> ..strFilename = Filename
>> ..
>> ..
>> Private Sub frmLayout_Load(...)
>> dim strLayout as new Filestream(strFilename, FileMode.Open)
>>
>> At this point I get an error because strFilename is empty (Nothing)
>>
>> When I step thru the code, I can see that the parm is correctly passed to >> and stored by the Sub New
>> What am I doing wrong?
>>
>>
>>
>>



Nov 21 '05 #6

P: n/a

"Jan Warning" <ja*********@wanadoo.nl> schrieb im Newsbeitrag
news:el*************@TK2MSFTNGP15.phx.gbl...
It had to replace a defective harddisk, so I could not reply any sooner.

I could reproduce this behavior in a small new project.
I also discobvered wahat I did wrong, although I still don't quite
understand it.

I passed the parameter from FormA to FormB as follows:
Private Parm as string
dim myFormb as New FormB(Parm)
FormB.Show

In FormB:
Private Filename as string
.

Public Sub New(byval Filename as string)
Filename = Filename
etc.

Names are resolved inside out. "Filename = Filename" assigns the argument to
the argument, i.e. it changes nothing. To change the field of the Form,
write

me.filename = filename

Public Sub Form2_Load .....
xxxx = Filename

Now filename appears to be empty (Nothing)

when I change the code to"
Private myFilename as string
.

Public Sub New(byval Filename as string)
myFilename = Filename
etc.

Public Sub Form2_Load .....
xxxx = myFilename

then everything is fine.

as I said, I don't quite understand, but it works.

"myfilename = " accesses the field of the Form because there is no local
variable with the name "myfilename"

Armin

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.