Home All Groups Group Topic Archive Search About
Author
25 May 2005 5:12 PM
MP
Hi,
(ps this is in a vba routine but I hope it's vb general enough to be ontopic
here)

I'm surprised to see that a property procedure declared with Friend modifier
can't be called by another function in the same form
I thought Friend allowed any sub in the current project to have access to
the property but subs outside the project did not have access to it
per msdn
"Modifies the definition of a procedure in a form module or class module to
make the procedure callable from modules that are outside the class, but
part of the project within which the class is defined."

as an example:
This is in a form code:

Friend Property Let MatchName(sData As String)
  msMatchName = sData
End Property

Friend Property Get MatchName() As String
  MatchName = msMatchName
End Property

then later in the form code:
Private Sub LoadListBox()
Dim lIdx As Long
Dim sblkname As String
Dim sPath As String
sPath = Me.Path
Dim sMatch As String
sMatch = Me.MatchName
MsgBox "Inside LoadListBox Match name is: " & sMatch
'this shows it to be a blank string
'etc
End Sub

So since the definition specifically says "...to make the procedure callable
from modules that are *outside* the class..." then I guess that means that
it's not callable from *inside* the class, but that still surprises me -
thinking that surely if another class can see it, how could the class itself
not see its own properties?

:-)
Is this correct or am I missing something

tia
Mark

Author
25 May 2005 5:37 PM
Tim Baur
Show quote Hide quote
"MP" <nospam@Thanks.com> wrote in
news:%l2le.3166$LT2.2420@tornado.rdc-kc.rr.com:

> Hi,
> (ps this is in a vba routine but I hope it's vb general enough to be
> ontopic here)
>
> I'm surprised to see that a property procedure declared with Friend
> modifier can't be called by another function in the same form
> I thought Friend allowed any sub in the current project to have access
> to the property but subs outside the project did not have access to it
> per msdn
> "Modifies the definition of a procedure in a form module or class
> module to make the procedure callable from modules that are outside
> the class, but part of the project within which the class is defined."
>
> as an example:
> This is in a form code:
>
> Friend Property Let MatchName(sData As String)
>   msMatchName = sData
> End Property
>
> Friend Property Get MatchName() As String
>   MatchName = msMatchName
> End Property
>
> then later in the form code:
> Private Sub LoadListBox()
>  Dim lIdx As Long
>  Dim sblkname As String
>  Dim sPath As String
>  sPath = Me.Path
>  Dim sMatch As String
>  sMatch = Me.MatchName
>  MsgBox "Inside LoadListBox Match name is: " & sMatch
> 'this shows it to be a blank string
> 'etc
> End Sub
>
> So since the definition specifically says "...to make the procedure
> callable from modules that are *outside* the class..." then I guess
> that means that it's not callable from *inside* the class, but that
> still surprises me - thinking that surely if another class can see it,
> how could the class itself not see its own properties?
>
>:-)
> Is this correct or am I missing something
>
> tia
> Mark
>
>
>

I think you're missing something, Mark.  Your assumptions are correct. 
I tried your snip and errored on "Me.Path".  Is this another friend
property that you didn't include?

The Me.MatchName reference worked fine.
Author
25 May 2005 7:08 PM
MP
"Tim Baur" <trbo20DIS***@ARDyahoo.com> wrote in message
news:Xns96618AA33F19trbo20DISREGARDyahoo@207.46.248.16...
>
> >
>
> I think you're missing something, Mark.  Your assumptions are correct.
> I tried your snip and errored on "Me.Path".  Is this another friend
> property that you didn't include?
>

Hi Tim,

yep,

Friend Property Get Path() As String
Path = msBlockPath
End Property
Friend Property Let Path(vData As String)
msBlockPath = vData
End Property

there must be something going on between calling the form from a stdmodule

now I see it has nothing to do with Friend or Public
If I set the property in a calling std module, the property gets set after
the call returns (the module sees the property value), but it's not set at
the time the form itself is loading and initiailizing (the form itself
doesn't see it's own value has been set).

So now I need to try to figure out how to "Pre-Load a property value" in a
form when calling from a std module and have the form be able to see the
property has been set before doing other work.

Must be some kind of timing issue between creating the form instance and the
form actually doing it's job as it initializes etc.


fwiw the calling sub is:
Sub AdcxAnchor()
  Debug.Print "Start test"
  Debug.Print "Set MatchName"
  adcxAnchorFrm.MatchName = "anc*"
  Debug.Print "Done set MatchName"

  Debug.Print "Get MatchName"
  If Len(adcxAnchorFrm.MatchName) > 0 Then
    Debug.Print "In calling module, matchname is: " &
adcxAnchorFrm.MatchName
    Else
    Debug.Print "In calling module, matchname is blank string "
  End If

  Debug.Print "Done get MatchName"

  'adcxAnchorFrm.Show
  Debug.Print "End Test"
End Sub

