Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

let, get, set???

Status
Not open for further replies.

matrix07

Programmer
Mar 21, 2002
41
0
0
CA
Hi there, I am reading a book about ASP, and they briefly talked about writing Classes. I'm kinda lost on what let, get, and set is for? What purposes does those properties serve? I've read the page a few times but still can't grasp the theory? Thanks!
 
"Let", "Get" and "Set" are class accessors. They are used to access the class properties. To define a property for your class, write the following (let's say you want to define "count" property that is an integer) :
Code:
private in_length
...
public Property Get count
  count = in_length
end Property

public Property Let count(newValue)
  in_length = newValue
End property

This property "count" will be used from outside your class this way :
Code:
<ClassName>.count = 5
..
dim newCount
newCount = <ClassName>.count

You may think &quot;why using this as i can do the same defining my &quot;in_length&quot; var as public ?&quot;. Well the answer is quite simple : If you want your property to be read-only or write only, provide only the Get or Let accessor.

Now for the &quot;Set&quot; : the &quot;set&quot; accessor is the same that the &quot;Let&quot; one except that &quot;Let&quot; is for simple data types while &quot;Set&quot; is for objects.
Exemple :
Code:
Class HelloWord
  public function display()
    MsgBox &quot;Hello Word&quot;
  End function
End class

Class Test
  private myHelloWord

  public sub Class_Initialize
    Set myHelloWord = new HelloWord
  end sub
  
  public Property Get displayer
    Set displayer = myHelloWord
  end Property
The below code will raise an error
Code:
  public Property Let displayer(newValue)
    myHelloWord = newValue
  End property
The above code will raise an error
The below code will work
Code:
  public Property Set displayer(newValue)
    Set myHelloWord = newValue
  End property
The above code will work
Code:
End Class
Water is not bad as long as it stays out human body ;-)
 
Hmmm... this was probably talking about Windows Script Components (WSC), a technology also and formerly known as &quot;scriptlets.&quot; This what Targol is referring to I think.

There is a major section in the Windows Script Technologies documentation on WSC, with a chapter called &quot;Script Component Tutorial.&quot; This is downloadable as a Windows HTML Help (.CHM) file from:


Your book may also have been talking about classes in ActiveX DLLs created using VB or C++ or something. VB uses similar Let, Get, and Set statements.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top