|
-
Apr 8th, 2009, 08:22 AM
#1
Thread Starter
Addicted Member
[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" 
-
Apr 8th, 2009, 08:38 AM
#2
Re: quick question
The compiler causes memory to be allocated for a variable at run time.
-
Apr 8th, 2009, 08:44 AM
#3
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
 
-
Apr 8th, 2009, 08:44 AM
#4
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."
-
Apr 8th, 2009, 08:58 AM
#5
Thread Starter
Addicted Member
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" 
-
Apr 8th, 2009, 09:08 AM
#6
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
-
Apr 8th, 2009, 09:16 AM
#7
Thread Starter
Addicted Member
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" 
-
Apr 8th, 2009, 09:19 AM
#8
-
Apr 8th, 2009, 09:35 AM
#9
PowerPoster
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.
-
Apr 8th, 2009, 09:45 AM
#10
Re: quick question
 Originally Posted by Muddy
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.
-
Apr 8th, 2009, 10:06 AM
#11
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
 
-
Apr 8th, 2009, 12:35 PM
#12
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|