How Embarrasing...

Big Boabby

Newcomer
Joined
Apr 29, 2002
Messages
8
Location
Kilmarnock, Scotland
Hi guys,

Here I am a VB6 user who is trying to break into .net. I have gone back to the drawing board and am trying to use a tutorial that I have.

It is so basic but It doesn' work. I have to create a new project, right click on the Form1.vb[Design] and inset the following code in under " 'Add any initialisation after the InitializeComponent() call"


Form1.text = "Hello World"



The trouble is that when I type form1. , I do not get the option of changing the Text property. When I type it manually, the wavy line is shown with the tool tip "Reference to a non-shared member requires an object reference"

What am I doing wrong guys? I have followed the tutorial to the letter and I can't even change the form caption (now known as text) unless I do it via the properties window?

Oh the shame of it!!!!!!!!!!!!!!

Cheers
 
Hi
I don't know where you got the tutorial from, but the author should be shot! :)

The 'Form1' in your case, is the name of the Class (everything in .net is now classes)
What you want is a instance of form1.
Because you are coding in the Form1 class, you can use the Me.Text syntax where 'Me' points to the instance of Form1.

Cheers
 
Superb - thankyou very much

so when I now run the program, what I am seeing is the visual representation of the form class, and not the form itself (am I right?)

one other question, how would I create an instance of a form and use it as the start up object?

For your reference, the book is called "The Book Of Visual Studio .Net - A Guide for Developers" by Robert B. Dunaway
 
I suggest you look up the description of 'Instance of a object' or maybe one of the guru's on this forum can give you one. I might just confuse you and myself attempting to describe it :)

As for your second question, you can create a instance of a form with the following code:
Visual Basic:
Dim myForm as new Form1()
but to set a form as a startup object, do the following:
1) Right click on your project in the solution explorer and select properties
2) In the 'Common Properties - General' tab you will see a dropdown list, displaying the current startup object - Change it here
The runtime environment will now create a instance of your form when it loads your project.
Hope it helps
 
Back
Top