|
-
Apr 6th, 2004, 07:39 AM
#1
Thread Starter
Frenzied Member
public (global) variables
when you have a module that is used to house public variables for the entire project to use, when are those initialized? are they done before formLoad or after? from what i can TELL, it's after.
-
Apr 6th, 2004, 07:50 AM
#2
PowerPoster
hi,
Don't know where you got that idea.
Try declaring a public variable in the module, referencing it in the first line of the formLoad event and putting a breakpoint on it.
You will see it is recognised.
Or have I completely misunderstood you??
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 6th, 2004, 07:52 AM
#3
Frenzied Member
Don't know if it makes a difference, but are you starting your app from a form or sub main?
-
Apr 6th, 2004, 07:55 AM
#4
PowerPoster
"Don't know if it makes a difference, but are you starting your app from a form or sub main?"
No, it makes no difference.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 6th, 2004, 08:44 AM
#5
Thread Starter
Frenzied Member
it's starting from a form.
I meant that I'm seeing the variables get initialized BEFORE the load (oops ). I have variables in the module and then reference them in LOAD. No problems. What I was really curious about is whether or not I should just go ahead and declare (example)
VB Code:
public x as An_Object = New An_Object
'OR
public x as An_object
I'm simply gonna use that one 'x' over and over so i've set it to a new An_object in the declaration.
Just curious if that's the way to go.
Last edited by Andy; Apr 8th, 2004 at 10:24 AM.
-
Apr 6th, 2004, 11:49 AM
#6
PowerPoster
Hi,
"I meant that I'm seeing the variables get initialized BEFORE the load. "
That's the opposite of what you first posted
It appears that all the declarations in the project are activated before any form or module loads.
"public x as An_Object = New An_Object
'OR
public x as An_object"
This is a totally different subject. Either will work but using NEW is more VB.NET like.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 7th, 2004, 02:47 AM
#7
Hyperactive Member
Now, we all agree that " all the declarations in the project are activated before any form or module loads" (if in a module, obviously, not in a Form not yet loaded) and that is a good result, I think
If we analize the second problem:
--------------------------------------------------------------------------------
public x as An_Object = New An_Object
'OR
public x as An_object
The difference is that "public x as An_object" declare the object but it does not instance it, so if you will try to refere to the object you will have a run time error.
To make your object fully usable, you must use, for example:
Dim Form1 as FormGoofy
Form1=New FormGoofy
or
Dim Form1 as NEW Formgoofy
Good job
Live long and prosper (Mr. Spock)
-
Apr 7th, 2004, 03:39 AM
#8
PowerPoster
Hi Alextyx,
I assume you have not tried out what you are saying
"Now, we all agree that " all the declarations in the project are activated before any form or module loads" (if in a module, obviously, not in a Form not yet loaded) "
We are NOT all agreed
You are contradicting yourself! if you amend
"not in a Form not yet loaded"
to
"not in a Form not yet being loaded"
then it makes sense.
Again
"The difference is that "public x as An_object" declare the object but it does not instance it, so if you will try to refere to the object you will have a run time error."
NO!!!
You can't refer to it because it is EMPTY.
When you fill it with an instanced object, you will be able to refer to the properties of that instanced object .
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 7th, 2004, 04:04 AM
#9
Hyperactive Member
Hi taxes,
This is the runtime error I obtain, in italian version:
Eccezione non gestita di tipo "System.NullReferenceException" in GIN.exe
Informazioni aggiuntive: Riferimento a un oggetto non impostato su un'istanza di oggetto.
The declaration in a public module is:
' ----------------- Dichiarazioni di Form -----------------------------------
Public FrmReg As New FrmRegistrazioni
Public FrmNota As New FrmEditaPrimaNota
Public FrmDaCancellare As FrmCercaRegistrazioni
The last line is the 'bad declaration' the others work properly, I assure!
The line in which the error is generated is among the lines of the load routine and it is, obviously: "GIN.FrmDaCancellare.Show()"
' --------- vvvvvvvvvvvvvv EVENTI vvvvvvvvvv -------------------
Private Sub FrmRientri_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
GIN.FrmDaCancellare.Show()
End Sub
As you can see, I can refer to an object declared and I can run the program and I can access to its methods, but I will have a run time error. I intended this, but perhaps I can't explain well. I guess you can also understand what I intended about form not loaded, or not? I know english from school and for electronics, that is my main occupation and surely I make a lot of mistake.I try to write in a correct way, but, try to be patience with me, please!
Live long and prosper (Mr. Spock)
-
Apr 7th, 2004, 09:48 AM
#10
PowerPoster
Hi,
I think this thread has moved completely away from the original post and I have difficulty in understanding the last post. Better let it lie.
Actually, re-reading the posts one of my responses missed the mark
I was referring to creating a container (if that is the right word!) variable to contain instantiated objects as required.
See Andy's "I'm simply gonna use that one 'x' over and over so i've set it to a new An_object in the declaration"
I did not notice the AN_ bit in front of OBJECT.
My apologies on this point.
Last edited by taxes; Apr 7th, 2004 at 10:27 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|