Hi, this is the code I have typed in
Dim F As New frmTransportUsage
F.Show()
F.txtUserID.Text = Me.txtUserID.Text
What is the purpose of the variable 'F'?
Thanks
Printable View
Hi, this is the code I have typed in
Dim F As New frmTransportUsage
F.Show()
F.txtUserID.Text = Me.txtUserID.Text
What is the purpose of the variable 'F'?
Thanks
F is the instance of the form. You could create 10 different instances and they would all be unique and each txtUserID could be different.
yes but what does it actually do?
Say I was writing this for a program documentation and I would be informing another programmer of its purpose
You need to create an instance of an object, be it a class or a form, in order to use it. F is the instance of the form frmTransportUsage.
There are some exceptions to the instance requirement with Shared objects and Modules.
Your telling me what it is, your telling me that 'F' is an instance of the frmTransportUsage, however i am asking what is its purpose, are you trying to tell me that the purpose of 'F' is to be an instance of the form frmTransportUsage??
If you want to have multiple instances of frmTransportUsage, not the form itself, running at the same time, you have to declare instances of that form. Think of it as a psuedo MDI app.
Yes, and it allows you to access objects within the form object. So you could call methods like .Show and properties like txtUserID.
I see, thankyou
Here is a nice explanation of the difference between an instance and a class:
http://www.tek-tips.com/faqs.cfm?fid=5611
The Dim F as XXX statement tells the compiler that there will be an object of type XXX created at some time. The compiler uses this information to set aside enough memory to hold an object of type XXX. In the case of all classes and some other types, it then takes the address of the first byte of that chunk of memory, and holds it somewhere. All access to the memory, and therefore all access to the instance of XXX is through that address. Methods and variables in XXX are held in a table that tells the compiler what amount to add to that base address to find the address at which the method or variable resides within the instance of XXX.
So what purpose does F serve? F is just a name. It is the name that is used to refer to the address of the memory that holds the instance of XXX. That's all it is: A name for an address.
I see, thanks