Announcement

Collapse
No announcement yet.

How to simplify visual aspect of code?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to simplify visual aspect of code?

    I'm writing code with an array Dim'd as a UDT, where I access the value with this nomenclature:

    Code:
    D(i).x
    D(i).y
    To simplify the visual aspect of my code, I'd like to use a single letter such as X or Y in place of the D(i).X and D(i).Y nomenclature, where I have to set the current element of the array somehow.

    Does PowerBASIC allow two variables to share the same address space, or have some other feature which would let me do what I want?

    I thought of using a macro, but assumed it would mess up other statements which should contain an X or Y (such as MsgBox).
    Last edited by Gary Beene; 21 Apr 2009, 08:56 AM.

  • #2
    Not a single character, but you could use a pointer.

    Code:
    LOCAL X AS DWORD PTR  ' Use proper variable type ie. LONG DWORD, etc.
    
    X = VARPTR(D(i).X)
    
    @X = 99   '  D(i).X = 99
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

    Comment


    • #3
      Well, UNIONs allow two named variables to share the same memory space...but...

      I thought of using a macro, but assumed it would mess up other statements which should contain an X or Y (such as MsgBox
      Well, if you used "X" or "Y" it would. Just use some token not likely to occur. I "assume" your desire here is to eliminate the PITA typing required..... dix is easier to type than d(i).X if you ask me.

      Code:
      MACRO  DIX =  D(i).X 
      MACRO  DIY =  D(i).Y 
      
         FOR I  = one to many 
              Z(i)  = DIX * DIY
         NEXT
      If you really wanted to get fancy you could use PTR vars

      Code:
       LOCAL pD AS MYTYPE PTR 
        REDIM D (somenumber) AS Mytype 
      
        pd =  VARPTR (D (0)) 
        FOR I = one to many_not_to_exceed_UBOUND 
            Z(I) =  @pD.X * @pD.Y 
            INCR pD 
        NEXT
      MCM
      Last edited by Michael Mattias; 21 Apr 2009, 09:11 AM.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Hey guys - quick responses - thanks!

        The pointer would mean that I have to set X each time i changes, so that might not simplify as much as I had in mind.

        The use of a 3-letter macro avoids the simple single-letter problem I noted, and DIX (or something like it) is certainly easier to type than D(i).x.

        Looks like a macro can pretty much get me there.

        Comment

        Working...
        X