Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

C to PowerBASIC Pointer Conversions

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

  • C to PowerBASIC Pointer Conversions

    below is a short c program that does some pointer minipulations
    with strings. the output produced by the program follows directly
    afterwards. right after that in the second post is about the same
    program in powerbasic. as time permits i'll post several more sets
    of comparison programs. a comment thread is in programming at...
    http://www.powerbasic.com/support/pb...ad.php?t=22503

    Code:
    #include "windows.h"
    #include <stdio.h>
    #define  last_index  3
    //
    int main(void)
    {
     char *szdata[]={"zero","one","two","three"}; // initial test data is in szdata[]
     bool blnfree=(bool)null;                     //array, but for purposes of exposition
     char **pmem=null;           //this data will be copied to dynamically allocated 
     unsigned int i,j;           //storage accessed by char pointer to pointer pmem.
     handle hheap;
     //
     hheap=getprocessheap();
     pmem=(char**)heapalloc(hheap,heap_zero_memory,sizeof(char*)*(last_index+1));
     if(pmem)
     {
        printf("allocate 16 bytes to hold four char pointers.\n");
        printf("there will be one allocation to hold the four\n");
        printf("pointers, i.e., pmem, and then four more allocations\n");  
        printf("for memory into which to copy the strings themselves.\n\n");
        printf("pmem=%u\n\n",pmem);
        puts("                        uint (%u)       str (%s)");
        puts("i       &pmem[i]        pmem[i]         pmem[i] ");
        puts("==================================================");
        for(i=0;i<=last_index;i++)
        {
            pmem[i]=(char*)heapalloc(hheap,heap_zero_memory,strlen(szdata[i])+1);
            if(pmem[i])
            {
               strcpy(pmem[i],szdata[i]);  //copy *szdata[] strings to storage
               printf("%u\t%u\t\t%u\t\t%s\n",i,&pmem[i],pmem[i],pmem[i]);
            }
        }
        printf("\n");
        for(i=0;i<=last_index;i++)
        {
            if(pmem[i])
            {  
               for(j=0;j<strlen(pmem[i]);j++)  //try some fancy byte 
                   printf("%c\t",pmem[i][j]);  // minipulations!
               printf("\n");
            }
        }
        printf("\n");
        for(i=0;i<=last_index;i++)
        {
            if(pmem[i])
            {  
               blnfree=!!heapfree(getprocessheap(),0,pmem[i]);
               printf("blnfree=%u\n",blnfree);
            }
        }
        printf("\n");
        blnfree=!!heapfree(getprocessheap(),0,pmem);
        printf("blnfree=%u\n",blnfree);
     }
     else
        puts("memory allocation failure!");
     getchar();
     //
     return 0;
    }
    Code:
    /*
    'output:
    '
    'allocate 16 bytes to hold four char pointers.
    'there will be one allocation to hold the four
    'pointers, i.e., pmem, and then four more allocations
    'for memory into which to copy the strings themselves.
    '
    'pmem=2307184
    '
    '                        uint (%u)       str (%s)
    'i       &pmem[i]        pmem[i]         pmem[i]
    '==================================================
    '0       2307184         2303368         zero
    '1       2307188         2307208         one
    '2       2307192         2307224         two
    '3       2307196         2307240         three
    '
    'z       e       r       o
    'o       n       e
    't       w       o
    't       h       r       e       e
    '
    'blnfree=1
    'blnfree=1
    'blnfree=1
    'blnfree=1
    '
    'blnfree=1
    */
    ------------------
    fred
    "fharris"+chr$(64)+"evenlink"+chr$(46)+"com"



    [this message has been edited by fred harris (edited august 03, 2007).]
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

  • #2
    PowerBASIC implementation of above C program (uses PBCC40):
    '
    Code:
    #Compile Exe                  'Program will demonstrate using pointers with 
    #Dim All                      'PowerBASIC.  The strings 'Zero', 'One', 'Two',
    #Include "Win32Api.inc"       'and 'Three' are first loaded into Asciiz array
    %LAST_ELEMENT = 3             'szData.  This will simulate real data coming 
    '                             'into a program through such sources as files,
    Function PBMain() As Long     'databases, COM ports, etc.  Then a sixteen byte
      Local szData() As Asciiz*8  'buffer is created to store four pointers to 
      Local pStr As Asciiz Ptr    'as yet unallocated memory.  Then memory is 
      Local pMem As Dword Ptr     'allocated to copy the four strings to, and
      Local pByte As Byte Ptr     'those pointers are stored in the former 16 byte
      Local hHeap As Dword        'block (pMem).  The strings and various addresses
      Register i As Long          'are eventually output showing two levels of
      '                           'indirection, as well as other fancy byte 
      Redim szData(%LAST_ELEMENT) As Asciiz*8                    'minipulations
      szData(0)="Zero" : szData(1)="One" : szData(2)="Two" : szData(3)="Three"
      hHeap=GetProcessHeap()
      pMem=HeapAlloc(hHeap,%HEAP_ZERO_MEMORY,(%LAST_ELEMENT+1)*sizeof(pMem))
      If pMem Then
         Print "pMem="pMem : Print
         Print " i         Varptr(@pMem[i]   @pMem[i]     @@pStr"
         Print "================================================"
         For i=0 To %LAST_ELEMENT
           @pMem[i]=HeapAlloc(hHeap,%HEAP_ZERO_MEMORY,Len(szData(i))+1)
           If @pMem[i] Then
              Poke$ Asciiz, @pMem[i], szData(i)
              pStr=Varptr(@pMem[i])
              Print i,Varptr(@pMem[i]),@pMem[i],@@pStr
           End If   
         Next i
         Print
         For i=0 To %LAST_ELEMENT
           If @pMem[i] Then
              [email protected][i]
              While @pByte
                Print Chr$(@pByte)+Space$(8);
                Incr pByte
              Wend 
              Print
           End If    
         Next i 
         Print
         For i=0 To %LAST_ELEMENT
           If @pMem[i] Then
              Print "Abs(IsTrue(HeapFree(hHeap,0,@pMem[i])))="Abs(IsTrue(HeapFree(hHeap,0,@pMem[i])))
           End If   
         Next i
         Print
         Print "Abs(IsTrue(HeapFree(hHeap,0,@pMem)))="Abs(IsTrue(HeapFree(hHeap,0,@pMem)))
      End If 
      Waitkey$
      '
      PBMain=0
    End Function
    Code:
    'Output
    '
    'pMem= 1261648
    '
    ' i         Varptr(@pMem[i]   @pMem[i]     @@pStr
    '================================================
    ' 0             1261648       1282824      Zero
    ' 1             1261652       1282840      One
    ' 2             1261656       1282856      Two
    ' 3             1261660       1282872      Three
    '
    'Z        e        r        o
    'O        n        e
    'T        w        o
    'T        h        r        e        e
    '
    'Abs(IsTrue(HeapFree(hHeap,0,@pMem[i])))= 1
    'Abs(IsTrue(HeapFree(hHeap,0,@pMem[i])))= 1
    'Abs(IsTrue(HeapFree(hHeap,0,@pMem[i])))= 1
    'Abs(IsTrue(HeapFree(hHeap,0,@pMem[i])))= 1
    '
    'Abs(IsTrue(HeapFree(hHeap,0,@pMem)))= 1

    ------------------
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"



    [This message has been edited by Fred Harris (edited August 04, 2007).]
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Comment


    • #3
      The C program below is/does about the same as the 1st C program
      above but it does what it does with four double precision floats.
      '
      Code:
      #include "Windows.h"     //Ptrs2.c
      #include "stdio.h"
      //
      int main(void)
      {
       double dblNums[]={1.234,2.345,3.456,4.567};
       double *ptrNums=NULL,**ptrDoubles=NULL,**ptrPtr=NULL;
       BOOL   blnFree=FALSE;
       unsigned int i;
       //
       ptrNums=(double*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(double)*4);
       if(ptrNums)
       {
          printf("ptrNums=%u\n\n",ptrNums);
          printf("i       &ptrNums[i]     ptrNums[i]\n");   //This program creates storage for
          printf("==================================\n");   //four doubles, i.e., ptrNums, and 
          for(i=0;i<4;i++)                                  //then the four doubles in dblNums
          {                                                 //are copied to this storage.  Then
              ptrNums[i]=dblNums[i];                        //the program allocates storage for
              printf                                        //four pointers to doubles and places
              (                                             //the addresses where the four doubles
               "%u\t%u\t\t%1.3f\n",                         //are sitting into this pointer 
               i,&ptrNums[i], ptrNums[i]                    //storage.
              );
          }
          printf("\n\n");
          ptrDoubles=(double**)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(double*)*4);
          if(ptrDoubles)
          {
             printf("ptrDoubles=%u\n\n",ptrDoubles);
             printf("i       &ptrDoubles[i]  ptrDoubles[i]   *ptrDoubles[i]  **ptrPtr\n");
             printf("================================================================\n");
             for(i=0;i<4;i++)
             {
                 ptrDoubles[i]=&ptrNums[i];
                 ptrPtr=&ptrDoubles[i];
                 printf
                 (
                  "%u\t%u\t\t%u\t\t%1.3f\t\t%1.3f\t\n",
                  i, &ptrDoubles[i], ptrDoubles[i], *ptrDoubles[i], **(ptrDoubles+i), **ptrPtr
                 );
             }
             blnFree=!!HeapFree(GetProcessHeap(),0,ptrDoubles);
             printf("\n\nblnFree=%u\n",blnFree);
          }   
          blnFree=!!HeapFree(GetProcessHeap(),0,ptrNums);
          printf("blnFree=%u\n",blnFree);
       } 
       getchar();
       //
       return 0;
      }
      Code:
      /*
      ptrNums=2307208
      //
      i       &ptrNums[i]     ptrNums[i]
      ==================================
      0       2307208         1.234
      1       2307216         2.345
      2       2307224         3.456
      3       2307232         4.567
      //
      //
      ptrDoubles=2307248
      //
      i       &ptrDoubles[i]  ptrDoubles[i]   *ptrDoubles[i]  **ptrPtr
      ================================================================
      0       2307248         2307208         1.234           1.234
      1       2307252         2307216         2.345           2.345
      2       2307256         2307224         3.456           3.456
      3       2307260         2307232         4.567           4.567
      //
      //
      blnFree=1
      blnFree=1
      */
      ------------------
      Fred
      "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

      [This message has been edited by Fred Harris (edited August 04, 2007).]
      Fred
      "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

      Comment


      • #4
        'This is a PowerBASIC translation of Ptrs2.c just above that deals
        'with doubles instead of strings.
        '
        Code:
        'Ptrs2.bas
        #Compile Exe "Ptrs2.exe"
        #Dim All
        #Include "Win32Api.inc"
        '
        Function PBMain() As Long
          Local ptrNums As Double Ptr
          Local ptrDoubles As Dword Ptr
          Local ptrPtr As Double Ptr
          Local dblNums() As Double
          Local blnFree As Long
          Register i As Long
          '
          Redim dblNums(3) As Double
          dblNums(0)=1.234 : dblNums(1)=2.345 : dblNums(2)=3.456 : dblNums(3)=4.567
          ptrNums=HeapAlloc(GetProcessHeap(),%HEAP_ZERO_MEMORY,sizeof(dblNums(0))*4)
          If ptrNums Then
             Print "ptrNums      ="ptrNums : Print
             Print " i             Varptr(@ptrNums[i]       @ptrNums[i]"
             Print "==================================================="
             For i=0 To Ubound(dblNums,1)
               @ptrNums[i]=dblNums(i)
               Print i,Varptr(@ptrNums[i]),,Format$(@ptrNums[i],"#.###")
             Next i
             Print
             ptrDoubles=HeapAlloc(GetProcessHeap(),%HEAP_ZERO_MEMORY,sizeof(ptrPtr)*4)
             If ptrDoubles Then
                Print "ptrDoubles   ="ptrDoubles : Print
                Print "               ptrPtr, or"
                Print " i             Varptr(@ptrDoubles[i])      @ptrDoubles[i]           @@ptrPtr"
                Print "============================================================================"
                For i=0 To Ubound(dblNums,1)
                  @ptrDoubles[i]=Varptr(@ptrNums[i])
                  ptrPtr=Varptr(@ptrDoubles[i])
                  Print i,ptrPtr,,@ptrDoubles[i],,Format$(@@ptrPtr,"#.###")
                Next i
                blnFree=Abs(IsTrue(HeapFree(GetProcessHeap(),0,ptrDoubles)))
                Print : Print "blnFree="Trim$(Str$(blnFree))
             End If
             Erase dblNums
             blnFree=Abs(IsTrue(HeapFree(GetProcessHeap(),0,ptrNums)))
             Print "blnFree="Trim$(Str$(blnFree))
          End If
          Waitkey$
          '
          PBMain=0
        End Function
        Code:
        'ptrNums      = 1281952
        '
        ' i             Varptr(@ptrNums[i]       @ptrNums[i]
        '===================================================
        ' 0             1281952                    1.234
        ' 1             1281960                    2.345
        ' 2             1281968                    3.456
        ' 3             1281976                    4.567
        '
        'ptrDoubles   = 1282280
        '
        '               ptrPtr, or
        ' i             Varptr(@ptrDoubles[i])      @ptrDoubles[i]           @@ptrPtr
        '============================================================================
        ' 0             1282280                     1281952                    1.234
        ' 1             1282284                     1281960                    2.345
        ' 2             1282288                     1281968                    3.456
        ' 3             1282292                     1281976                    4.567
        '
        'blnFree= 1
        'blnFree= 1
        ------------------
        Fred
        "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"
        Fred
        "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

        Comment


        • #5
          Then here's a set that uses a type/struct and adds the twist to first
          write four records out to a file "Data.dat", then in a procedure
          reads the four records back into allocated memory and mucks around
          with that for a bit.

          Code:
          #include "windows.h"                //Ptrs3.c
          #include <stdio.h>
          #include <string.h>
          //
          typedef struct PERSON               //C will pad this struct with four extra bytes over and above
          {                                   //the thirty-six required by the size of its members.  I believe
           char         szName[24];           //there is an 'attribute' specifier you can use to change this 
           unsigned int iAge;                 //if you want, but for our purposes here we'll live with it.
           double       dblIncome;
          }Person;
          //
          //
          void OutputRoutine(char *pszFileName)
          {
           Person *pFolks=NULL,**ppFolks=NULL;
           Person Somebody;
           BOOL blnFree=0;
           unsigned int i;
           DWORD dwRead;
           HANDLE hFile;
           //
           hFile=CreateFile(pszFileName,GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_FLAG_RANDOM_ACCESS,NULL); //open file
           if(hFile)
           {
              pFolks=(Person*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Person)*4); // Since the struct 
              printf("pFolks=%u\n\n",pFolks);                                                //'Person' is 40 bytes,
              if(pFolks)                                                                     //we're asking HeapAlloc()
              {                                                                              //for a 160 byte buffer
                 printf("i\t&pFolks\tFrenchmen\t\tAge\tIncome\n");                           //here.  It will be 
                 printf("========================================================\n");       //returned in pFolks.
                 for(i=0;i<4;i++)                                           //Then we'll read the four records we put
                 {                                                          //in the file in main() into a Person struct
                     ReadFile(hFile,&Somebody,sizeof(Person),&dwRead,NULL); //here named 'Somebody' (one record at a 
                     strcpy(pFolks[i].szName,Somebody.szName);              //time).  The statements within the loop
                     pFolks[i].iAge=Somebody.iAge;              //then copy the data out of the tempory storage variable
                     pFolks[i].dblIncome=Somebody.dblIncome;    //Somebody and put it into the HeapAlloc()'ed storage
                     printf                                     //buffer pointed to by the pointer var pFolks.  Within
                     (                                          //this 160 byte buffer will exist the original data put
                       "%u\t%u\t%s\t%u\t%6.2f\n",               //in per[] down in main().  Data is stored here, not
                       i,&pFolks[i],pFolks[i].szName,pFolks[i].iAge,pFolks[i].dblIncome //addresses.
                     );
                 }
                 //Two Levels Of Indirection
                 printf("\n\n");
                 printf("sizeof(Person*)=%u\n",sizeof(Person*));
                 ppFolks=(Person**)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(Person*)*4);  //Allocate 16 bytes
                 printf("ppFolks=%u\n\n",ppFolks);                                                  //for four pointers
                 printf("i\t&ppFolks[i]\tppFolks[i]\tFrenchmen\t\tAge\tIncome\n");                  //to pointers.
                 printf("================================================================================\n");
                 for(i=0;i<4;i++)                        //ppFolks is the starting address of a 16 byte buffer whose
                 {                                       //four elements will contain the addresses where the four 
                     ppFolks[i]=&pFolks[i];              //Person structs are stored.  In the example below, the address
                     printf                              //where the 1st szName of the first struct is stored is at
                     (                                   //2307336.  At that memory address the 32 bit number 2307168 
                      "%u\t%u\t\t%u\t\t%s\t%u\t%6.2f\n", //will be stored.
                      i,&ppFolks[i],ppFolks[i],ppFolks[i]->szName,ppFolks[i]->iAge,ppFolks[i]->dblIncome
                     );           
                 }
                 blnFree=!!HeapFree(GetProcessHeap(),0,ppFolks);
                 printf("\nblnFree=%u\n",blnFree);
                 blnFree=!!HeapFree(GetProcessHeap(),0,pFolks);
                 printf("blnFree=%u\n\n",blnFree);
              }
              CloseHandle(hFile);
           }
           else
              puts("Error Opening File!");
          }
          //
          //
          int main(void)
          {
           char szFile[]="Data.dat";
           DWORD dwWritten;
           unsigned int i;
           Person per[4];
           HANDLE hFile;
           //
           strcpy(per[0].szName,"Alexis DeTocqueville");    //1st person    Put names & associated data in array
           per[0].iAge=24;                                  //              of structs ( per[] ).
           per[0].dblIncome=45654.67;
           strcpy(per[1].szName,"Frederic LaPlay     ");    //2nd person    In real program data would come from
           per[1].iAge=48;                                                  //files, databases, other windows 
           per[1].dblIncome=4454.67;                                        //controls, etc.
           strcpy(per[2].szName,"Emile Durkheim      ");    //3rd person
           per[2].iAge=25;
           per[2].dblIncome=49874.67;
           strcpy(per[3].szName,"Rene Descartes      ");    //4th person
           per[3].iAge=67;
           per[3].dblIncome=67432.43;
           printf("sizeof(per[0])=%u\n",sizeof(per[0]));
           hFile=CreateFile(szFile,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_FLAG_RANDOM_ACCESS,NULL);  //CreateFile() Api
           if(hFile)                                        
           {
              for(i=0;i<4;i++)  //write four records to random access binary file
                  WriteFile(hFile,&per[i],sizeof(Person),&dwWritten,NULL);
              CloseHandle(hFile);
           } 
           OutputRoutine(szFile);                           //Call OutputRoutine() to exercise pointers
           getchar();                                       //Pass filename in parameter
           //
           return 0;
          }
          Code:
          /*
          sizeof(per[0])=40
          pFolks=2307168
          '
          i       &pFolks Frenchmen               Age     Income
          ========================================================
          0       2307168 Alexis DeTocqueville    24      45654.67
          1       2307208 Frederic LaPlay         48      4454.67
          2       2307248 Emile Durkheim          25      49874.67
          3       2307288 Rene Descartes          67      67432.43
          '
          '
          sizeof(Person*)=4
          ppFolks=2307336
          '
          i       &ppFolks[i]     ppFolks[i]      Frenchmen               Age     Income
          ================================================================================
          0       2307336         2307168         Alexis DeTocqueville    24      45654.67
          1       2307340         2307208         Frederic LaPlay         48      4454.67
          2       2307344         2307248         Emile Durkheim          25      49874.67
          3       2307348         2307288         Rene Descartes          67      67432.43
          '
          blnFree=1
          blnFree=1
          */
          ------------------
          Fred
          "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"
          Fred
          "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

          Comment


          • #6
            PowerBASIC implementation of above Ptrs3.c

            '
            Code:
            #Compile Exe      'Ptrs3.bas
            #Dim All
            #Include "Win32Api.inc"
            '
            Type Person
              szName          As Asciiz*24
              dwAge           As Dword
              dblIncome       As Double
            End Type
            '
            '
            Sub OutputRoutine(strFileName As String)
              Local pSomebody As Person Ptr
              Local pSomeone As Person Ptr
              Local pBody As Person Ptr
              Local dwPtr As Dword Ptr
              Local Someone As Person
              Local blnFree As Long
              Register i As Long
              Local fp As Integer
              '
              fp=Freefile
              Open strFileName For Random As #fp Len=Len(Person)
              pSomeone=HeapAlloc(GetProcessHeap(),%HEAP_ZERO_MEMORY,sizeof(Person)*4)
              Print "pSomeone = "pSomeone : Print
              If pSomeone Then
                 Print "Some of My Favorite Frenchmen"
                 Print
                 Print " i   Varptr(@pSomeone[i])  @pSomeone[i].szName   @pSomeone[i].dwAge  @pSomeone[i].dblIncome"
                 Print "============================================================================================="
                 For i=0 To 3
                   Get #fp,i+1,Someone
                   Poke$ Asciiz, Varptr(@pSomeone[i]), Someone.szName
                   @pSomeone[i].dwAge=Someone.dwAge
                   @pSomeone[i].dblIncome=Someone.dblIncome
                   Print i; _
                   Tab(5)Varptr(@pSomeone[i]); _
                   Tab(28)@pSomeone[i].szName; _
                   Tab(58)@pSomeone[i].dwAge; _
                   Tab(75)@pSomeone[i].dblIncome
                 Next i
                 Print
                 dwPtr=HeapAlloc(GetProcessHeap(),%HEAP_ZERO_MEMORY,16)
                 Print
                 Print "dwPtr = "dwPtr
                 Print
                 Print " i   Varptr(@dwPtr[i])  @dwPtr[i]   @pSomeone[i].szName     @pSomeone[i].dwAge  @pSomeone[i].dblIncome"
                 Print "======================================================================================================"
                 If dwPtr Then
                    For i=0 To 3
                      @dwPtr[i]=Varptr(@pSomeone[i])
                      [email protected][i]
                      Print i; _
                      Tab(5)Varptr(@dwPtr[i]); _
                      Tab(24)@dwPtr[i]; _
                      Tab(37)@pSomebody.szName; _
                      Tab(60)@pSomebody.dwAge; _
                      Tab(84)@pSomebody.dblIncome
                    Next i
                    Print:Print
                    Print " i   pBody    @dwPtr[i]  @@pBody.szName       @@pBody.dwAge  @@pBody.dblIncome"
                    Print "=============================================================================="
                    For i=0 To 3
                      pBody=Varptr(@dwPtr[i])
                      Print i; _
                      Tab(5)pBody; _
                      Tab(14)@dwPtr[i]; _
                      Tab(26)@@pbody.szName; _
                      Tab(50)@@pbody.dwAge; _
                      Tab(64)@@pbody.dblIncome
                    Next i
                    blnFree=Abs(IsTrue(HeapFree(GetProcessHeap(),0,pSomeone)))
                    Print
                    Print "blnFree="blnFree
                 End If
                 Close #fp
                 blnFree=Abs(IsTrue(HeapFree(GetProcessHeap(),0,dwPtr)))
                 Print "blnFree="blnFree
              End If
            End Sub
            '
            '
            Function PBMain() As Long
              Local strFile As String
              Local per() As Person
              Register i As Long
              Local fp As Integer
              '
              Redim per(3) As Person
              per(0).szName="Alexis Detocqueville"                    '1st person
              per(0).dwAge=24
              per(0).dblIncome=45654.67
              per(1).szName="Emile Durkheim      "                    '2nd person
              per(1).dwAge=48
              per(1).dblIncome=47453.12
              per(2).szName="Frederic LePlay     "                    '3rd person
              per(2).dwAge=25
              per(2).dblIncome=93654.67
              per(3).szName="Rene Descartes      "                    '4th person
              per(3).dwAge=67
              per(3).dblIncome=45654.67
              Print "SizeOf(Person)="SizeOf(Person)
              strFile="Data.dat"
              fp=Freefile
              Open strFile For Random As #fp Len=Len(Person)
              For i=0 To 3
                Put #fp,i+1,per(i)
              Next i
              Close #fp
              Call OutputRoutine(strFile)
              Waitkey$
              '
              PBMain=0
            End Function

            Code:
            'SizeOf(Person)= 36
            'pSomeone =  1282512
            '
            'Some of My Favorite Frenchmen
            '
            ' i   Varptr(@pSomeone[i])  @pSomeone[i].szName   @pSomeone[i].dwAge  @pSomeone[i].dblIncome
            '=============================================================================================
            ' 0   1282512               Alexis Detocqueville           24               45654.67
            ' 1   1282548               Emile Durkheim                 48               47453.12
            ' 2   1282584               Frederic LePlay                25               93654.67
            ' 3   1282620               Rene Descartes                 67               45654.67
            '
            '
            'dwPtr =  1282704
            '
            ' i   Varptr(@dwPtr[i])  @dwPtr[i]   @pSomeone[i].szName     @pSomeone[i].dwAge  @pSomeone[i].dblIncome
            '======================================================================================================
            ' 0   1282704            1282512     Alexis Detocqueville    24                      45654.67
            ' 1   1282708            1282548     Emile Durkheim          48                      47453.12
            ' 2   1282712            1282584     Frederic LePlay         25                      93654.67
            ' 3   1282716            1282620     Rene Descartes          67                      45654.67
            '
            '
            ' i   pBody    @dwPtr[i]  @@pBody.szName       @@pBody.dwAge  @@pBody.dblIncome
            '==============================================================================
            ' 0   1282704  1282512    Alexis Detocqueville     24            45654.67
            ' 1   1282708  1282548    Emile Durkheim           48            47453.12
            ' 2   1282712  1282584    Frederic LePlay          25            93654.67
            ' 3   1282716  1282620    Rene Descartes           67            45654.67
            '
            'blnFree= 1
            'blnFree= 1
            ------------------
            Fred
            "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"
            Fred
            "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

            Comment

            Working...
            X