Re: How to refer to a class property while in that class. (Solved)



I tried that out and it does seem to work
like you say:
______________________________

Dim c1
Set c1 = new dataProc
MsgBox c1.Token
c1.DoMe
MsgBox c1.Token
Set c1 = Nothing

Class dataProc
Private m_token

Public Property Get Token()
Token = m_token
End Property

Public Property Let Token(p_data)
m_token = p_data
End Property

Public Sub DoMe()
Me.makeToken
End Sub


Public Function makeToken()
m_token = "blah"
End Function
End Class
______________________________

The second msgbox says "blah", indicating
that Me.makeToken ran OK.

I don't see the point, though. The makeToken
sub is in your scope, so "Me" is superfluous.
I don't know about "Me" in PHP. "Me" is used
in VB to reference a VB Form from within itself
because there needs to be a reference to the
form object. But in a class there's nothing you don't
have access to. Even an event sub like Class_Initialize
is still just a local sub from inside the class, so
there just isn't any purpose for "Me" as far as I
can see. In other words, you don't need to reference
the class object to access any of the class functionality
if you're running inside the class.

You can use simply:
makeToken

To use Me.makeToken is like saying to yourself:
"Self, let's have lunch."
It's obviously "Self" you're referring to. :)

for example, here is another function I'm trying to run in the same
class. (sorry for not putting this in the previous post)


Public Function makeNew()
If Len(Me.Token) <> 20 Then
Me.MakeToken
End If

When this runs, Len(Me.Token) translates to 0, which would leave me to
believe that me.Token is Null because it is not referencing the class
properly.
On the other hand, Me.MakeToken on the next line successfuly runs the
makeToken function.
Note: from the main script I've done the following to ensure that
Token, is not actually null.

Set dp = new dataProc

dp.MakeToken
response.write(dp.Token) ' which has a value or 20 chars
dp.MakeNew



.



Relevant Pages

  • Re: Referencing Dynamic Range
    ... Sub copyrange() ... MsgBox ... How do I reference an ActiveCell? ... active cell instead of specifying a cell below? ...
    (microsoft.public.excel.programming)
  • RE: Referencing Dynamic Range
    ... Sub copyrange() ... MsgBox ... How do I reference an ActiveCell? ... active cell instead of specifying a cell below? ...
    (microsoft.public.excel.programming)
  • RE: COMException while formatting PowerPoint shapes
    ... it seems that the VBA code did not run well at my side. ... run Test2 to use the Reference. ... Sub Test() ... MsgBox o.Name ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: Public variables and separate library files
    ... You would need to create a reference from the file needing to use the ... > Public temp As Integer ... > Sub Master() ... > MsgBox ...
    (microsoft.public.excel.programming)
  • Problems creating an exchange mailbox and setting permissions
    ... Exchange Mailbox the rest is working fine. ... sub Window_Onload ... msgbox "Please enter the users First Name" ... msgbox "Please select the Account Type" ...
    (microsoft.public.scripting.vbscript)