'the forms initialize event
Private Sub UserForm_Initialize()
  Debug.Print "Initialize UserForm"
  Debug.Print "Set Path"
    Me.Path = "H:\ptsg\blocks2\"
  Debug.Print "Done Set Path"

  If Len(MatchName) > 0 Then
    Debug.Print "On initialize, match is: " & MatchName
    Else
    Debug.Print "On initialize, match is blank string"
  End If

  Debug.Print "LoadListBox"
    LoadListBox
  Debug.Print "Done LoadListBox"

End Sub

'another sub in form
Private Sub LoadListBox() '(sMatch As String)
Dim lIdx As Long
Dim sblkname As String
Dim sPath As String
sPath = Me.Path
MsgBox "Path: " & sPath

Dim sMatch As String
sMatch = Me.MatchName
If Len(sMatch) > 0 Then
    Debug.Print "Inside LoadListBox Match name is: " & sMatch
  Else
    Debug.Print "Cant get MatchName property"
    'Unload Me
    Exit Sub
End If

Dim colFiles As Collection
Dim adcFile As adcxFile
Set adcFile = ADCXUtils2005.InitadcxFile
adcFile.CollectFiles colFiles, sPath, sMatch & ".dwg", False
Set adcFile = Nothing

  Me.ListBox1.Clear
  If Not colFiles Is Nothing Then
    If colFiles.count > 0 Then
      For lIdx = 1 To colFiles.count
        sblkname = Mid$(colFiles(lIdx), (Len(sPath)) + 1)
        Me.ListBox1.AddItem sblkname
      Next lIdx
      Else
      MsgBox "No anchor blocks found matching " & sMatch
    End If '>0
  End If
  Set colFiles = Nothing
End Sub



results in immediate with public property:(form didn't initialize)
Start test
Set MatchName <---------------here form doesn't even initialize
Done set MatchName
Get MatchName
In calling module, matchname is: anc*<------but calling sub sees the
property was set
Done get MatchName
End Test

results in immediate with friend property:(form did initialize but didn't
see the property value)
Start test
Set MatchName
Initialize UserForm <---------------here form is initializing
Set Path
Done Set Path
On initialize, match is blank string <-------------but it doesn't see it 's
property value
LoadListBox
Cant get MatchName property
Done LoadListBox
Done set MatchName
Get MatchName
In calling module, matchname is: anc*<----but the std module does see the
property value but not till later
Done get MatchName
End Test




Thanks for looking at this
Mark
Author
25 May 2005 7:28 PM
Tim Baur
"MP" <nospam@Thanks.com> wrote in news:%24le.3174$LT2.1383@tornado.rdc-
kc.rr.com:

> but it's not set at
> the time the form itself is loading and initiailizing (the form itself
> doesn't see it's own value has been set).
>

Just playing a hunch here without really understanding everything that's
going on...

Are you declaring the form:

   Dim frmMyForm As New SomeForm

Or are you doing it like:

   Dim frmMyForm as SomeForm

   ...

   Set frmMyForm = New SomeForm

?
Author
25 May 2005 7:48 PM
Jeff Johnson [MVP: VB]
"MP" <nospam@Thanks.com> wrote in message
news:%24le.3174$LT2.1383@tornado.rdc-kc.rr.com...

> now I see it has nothing to do with Friend or Public
> If I set the property in a calling std module, the property gets set after
> the call returns (the module sees the property value), but it's not set at
> the time the form itself is loading and initiailizing (the form itself
> doesn't see it's own value has been set).

Ohhhhhhhhhhhh.

You'll never be able to make this work in the Load or Initialize event.
You're going to have to create a method (I always call mine "Init"), set all
the desired properties, then call this method.
Author
25 May 2005 10:26 PM
MP
"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:OQJ4vKWYFHA.796@TK2MSFTNGP09.phx.gbl...
>
>
> Ohhhhhhhhhhhh.
>
> You'll never be able to make this work in the Load or Initialize event.
> You're going to have to create a method (I always call mine "Init"), set
all
> the desired properties, then call this method.
>


thank you thank you thank you


Show quoteHide quote
:-)
Mark
Author
25 May 2005 5:39 PM
Jeff Johnson [MVP: VB]
"MP" <nospam@Thanks.com> wrote in message
news:%l2le.3166$LT2.2420@tornado.rdc-kc.rr.com...

> sMatch = Me.MatchName

This is kind of a kooky question but what happens if you drop "Me." from
that line?
Author
25 May 2005 7:10 PM
MP
"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:OfGItCVYFHA.2948@TK2MSFTNGP10.phx.gbl...
>
> "MP" <nospam@Thanks.com> wrote in message
> news:%l2le.3166$LT2.2420@tornado.rdc-kc.rr.com...
>
> > sMatch = Me.MatchName
>
> This is kind of a kooky question but what happens if you drop "Me." from
> that line?
>
>

by itself, the change had no effect.

I just use the Me. qualifier to be overly clear to myself - (my lame attempt
at self documenting code)
:-)

it doesn't fix the problem however.

Thanks
Mark