The differences between Get, Set and Let

Posted On 2007-01-13 by FortyPoundHead
Keywords: Visual Basic VB6
Tags: General Tip Tutorial Windows
Views: 1876

One question a VB programmer is asked a lot about, especially in a job interview, is the differences between let, set, and get. Now some of the advanced programmers out there might laugh, but you''d be surprised at how many beginning developers trip up on this. I''ve asked the question of interviewees myself. So, in hopes of helping out budding programmers, here is the explanation.

Let Statement

[Let] varname = expression

Assigns the value of an expression to a variable (varname). The Let keyword is usually omitted and is assumed by Visual Basic.

For example:
Let intMyNumber = 5
Let strMyString = "Text Goes Here"

Get Statement

Get [#]filenumber,[ recnumber,] varname

Reads data from the open disk file corresponding to the filenumber argument into a variable (varname). Get works with files open as Random or Binary, and a record number (recnumber) can be specified when retrieving data from a Random file. When using Binary files, recnumber can alternatively be used to specify the byte position from which the data is to be read.

Set Statement

Set objectvar = {[New] objectexpression | Nothing}

Assigns an object reference (objectexpression) to a variable or property (objectvar). The optional New keyword can be used to indicate that the object should be created implicitly. To disassociate objectvar with a specific object and free up the resources it is using, assign it the Nothing keyword.

For example, using your textbox example:

Set MyTextBox as Textbox

This is also used to instantiate new instances of classes, recordsets, and other things. Basically, it allows you to treat just about anything as an object.

About the Author

FortyPoundHead has posted a total of 1974 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links