Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    In pascal or C, i can write a variant record or union, respectively, like this

    type Rec = record
    case integer of
    0: (i: integer);
    1: (d: double);
    end;

    This structure forces Rec.i and Rec.d to share the same storage. Is there a VBA equivalent?

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    I'm not sure if this is what you want, but you can use the TYPE statement to create a user-defined datatype containing 1 or more elements.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    VB/VBA doesn't deal directly with pointers. In fact, it's downright difficult to even get the actual address in VB. What are you trying to do?
    Charlotte

  4. #4
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    the TYPE statement _might_ be what i want, but putting two "fields" in a type merely aggregates two individual types. The storage allocated is the sum of the lengths of each field.

    What I want to do is refer to the SAME storage, in two separate and distinct ways, without making a copy. Often, in any language, this is "an error".

  5. #5
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    I don't mind downright difficult, if there is a way at all, because i can do it once, and stick it in a class (maybe). Or at least get the principle down, and provide a tool that does the hard part.

    I am also trying to coerce the calling system to allow something like

    Dim b() as byte
    Call SubA([img]/forums/images/smilies/cool.gif[/img]
    ...
    Sub SubA(s as String)
    '
    ' ... mess around with bytes using string functions

    or vice versa, strings as bytes, but i am failing so far in that attempt.

    'Variant' seems to do a bunch of built-in conversions, so that doesnt look like a promising approach.

    i may have to build a dll in another language to allow what i want to do - is that what you meant by "downright "? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    The only way you can do it in VB/VBA is by using a Variant variable, which can hold various datatypes and even objects. Of course, the variant expands to hold what you stow in it, so it isn't using *exactly* the same storage, but that's about as close as you're going to come. On the other hand, variants are inefficient for the same reason they are so useful.

    Parenthetically, It isn't usual to try to control VBA to the level you control languages like C. It wasn't built for it, and it will fight you all the way.
    Charlotte

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    There is an indirect method for returning the actual address being used, but it isn't really useful in VB since you can't do much with it. I'm sure google can track it down for you, but I've lost track of it over the years.

    The problem you're running into is that you can't pass a byte array to a string argument. Your arguments have to match the declaration unless you pass them into a variant.
    Charlotte

  8. #8
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    ok, i'll look at the Variant a little more closely.

    >>Parenthetically, It isn't usual to try to control VBA to the level you control languages like C. It wasn't built for it, and it will fight you all the way.

    That's the story of my life <img src=/S/grin.gif border=0 alt=grin width=15 height=15>. Where are the Achilles heels in VBA, if there are any?

  9. #9
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    This looks interesting...
    http://www.codeproject.com/useritems/how_t...isual_basic.asp

    there are a few others. I'll check them out.

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    All over the place, but they usually just break the application rather than breaking down and letting you do what you want. VB/VBA wasn't designed to do low-level stuff like C and Pascal. It's designed to manipulate the interface at a much higher level and to hide all the technical stuff that's going on in underlying dlls.
    Charlotte

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    Just remember, pointers notwithstanding, you still can't get VB/VBA to accept a byte array directly into a string argument.
    Charlotte

  12. #12
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    Drat!

  13. #13
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    How would you rate this book's applicability to VBA, altho it is aimed at VB?:
    Advanced Visual Basic 6 : Power Techniques for Everyday Programs, Book w/CD-ROM (The DevelopMentor Series) by Matthew Curland

  14. #14
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    You can on the other hand simply assign your byte array to a string variable and pass that to your procedure, which would seem like the simplest thing to me. Any use?
    Regards,
    Rory

    Microsoft MVP - Excel

  15. #15
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA equivalent to Pascal or C? (AXP 10.2627.2625)

    The assign is essentially a copy, whereas i am trying to access "the original thing" as if it were "some other thing". I want to work with a reference or pointer to "the original thing" without doing a copy.

    You're probably right, tho, (Charlotte, too), that i am trying to do "too much" & just do the simple things that VBA is designed for.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •