Home All Groups Group Topic Archive Search About

Passing Structure (Type)

Author
12 Jun 2009 12:44 PM
David
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?

Author
12 Jun 2009 1:01 PM
Rick Raisley
Show quote Hide quote
"David" <dw85745***@earthlink.net> wrote in message
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?
>

I would presume using the structure would be the same as other variables, so
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
Author
12 Jun 2009 1:28 PM
mayayana
> 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?

You just answered that:

> 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
Author
12 Jun 2009 3:58 PM
Rick Raisley
"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
Author
12 Jun 2009 6:14 PM
David
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
>
>