fortypoundhead.com

The differences between Get, Set and Let

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


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:54.161.91.76

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




Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers