Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Reading from my VB.NET book that I have... To Display a form you must declare it. This is done by declaring a new

"Instance" of the form:

 

DIM MyForm as NEW frmExample()

 

MyForm.ShowDialog() 'Modal Display

 

 

My question is: Is frmExample the new form?

Why does it say Myform.ShowDialog ? And not frmExample.ShowDialog? whats the difference? Is MyForm the new instance?

 

Couldn't you declare it as

 

Dim frmExample as NEW frmExample()

So that it reads

frmExample.ShowDialog()

:confused:

  • *Experts*
Posted

In your example a variable is declared, named MyForm. What is done after that is a NEW instance of the class named frmExample is assigned to the variable called MyForm. So yes, the form contained in MyForm is a new instance of frmExample. Now your variable contains an instance of the frmExample class. Declaring like this:

Dim frmExample As New frmExample

Would work, but you would probably get into name conflicts, which makes programming much harder.

Posted
In your example a variable is declared, named MyForm. What is done after that is a NEW instance of the class named frmExample is assigned to the variable called MyForm. So yes, the form contained in MyForm is a new instance of frmExample. Now your variable contains an instance of the frmExample class. Declaring like this:

Dim frmExample As New frmExample

Would work, but you would probably get into name conflicts, which makes programming much harder.

 

So what else can one do with using NEW ???

  • *Experts*
Posted
Well the New keyword is used for creating new instances of an object by calling its constructor. There isn't much more you can do with it :).
Posted

ok Maybe it's all explaned above but here's a resume

 

everithing in vb.net are objects

an object can be anything :

 

- form

- button

- file

- human

- ....

some of these object are ready to use others aren't

every object has it's own properties

 

like :

a human can breath

a human can have a name

a human can talk

a human has eyes an theyr color difer from human to human

 

a form can't breath but a form can resize

a form can have a name aswell

and a form can do showdialog

 

well you get the picture

 

well if you want to use one of these objects in you application

you need to create a new one first and give it a name

and that is way you need to declare it like:

 

Michael as new human

 

or

 

TestForm as new form

 

now you created a object with the naem you chose

and by using that name followed by a point you can call

it properties or abillities like functions or subs that are difined in that object

 

so if you want to use the showdialog function of the form object you created you first have to the new forms name follows by a point and then use it's function

eg:

 

testForm.showdialog()

 

hope this helps you understand classes (or objects is the same)

i know this is a bit confusing if you just started to experiment with this but it so powerfull.

 

(for all you code gurus i know that name is a propertie and that the name given to the object is just a pointer to the object memory but i try to make something understandable to new or

beginning programmers so don't make it look harder than it is.)

;-)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...