Results 1 to 11 of 11

Thread: What is the purpose of my variable?

  1. #1

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    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"

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  3. #3

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    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"

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  5. #5

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    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"

  6. #6
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    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.

  7. #7
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  8. #8

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Re: What is the purpose of my variable?

    I see, thankyou
    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"

  9. #9
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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

  11. #11

    Thread Starter
    Addicted Member Pantero's Avatar
    Join Date
    Jan 2009
    Posts
    169

    Re: What is the purpose of my variable?

    I see, 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"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width