473,382 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

passing parameters between forms

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
6 1232
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
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
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adrian Parker | last post by:
Is it possible to pass data between forms as you pass parameters into a function? I know I can add a class and members as to share data, or create a module with public variables, is this the...
2
by: Bob | last post by:
I'm new to Access projects and SQL server and am not a veteran VB programmer. There's a cry for help! I'm attempting to print the current form on screen by using a command button which the user...
0
by: Zlatko Matiæ | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
5
by: rettigcd | last post by:
Hello, I need to create a custome form that operates similar to the MsgBox() and InputBox() functions. I can't figure out how to pass data to a MODAL dialog box (form). I've tried 3...
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
0
by: Neelima Godugu | last post by:
Hi All, I have developed a windows forms user control, which I am going to host in Internet Explorer.. I am familiar with the security settings requirement inorder to do the above. I have...
4
by: David Freeman | last post by:
Hi There! I'm just wondering if there's a way to pass parameters (as if you were passing parameters to a ASCX web control) when calling an ASPX page? e.g. MyDetailsPage.UserName = "david" ...
3
hyperpau
by: hyperpau | last post by:
Hi there guys! I have a Form where there are three comboboxes. This comboboxes are used as references for the parameter of 3 fields in a query. when I hit a command button in my form, it opens...
3
by: RoadRunner | last post by:
Hi, I am having a problem. I have a very simple employee database. The client needs to see everything on a form before any updates or deletions can be made. I have a form that loads with two...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.