|
-
Mar 7th, 2009, 09:17 AM
#1
Thread Starter
Addicted Member
What is the purpose of my variable?
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
Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.
"A clever person solves problems, a wise person avoids them" 
-
Mar 7th, 2009, 09:21 AM
#2
Re: What is the purpose of my variable?
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.
-
Mar 7th, 2009, 09:25 AM
#3
Thread Starter
Addicted Member
Re: What is the purpose of my variable?
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
Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.
"A clever person solves problems, a wise person avoids them" 
-
Mar 7th, 2009, 09:41 AM
#4
Re: What is the purpose of my variable?
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.
-
Mar 7th, 2009, 09:45 AM
#5
Thread Starter
Addicted Member
Re: What is the purpose of my variable?
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??
Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.
"A clever person solves problems, a wise person avoids them" 
-
Mar 7th, 2009, 09:50 AM
#6
Re: What is the purpose of my variable?
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.
-
Mar 7th, 2009, 09:50 AM
#7
Re: What is the purpose of my variable?
Yes, and it allows you to access objects within the form object. So you could call methods like .Show and properties like txtUserID.
-
Mar 7th, 2009, 09:52 AM
#8
Thread Starter
Addicted Member
Re: What is the purpose of my variable?
Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.
"A clever person solves problems, a wise person avoids them" 
-
Mar 7th, 2009, 09:53 AM
#9
Re: What is the purpose of my variable?
Here is a nice explanation of the difference between an instance and a class:
http://www.tek-tips.com/faqs.cfm?fid=5611
-
Mar 7th, 2009, 11:01 AM
#10
Re: What is the purpose of my variable?
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.
My usual boring signature: Nothing
 
-
Mar 7th, 2009, 05:09 PM
#11
Thread Starter
Addicted Member
Re: What is the purpose of my variable?
Im using visual basic 2008 express edition so any posts that include coding or stuff PLEASE refer to vb 2008.
"A clever person solves problems, a wise person avoids them" 
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
|