From: Ralph on

"dpb" <none(a)non.net> wrote in message
news:haqrim$ivo$2(a)news.eternal-september.org...
> Ralph wrote:
> > "dpb" <none(a)non.net> wrote in message
> > news:haqma1$cci$1(a)news.eternal-september.org...
> >> dpb wrote:
> >>> xytsrm wrote:
> >>>> Thanks dpb,
> >>>>
> >>>> I thought I had done this in VB along time ago, but it might have
been
> >>>> another language. The VarPtr does allow me to get the reference to
> >>>> the variables; perhaps there's another undocumented function that
> >>>> would make the indirect assignment.
> >>> ...
> >>>
> >>> In VB syntax, no.
> >> Even in the one place where there might be a chance the concept of C
> >> union didn't make it into UDTs nor did any incarnation of Fortran's
> >> EQUIVALENCE
> >>
> >> --
> >
> > In VB "unions" are called Variants. <g>
> ...
>
> :)
>
> But not actually as they don't have multiple symbols, only
> data-tolerance for the same variable identifier which is what OP was
> asking for.
>

I think you will find you are cutting too fine a distinction. A VB Variant
is nothing more than a "typed" union (or un-typed in the case of empty),
which is the default datatype in VB and which the language inherently knows
how to managed.

It isn't that VB doesn't have "unions", it is it doesn't need them.

-ralph


From: Eduardo on
Ralph escribi�:
>
> You can write a function that returns a 'variable' ...
>
> Public Function GetStrFromPtr( ByRef addrVar As Long ) As String
> GetStrFromPtr = addrVar
> End Function

It doesn't work for me:
(The long number is just converted to String)

Option Explicit

Dim A As String
Dim B As String
Dim C As String

Dim mPointers(2) As Long

Private Sub Form_Load()
A = "A"
B = "B"
C = "C"
mPointers(0) = StrPtr(A)
mPointers(1) = VarPtr(B)
mPointers(2) = StrPtr(C)

End Sub

Private Sub Command1_Click()
Dim iCr As Long
Dim iPt As Long

For iCr = 0 To 2
iPt = mPointers(iCr)
Debug.Print GetStrFromPtr(iPt)
Next iCr
End Sub

Private Function GetStrFromPtr(ByRef addrVar As Long) As String
GetStrFromPtr = addrVar
End Function
From: xytsrm on
There is a separate undocumented function for array addresses: VarPtrArray

X.

"Ralph" wrote:

>
> "xytsrm" <xytsrm(a)discussions.microsoft.com> wrote in message
> news:44DEDE47-6104-448F-BCFD-C5FEAF8E897D(a)microsoft.com...
> > Thanks dpb,
> >
> > I thought I had done this in VB along time ago, but it might have been
> > another language. The VarPtr does allow me to get the reference to the
> > variables; perhaps there's another undocumented function that would make
> the
> > indirect assignment.
> >
>
> You can write a function that returns a 'variable' ...
>
> Public Function GetStrFromPtr( ByRef addrVar As Long ) As String
> GetStrFromPtr = addrVar
> End Function
>
> This works by declaring the func param as ByRef, which is the address.
> However, you will have to define a Function for each Type.
>
> Also I didn't mention it as you weren't attempting it, but as you are
> playing around it is inevitable you'll come across it sooner or later -
> VarPtr doesn't work for Arrays, but then it kinda does ... <g> VB Arrays are
> SafeArrays objects, and not a simple contiguous block of memory you might
> guess.
>
> Most of this is an old hat that has been chewed to death. Google/Search for
> "VB6 SafeArrays VarPtr" for more gory details. It can be good fun and an
> interesting exercise for an idle weekend if you have yet to go there. But
> appreciate in the end - you will find no practical use for these functions
> in VB except for those few scenarios they were initially designed for.
>
> -ralph
>
>
>
From: xytsrm on
Actually the other language I was referring to was PLM86, a Pascal like
language that allowed indirect addessing through pointer references.

X.


"dpb" wrote:

> Ralph wrote:
> > "dpb" <none(a)non.net> wrote in message
> > news:haqma1$cci$1(a)news.eternal-september.org...
> >> dpb wrote:
> >>> xytsrm wrote:
> >>>> Thanks dpb,
> >>>>
> >>>> I thought I had done this in VB along time ago, but it might have been
> >>>> another language. The VarPtr does allow me to get the reference to
> >>>> the variables; perhaps there's another undocumented function that
> >>>> would make the indirect assignment.
> >>> ...
> >>>
> >>> In VB syntax, no.
> >> Even in the one place where there might be a chance the concept of C
> >> union didn't make it into UDTs nor did any incarnation of Fortran's
> >> EQUIVALENCE
> >>
> >> --
> >
> > In VB "unions" are called Variants. <g>
> ....
>
> :)
>
> But not actually as they don't have multiple symbols, only
> data-tolerance for the same variable identifier which is what OP was
> asking for.
>
> --
>
From: dpb on
Ralph wrote:
> "dpb" <none(a)non.net> wrote in message
> news:haqrim$ivo$2(a)news.eternal-september.org...
>> Ralph wrote:
>>> "dpb" <none(a)non.net> wrote in message
>>> news:haqma1$cci$1(a)news.eternal-september.org...
>>>> dpb wrote:
>>>>> xytsrm wrote:
>>>>>> Thanks dpb,
>>>>>>
>>>>>> I thought I had done this in VB along time ago, but it might have
> been
>>>>>> another language. The VarPtr does allow me to get the reference to
>>>>>> the variables; perhaps there's another undocumented function that
>>>>>> would make the indirect assignment.
>>>>> ...
>>>>>
>>>>> In VB syntax, no.
>>>> Even in the one place where there might be a chance the concept of C
>>>> union didn't make it into UDTs nor did any incarnation of Fortran's
>>>> EQUIVALENCE
>>>>
>>>> --
>>> In VB "unions" are called Variants. <g>
>> ...
>>
>> :)
>>
>> But not actually as they don't have multiple symbols, only
>> data-tolerance for the same variable identifier which is what OP was
>> asking for.
>>
>
> I think you will find you are cutting too fine a distinction. A VB Variant
> is nothing more than a "typed" union (or un-typed in the case of empty),
> which is the default datatype in VB and which the language inherently knows
> how to managed.
>
> It isn't that VB doesn't have "unions", it is it doesn't need them.

I _SAID_ the memory is the same, the syntax of referencing it isn't the
same and it wasn't I who asked the question of how to address the same
memory with two names but OP.

It is a different question; the distinction is in answering the question
asked specifically and it's real.

Whether it is "needed" or not depends on whether wants the particular
facility.

--
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: ItemData screwed up after sort ???
Next: ReDim'ed Array size