473,320 Members | 2,097 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,320 software developers and data experts.

passing info from one form to another

Guy
Hi,

I'm working in vb.net and have one form that creates a second form. I need
the first form pass info to the second form.

I tried using a shared property in the first form and got this error :
Cannot refer to an instance member of a class from within a shared method or
shared member initializer without an explicit instance of the class.

I changed the shared property to public and got this error :
Reference to a non-shared member requires an object reference.

Does anyone know how I could do this?

Thanks,
Guy

Jul 21 '05 #1
5 1449
liu
in your form2, create a public variable or property(heheh i dont know what
are the differences of these 2)

dim f2 as new form2
f2.variable1 = "my value1"
f2.variable2 = "my value2"
f2.show()
Jul 21 '05 #2
Guy
thanks for the response, liu.

I tried your idea but am still getting the same errors.

Guy

"liu" wrote:
in your form2, create a public variable or property(heheh i dont know what
are the differences of these 2)

dim f2 as new form2
f2.variable1 = "my value1"
f2.variable2 = "my value2"
f2.show()

Jul 21 '05 #3
Guy,

Are you sure that you do not need a modal form.

dim frm2 as new form2
frm2.MyPublicPropertyThatINeed = "whatever"
frm.showdialog

Cor
Jul 21 '05 #4
"Guy" <Gu*@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
Hi,

I'm working in vb.net and have one form that creates a second form. I need
the first form pass info to the second form.
I prefer to use the form constructor to send in any information the form may
need.

Dim f2 As New Form2(myData);
I tried using a shared property in the first form and got this error :
Cannot refer to an instance member of a class from within a shared method
or
shared member initializer without an explicit instance of the class.
A shared member can only talk to other shared members directly.
I changed the shared property to public and got this error :
Reference to a non-shared member requires an object reference.
One of the members is still shared.
Does anyone know how I could do this?
You have to pass some data around at some point. Now it doesn't really make
much sense having the variables shared since then they have class scope
rather than instance scope, and I assume you're trying to access instance
data. Thus, if you don't want to use the constructor option above you can
use liu's suggestion, just make sure that none of the variables or methods
setting them are Shared.
Thanks,
Guy

Jul 21 '05 #5
I do recommend using constructor to pass data from form to form. Just
initalize the new form with the data you need to pass and handle them in the
constructor of the newly launched form. In C#, it looks like this:

MyNewForm newForm=new MyNewForm(Info1,Info2);
newForm.Show();

In MyNewForm:

public MyNewForm(string Info1, string Info2)
{
#assign value of Info1 and Info2 to their respective variable
}

cheers,
yizhe
"Sean Hederman" wrote:
"Guy" <Gu*@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
Hi,

I'm working in vb.net and have one form that creates a second form. I need
the first form pass info to the second form.


I prefer to use the form constructor to send in any information the form may
need.

Dim f2 As New Form2(myData);
I tried using a shared property in the first form and got this error :
Cannot refer to an instance member of a class from within a shared method
or
shared member initializer without an explicit instance of the class.


A shared member can only talk to other shared members directly.
I changed the shared property to public and got this error :
Reference to a non-shared member requires an object reference.


One of the members is still shared.
Does anyone know how I could do this?


You have to pass some data around at some point. Now it doesn't really make
much sense having the variables shared since then they have class scope
rather than instance scope, and I assume you're trying to access instance
data. Thus, if you don't want to use the constructor option above you can
use liu's suggestion, just make sure that none of the variables or methods
setting them are Shared.
Thanks,
Guy


Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newbie | last post by:
OK, this may be impossible since I'm using 3rd party shopping cart ASP software, but I've been able to finagle a lot of other stuff I thought wouldn't work, so here we go: I'm using a form in...
2
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text,...
3
by: Ben R. | last post by:
I've got an asp.net application with a page that collects user info via forms and I'd like to have those values then passed to a 2nd page for a continuation which makes use of the entered values...
10
by: Noozer | last post by:
Below is some ASP, HTML and javascript. It is part of a page used to maintain a small database. This code did work at one time, but has since stopped. For some reason the data on my form is not...
4
by: thawk | last post by:
I have tried to pass information from one form to another using the described method in the documentation, but everytime I attempt to do this I get an error message that states that I have a null...
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...
5
by: Guy | last post by:
Hi, I'm working in vb.net and have one form that creates a second form. I need the first form pass info to the second form. I tried using a shared property in the first form and got this error...
2
by: whitc26 | last post by:
Let me preface: I'm a novice, and have no programming experience. I have created an access database and have a few tables in it. I have created a form called "clients" This form opens up and...
3
by: Mufasa | last post by:
Are the only two real options for passing info between pages using QueryString and Session Variables? Am I missing any other viable way? TIA - Jeff.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.