Link to home
Start Free TrialLog in
Avatar of bobf22
bobf22

asked on

SHARED ARRAYS IN VB

I'm converting from VAX BASIC to VB. Is there a way similar to VMS's Named COMMON or C's UNION statement where I can have several arrays start at the same address in memory? The application is a realtime structure which uses a linked list of values; some are bytes, some are integers, some long integers.

Byte BArray (2047,31)    ' 32 bytes
Word IArray (2047,15)    ! 32 bytes
Long LArray (2047,7)     ! 32 bytes

I would like to see these arrays overlay each other by starting at the same physical memory address.

Thanks in Advance,
Bob Fidelman
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

As far as i know, you can't have the arrays to be analysed the way you want, but you can copy the memory (using the LSet operator) from one array to the other, thus simulation the behaviour.

Hope this helps
Avatar of GivenRandy
GivenRandy

Yes, LSet works okay for what you want to do.  For other things (like converting Single floats to Longs) is easy with the MoveMemory API.

-- in module --

Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)

-- in form / module --

Public Function AsciiFloat(S As String) As Single
    Dim L As Long
    Dim F As Single
   
    L = AsciiLong(S)
    MoveMemory F, L, 4
    AsciiFloat = F
End Function


Helas VB does not have a UNION like structure
Don't know how to do it but maybe u can use the win32 memory mapped file functions in VB using global namespace(like mapped common block in Vax/VMS)to share data between applications.
Read the book "VB Progr. Guide to the Win32 API" -by Dan Appleman.
There're examples elaborated in that book.

I hope this help u
ASKER CERTIFIED SOLUTION
Avatar of Spngbob_SqPnts
Spngbob_SqPnts

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobf22

ASKER

This is great... it gives me a head start on the array and pointers. excellent answer.