|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Passing Structure (Type)This structure is used in two "simultaneous" loops -- a real-time loop, and -- a general loop. The real-time loop is suspended (Active X data input buffered) when the general loop is executing. I'm getting random corruption sometimes and can't pinpoint where. VB won't allow a structure to be passed ByVal. ======= QUESTION ======== If I pass the global structure as a parameter to a procedure, [ e.g MyProcedure (TTemp As TGlobalInfo) ] is a local copy created OR am I just referencing the Global structure that is being passed into the procedure?
Show quote
Hide quote
"David" <dw85745***@earthlink.net> wrote in message I would presume using the structure would be the same as other variables, so news:uewy6t16JHA.1372@TK2MSFTNGP05.phx.gbl... >I have a Public structure. > > This structure is used in two "simultaneous" loops > -- a real-time loop, and > -- a general loop. > > The real-time loop is suspended (Active X data input buffered) when the > general loop is executing. > > I'm getting random corruption sometimes and can't pinpoint where. > > VB won't allow a structure to be passed ByVal. > > ======= QUESTION ======== > > If I pass the global structure as a parameter to a procedure, > > [ e.g MyProcedure (TTemp As TGlobalInfo) ] > > is a local copy created OR am I just referencing the Global structure that > is being passed into the procedure? > it is referenced, rather than creating a copy. The default is ByRef, after all. If you need to operate on or change the structure within the procedure, but don't want the "master" changed, you can simulate By Ref, using something like: Sub MyProcedure (TTemp As TGlobalInfo) Dim NewTemp As TGlobalInfo NewTemp = TTemp 'Continue operation using NewTemp instead, leaving TTemp (which is the original structure) unchanged. 'An alternate would be to save TTamp as NewTemp, and then change it back at the end of the procedure, but the above seems simpler. -- Regards, Rick Raisley heavymetal-A-T-bellsouth-D-O-T-net > If I pass the global structure as a parameter to a procedure, You just answered that:> is a local copy created OR am I just referencing the Global structure that > is being passed into the procedure? > VB won't allow a structure to be passed ByVal. If it's a global variable you don't even need to> pass it. Sub SomeProcedure() TTemp.someValue = somethingOrOther End Sub If it were not a global variable it'd still work the same way. You could pass it to a sub. There's no need to have a function for a value returned in a ByRef parameter variable: Sub SomeProcedure(TTemp As TGlobalInfo) TTemp.someValue = somethingOrOther End Sub "mayayana" <mayaXXy***@rcXXn.com> wrote in message I missed the fact that it was global in the first place, so didn't need news:%23x4YOI26JHA.4404@TK2MSFTNGP04.phx.gbl... > >> If I pass the global structure as a parameter to a procedure, >> is a local copy created OR am I just referencing the Global structure >> that >> is being passed into the procedure? > > If it's a global variable you don't even need to > pass it. > passing to the sub/function. -- Regards, Rick Raisley heavymetal-A-T-bellsouth-D-O-T-net Rick:
Thanks for correction, but not needed in my case, I got your point. Hope will resolve my issue. Thanks for your input. Consider thread closed. David Show quoteHide quote "Rick Raisley" <heavymetal-A-T-bellsouth-D-O-Tnet> wrote in message news:%23vtkga36JHA.1416@TK2MSFTNGP04.phx.gbl... > "mayayana" <mayaXXy***@rcXXn.com> wrote in message > news:%23x4YOI26JHA.4404@TK2MSFTNGP04.phx.gbl... >> >>> If I pass the global structure as a parameter to a procedure, >>> is a local copy created OR am I just referencing the Global structure >>> that >>> is being passed into the procedure? >> >> If it's a global variable you don't even need to >> pass it. >> > > > I missed the fact that it was global in the first place, so didn't need > passing to the sub/function. > > -- > Regards, > > Rick Raisley > heavymetal-A-T-bellsouth-D-O-T-net > > |
|||||||||||||||||||||||