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.
Printable View
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.
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??
Don't know if it makes a difference, but are you starting your app from a form or sub main?
"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.
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.:wave: :wave: :wave: :wave: :wave:
Hi,
"I meant that I'm seeing the variables get initialized BEFORE the load. "
That's the opposite of what you first posted:confused:
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.
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:p
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
Hi Alextyx,
I assume you have not tried out what you are saying:rolleyes: :rolleyes:
"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:wave:
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 .
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! :blush:
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:mad: :blush:
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.