home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / PBAPI10.ZIP / USERSIDX.BAS < prev    next >
BASIC Source File  |  1998-02-21  |  9KB  |  189 lines

  1. ' ─────────────────────────────────────────────────────────────────────────
  2. ' Program Title: Sample Program for TriBBS's USERS.IDX API UNIT
  3. '     Copyright: 1997-98 by Freejack's Software
  4. '        Author: Gary Price
  5. ' Last Modified: 02/21/98
  6. ' ─────────────────────────────────────────────────────────────────────────
  7. '         Notes:
  8. ' ─────────────────────────────────────────────────────────────────────────
  9. '       History:
  10. ' ─────────────────────────────────────────────────────────────────────────
  11. '
  12. ' In this sample.bas file, you will see servals different examples on how
  13. ' to use the Pointer "ui" to make calls to the TriBBS API USERSIDX.PBU Unit.
  14. ' Also there are some examples showing how to use the USERSIDX.PBU Unit
  15. ' without using pointers.  To use any of the current examples, go to the
  16. ' section and you will see a "$IF 0" statment at the head of the example, all
  17. ' you need to do to make that section of code run is change the '0' to any
  18. ' non-zero number.
  19. '
  20. ' A pointer is a varible that holds 32-bit (4 byte) address of data located
  21. ' elsewhere in memory. It is called a pointer because it literally points
  22. ' to data. The data at which it points is known as the target.
  23. '
  24. ' Pointers are Powerfull! The address is defined at run-time, so any target
  25. ' in memory can be referenced by your program just as if it were a standard
  26. ' PowerBASIC varible. This type of indirection is much faster and more
  27. ' efficient than PEEKing and POKEing at the target data.
  28. '
  29. ' All String Pointer calls will grab the data from memory, and strip any
  30. ' spaces and null terminator characters from the end of the string which
  31. ' will allow you to print with better screen output control.
  32. '
  33. ' When writting back to memory with a pointer string, this USERSIDX API will
  34. ' set the length back to proper size and add the null terminator, CHR$(0)
  35. ' to the end of the string. This again, will save time in writting back
  36. ' to the original record USERS.IDX.
  37. '
  38. ' For non-pointer calls, you will have to adjust the string yourself for
  39. ' proper printing to the screen. Also, when writting back to the USERS.IDX
  40. ' file, you must add a num terminator to the end of the string. More on this
  41. ' in the Non-Pointer example.
  42. ' ─────────────────────────────────────────────────────────────────────────
  43.  
  44. $CPU 80386                    ' Requires a 386 system or faster
  45.  
  46. $OPTIMIZE SPEED             ' make fastest possible executable
  47.  
  48. '$COMPILE EXE "USERIDX.EXE" ' compile to an EXE
  49.  
  50. $DEBUG MAP OFF              ' turn off map file generation
  51. $DEBUG PBDEBUG OFF          ' don't include pbdebug support in our executable
  52.  
  53. $LIB COM        OFF         ' turn off PowerBASIC's communications library.
  54. $LIB CGA        OFF         ' turn off PowerBASIC's CGA graphics library.
  55. $LIB EGA        OFF         ' turn off PowerBASIC's EGA graphics library.
  56. $LIB VGA        OFF         ' turn off PowerBASIC's VGA graphics library.
  57. $LIB LPT        OFF         ' turn off PowerBASIC's printer support library.
  58. $LIB IPRINT     OFF         ' turn off PowerBASIC's interpreted print library.
  59. $LIB FULLFLOAT  OFF         ' turn off PowerBASIC's floating point support.
  60.  
  61. $ERROR BOUNDS   ON          ' turn on bounds checking for pointer debugging
  62. $ERROR NUMERIC  OFF         ' turn off numeric checking
  63. $ERROR OVERFLOW OFF         ' turn off overflow checking
  64. $ERROR STACK    OFF         ' turn off stack checking
  65.  
  66. $COM    0                   ' set communications buffer to nothing
  67. $STRING 16                  ' set largest string size at 16k
  68. $STACK  2048                ' let's use a 2k stack
  69. $SOUND  1                   ' smallest music buffer possible
  70.  
  71. $DIM ALL                    ' forces all Varibles and Arrays to be
  72.                             ' pre-dementioned before use.
  73.  
  74. $DYNAMIC                    ' all arrays will be dynamic by default
  75.  
  76. $OPTION CNTLBREAK OFF       ' don't allow Ctrl-Break to exit program
  77.  
  78. DEFINT A-Z                  ' default all variables to integers for maximum
  79.                             ' speed and minimum size
  80. '============================================================================
  81.  
  82.  
  83. '============================================================================
  84. '                          DECLARATIONS SECTION
  85. '============================================================================
  86. ' ** THIS SECTION IS FOR LINKS AND INCLUDES STATMENTS **
  87.  
  88. $LINK "G:\PB35\TBAPI10\PBAPI10.PBL"    ' ** SET THIS LINE TO YOUR PATH **
  89. $INCLUDE "G:\PB35\TBAPI10\PBAPI10.INC" ' ** SET THIS LINE TO YOUR PATH **
  90.  
  91. '---------------------------------------------------------------------------
  92. ' ** DECLARE SUB's BELOW THAT WILL BE USED IN THIS PROGRAM **
  93. '
  94. ' Use this section for any declarations needed to be made other than the
  95. ' USERS.IDX API which are located in the USERSIDX.INC file.
  96.  
  97. '----------------------------------------------------------------------------
  98. ' ** SET THIS LINE BELOW TO YOUR TRIBBS MAIN NODE's DIRECTORY **
  99.  
  100. TBNode1sMainDirectory = "E:\TRIBBS"
  101. '============================================================================
  102.  
  103. '============================================================================
  104. '                         ** MAIN PROGRAM BODY **
  105. '============================================================================
  106.  
  107. CLS     ' Clears screen prepares it for printing
  108.  
  109. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. '                ** EXAMPLE 1 for USERS.IDX Pointer Calls **
  111. '----------------------------------------------------------------------------
  112. $IF 0 ' Change the '0' to '1' to run this example
  113.  
  114.   USERS_IDX_Open           ' Will Open USERS.IDX
  115.  
  116.     'PRINT "Total Records:" USERS_IDX_Length  ' Returns and Prints Number of
  117.                                               ' Records in USERS.IDX
  118.  
  119.    ' Search the USERS.IDX for a user's name. If found, will read record into
  120.    ' memory, then you can read the user's name and record number. If user
  121.    ' name isn't found, then it will return a '0'.
  122.  
  123.     IF USERS_IDX_Search("Gary Price") <> 0 THEN ' Checks to see if user is
  124.                                                 ' in the users.idx file.
  125.                                                   ' 0 = User was not found
  126.                                                   ' 1 = User was found
  127.  
  128.       PRINT USERS_IDX_GetUN  ' Returns a 32-bit pointer to the User's Name
  129.                              ' string after the search.
  130.       PRINT USERS_IDX_GetRN  ' Returns a 32-bit pointer to the User's Record
  131.                              ' Number after the search
  132.     END IF                   ' Ends IF/END statment
  133.  
  134.   USERS_IDX_Close          ' Closes USERS.IDX file
  135.  
  136. $ENDIF
  137. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138.  
  139. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. '                ** EXAMPLE 2 for USERS.DAT Pointer Calls **
  141. '----------------------------------------------------------------------------
  142. $IF 0 ' Change the '0' to '1' to run this example
  143.  
  144. DIM RecNum AS WORD
  145.  
  146.    ' Search the USERS.IDX for a user's name. If found, will read record into
  147.    ' memory, then you can get the record number and pass it to 'RecNum' so it
  148.    ' can search and obtain user's information from the Users.dat file. If
  149.    ' user's name isn't found, then USERS_IDX_Search() will return a '0'.
  150.  
  151.  USERS_IDX_Open             ' Opens USERS.IDX
  152.  
  153.  IF USERS_IDX_Search("Gary Price") <> 0 THEN ' Checks to see if user is
  154.                                              ' in the users.idx file.
  155.                                                ' 0 = User was not found
  156.                                                ' 1 = User was found
  157.  
  158.      RecNum = USERS_IDX_GetRN ' Returns a 32-bit pointer to the User's
  159.                               ' Record Number after the search
  160.  
  161.  USERS_DAT_OpenReadClose RecNum  ' Will Open, Read and Close USERS.DAT
  162.                                  ' for RecNum, which was returned by the
  163.                                  ' USERS_IDX_Search function
  164.  
  165.   ' Grab File Area's data from memory using the a 32-bit pointer
  166.   ' and print partial record
  167.  
  168.     PRINT USERS_DAT_GetUN     ' Name
  169.     PRINT USERS_DAT_GetAN     ' Alias Name
  170.     PRINT USERS_DAT_GetUP     ' Password
  171.     PRINT USERS_DAT_GetSA1    ' Street Address 1
  172.     PRINT USERS_DAT_GetSA2    ' Street Address 2
  173.     PRINT USERS_DAT_GetCity   ' City
  174.     PRINT USERS_DAT_GetUS     ' State
  175.     PRINT USERS_DAT_GetUC     ' Country
  176.     PRINT USERS_DAT_GetUZ     ' Zipcode
  177.     PRINT USERS_DAT_GetUPN    ' Phone Number
  178.     PRINT USERS_DAT_GetUBD    ' Birth Date
  179.  
  180.  END IF       ' Ends the END/IF condition for Users.idx search
  181.  
  182.  USERS_IDX_Close              ' Closes USERS.IDX file
  183.  
  184.  
  185. $ENDIF
  186.  
  187. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188. END                          ' Ends the Program
  189.