|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Friend Property ques(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 somethingtia Mark
Show quote
Hide quote
"MP" <nospam@Thanks.com> wrote in I think you're missing something, Mark. Your assumptions are correct. 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 tried your snip and errored on "Me.Path". Is this another friend property that you didn't include? The Me.MatchName reference worked fine. "Tim Baur" <trbo20DIS***@ARDyahoo.com> wrote in message Hi Tim,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? > 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 "MP" <nospam@Thanks.com> wrote in news:%24le.3174$LT2.1383@tornado.rdc- kc.rr.com:> but it's not set at Just playing a hunch here without really understanding everything that's > the time the form itself is loading and initiailizing (the form itself > doesn't see it's own value has been set). > 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 ? "MP" <nospam@Thanks.com> wrote in message Ohhhhhhhhhhhh.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). 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. "Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message thank you thank you thank younews: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. > Show quoteHide quote :-) Mark "MP" <nospam@Thanks.com> wrote in message This is kind of a kooky question but what happens if you drop "Me." from news:%l2le.3166$LT2.2420@tornado.rdc-kc.rr.com... > sMatch = Me.MatchName that line? "Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message by itself, the change had no effect.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? > > 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 |
|||||||||||||||||||||||