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

Easy But Stupid Question

Hey,

I just want to know (i know i should know this) how can i
show up another form?

I have 2 forms and the first one has a button on it that
when i click the button i want the second form to show up
(and the first form disappear), and i also want another
button on the second form to return to the first form.

When i use the following code

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnNorthwind.Click
DataForm1.Show()
End Sub

I get this error: Reference to a non-shared member
requires an object reference.

Can someone please help me.

Thanks

Nov 20 '05 #1
7 1253
dim df1 as new DataForm1
df1.show

Cheers

Jody

"Trev" <tj**@bigpond.net.au> wrote in message
news:04****************************@phx.gbl...
Hey,

I just want to know (i know i should know this) how can i
show up another form?

I have 2 forms and the first one has a button on it that
when i click the button i want the second form to show up
(and the first form disappear), and i also want another
button on the second form to return to the first form.

When i use the following code

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnNorthwind.Click
DataForm1.Show()
End Sub

I get this error: Reference to a non-shared member
requires an object reference.

Can someone please help me.

Thanks

Nov 20 '05 #2
Hi Trev,

It <is> an easy question - once you know - but it's far from stupid. This
issue (Forms versus Form classes) is a major stumbling block for many
programmers coming from VB6 to VB.NET.

The following is taken from an answer to someone a while back. It only
answers part of your question, but hopefully it will shed a bit of light on
the matter.

Forms are no longer just there. They have to be managed. What's worse is
that I'm not quite telling the truth. The .NET designers, in an effort to be
helpful, have hidden some of the code that, if it had to be done manually,
would make things clearer.

In C#, if you want a form, you have to code its declaration and its
instantiation and then show it. All C# programs start with their "Sub Main".
This creates the startup form and off you go. Being explicit means less
confusion.

In VB, if you don't use Sub Main as your starting point, the compiler
effectively creates it for you - behind the scenes. And thus the confusion
starts! Here you have an obviously visible form which has appeared out of
nowhere. There is no variable with which to access it from outside the form.
There is little (to a newcomer from VB6) to say that this Form1 is <not> the
form that you can see, but is the class (template) for the form.

Create a project with a single form, Form1 and this is what you get
(simplified)

Class Form1
Sub Main
Dim f As New Form1
Application.Run (f)
End Sub

Sub New
Sub Form1_Load
End Class

But you never get to see the Sub Main as this is done for you and hidden.
In VB6, Form1 would be the class <and> the instance. In VB.NET, Form1 is the
class <only> while f, the hidden variable, is the instance.

Let's put Sub Main into a module:

Module LetsGo
Public f As New Form1
Sub Main
Application.Run (f)
End Sub
End Module

Class Form1
Sub New
Sub Form1_Load
End Class

Now you have a global variable, f, which is the actual form. You can
access this variable from anywhere and use it to Show and Hide, etc.

Regards,
Fergus
Nov 20 '05 #3
* "Trev" <tj**@bigpond.net.au> scripsit:
I just want to know (i know i should know this) how can i
show up another form?

I have 2 forms and the first one has a button on it that
when i click the button i want the second form to show up
(and the first form disappear), and i also want another
button on the second form to return to the first form.

When i use the following code

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnNorthwind.Click
DataForm1.Show()
End Sub

I get this error: Reference to a non-shared member
requires an object reference.


You will have to use 'Call (New DataForm1()).Show())'.

But this won't solve your problem.

<http://www.google.de/groups?selm=u%23xQOutWDHA.2100%40TK2MSFTNGP11.phx. gbl>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Cor

">
You will have to use 'Call (New DataForm1()).Show())'.

But this won't solve your problem.

?????
Nov 20 '05 #5
Cor
Hi Trev,
In addition to the others,
I just want to know (i know i should know this) how can i
show up another form?

I have 2 forms and the first one has a button on it that
when i click the button i want the second form to show up
(and the first form disappear), and i also want another
button on the second form to return to the first form.

This kind of form looks like a dialog form. Therefore is a special method

\\\
dim frm as new form2
frm.showdialog(me)
theTextTromTorm2=frm.aPublicvariableInForm2
frm.dispose 'one of the exceptions to use dispose
///

I hope this helps a little bit?

Cor
Nov 20 '05 #6
"Cor" <no*@non.com> schrieb

">
You will have to use 'Call (New DataForm1()).Show())'.

But this won't solve your problem.

?????


It shows a *new* form, not the one shown before.
--
Armin

Nov 20 '05 #7
* "Cor" <no*@non.com> scripsit:
You will have to use 'Call (New DataForm1()).Show())'.

But this won't solve your problem.

?????


The application will exit because it doesn't have a message loop any
more instead of showing the 2nd form.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

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

Similar topics

2
by: Maximus | last post by:
Hi, Ok my problem is hard to explain... I'm making a directdraw based program and of course maps. I can put texture on my map but I want to save those information in a structure with a x, y and a...
119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
2
by: Ron Weldy | last post by:
I read that you don't need .cs files to deploy but I suppose if you are trying to reconstruct someone's work, you will need these files. Is that correct?
5
by: Brad | last post by:
I am very very new to ASP .Net developement and am all self-taught. I have been programming Windows vb forms for a while however. I know this is a stupid question. I have my home page and some...
1
by: Brad Allison | last post by:
Okay, I am grabbing data from a dinosaur, an AS400 system. One of the date fields is formated as decimal so the data adapter is filling the data set with these decimal numbers (ie 712004 for today...
6
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no...
8
by: Michael | last post by:
Hi, I'm trying to use a table and format it with CSS, but I cant get it to render with a border. I know this is really easy, but I can't see what I have wrong and when I search for tables and...
0
zuquirio
by: zuquirio | last post by:
Hi folks, I have a simple question. I'm getting started with struts 2, spring 2, hibernate etc... But I don't know what is the meaning of $, # and % symbols that appears in some source code. i.e.:...
2
by: Lynx101 | last post by:
Hi, Is this a stupid question? Senario: Two tables linked together with an ID number. Question: When using a combo box, which refences another table by indexed autonumber, is there a way to...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.