Results 1 to 12 of 12

Thread: [RESOLVED] quick question

  1. #1

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

    Resolved [RESOLVED] quick question

    Hi, does a variable create a memory cell, or is it actually the memory cell, for example:

    Dim Answer As DialogResult

    This is the explanation I have written for that line of code:

    "This line of code uses a Dim (Dimension) statement to declare a variable called ‘Answer’.
    This variable creates an object to store the user’s answer to a dialog result."

    and this is the explanation that my friend said it was:

    "This line of code uses a Dim (Dimension) statement to declare a variable called ‘DialogResult’. This variable is a memory cell to store the user’s answer to the dialog result."

    Can anyone tell me which is the right explanation?

    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
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: quick question

    The compiler causes memory to be allocated for a variable at run time.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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

    Re: quick question

    The variable holds the memory address of a chunk of memory that is sized large enough to hold an object of type DialogResult. The variable does not hold the object itself, nor is the object created by that line. All that is done is that a chunk of memory of the right size is set aside, and the address of that chunk of memory is stored with the name of the variable.
    My usual boring signature: Nothing

  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: quick question

    "This line of code uses a Dim (Dimension) statement to declare a variable called ‘Answer’.
    This variable creates an object to store the user’s answer to a dialog result."


    Looks correct(ish), to me. However, it's not strictly true. 'It declares a variable called Answer that is of the type DialogResult' is all you can say about the line: nothing more.

    It certainly does not declare a variable called DialogResult (so your friends answer is incorrect from that stand point).

    With regards to 'memory cell': the declaration does nothing in and of itself. only when that variable is used for the first time in your code is memory actually assigned [edit: this isn't actually strictly true] or used (the 'memory cell' you possibly refer to). Effectively, the variable is a humanly readable mechanism to refer to a specific location in memory.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  5. #5

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

    Re: quick question

    I see, so a good explanation would be:

    This line of code uses a Dim statement to declare a variable called ‘Answer’. This variable sets aside a chunk of memory, to store the answer to the dialog result"

    Is that correct?
    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
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: quick question

    Code:
            'Answer does not exist
            If Answer = Windows.Forms.DialogResult.None Then
    
            End If
            Dim Answer As DialogResult 'now it does
            'when the statement above is executed Answer = Windows.Forms.DialogResult.None
            If Answer = Windows.Forms.DialogResult.None Then
                Stop
            End If
            Answer = MessageBox.Show("FOO", "BAR")
            'when the statement above is executed Answer = Windows.Forms.DialogResult.OK
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

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

    Re: quick question

    why have you given me a piece of code, dbasnett? I need a simple explanation, if anything I am even more confused now..
    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"

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: quick question

    Then see post# 2 - 4.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: quick question

    I wouldnt think that it would be strictly correct to say that the variable "does" anything.

    The help file definition of Dim looks good to me:
    Dim - "Declares and allocates storage space for one or more variables."

    And the definition of variable from Wikipedia looks good to me:
    "variable is a keyword or phrase (identifier) that is linked to a value stored in the system's memory "
    Last edited by Muddy; Apr 8th, 2009 at 09:39 AM.

  10. #10
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: quick question

    Quote Originally Posted by Muddy View Post
    I wouldnt think that it would be strictly correct to say that the variable "does" anything.

    The help file definition of Dim looks good to me:
    Dim - "Declares and allocates storage space for one or more variables."

    And the definition of variable from Wikipedia looks good to me:
    "variable is a keyword or phrase (identifier) that is linked to a value stored in the system's memory "
    A variable doesn't do anything. It simply sits there and holds the memory address for whatever value that address is holding.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

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

    Re: quick question

    It holds the address of a chunk of memory large enough to hold an object of the declared type. The memory holds Nothing until an object of the correct type is put into it.
    My usual boring signature: Nothing

  12. #12

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

    Re: quick question

    Thanks shaggy thats exactly what I was looking for.
    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