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

  1. ' ─────────────────────────────────────────────────────────────────────────
  2. ' Program Title: Sample Program for TriBBS's USERS.DAT 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 "ud" to make calls to the TriBBS API USERSDAT.PBU Unit.
  14. ' Also there are some examples showing how to use the USERSDAT.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 Powerful! 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 USERSDAT 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.DAT.
  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.DAT
  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 "USERDAT.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.DAT API which are located in the USERSDAT.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.DAT Pointer Calls **
  111. '----------------------------------------------------------------------------
  112. $IF 0 ' Change the '0' to '1' to run this example
  113.  
  114. DIM UN AS STRING          ' Dimention a Local Varible to hold User's Name for
  115.                           ' this example
  116.  
  117.   USERS_DAT_OpenRead 1    ' Will Open and Read in USERS.DAT
  118.                           ' record #1
  119.  
  120.     PRINT "Total Records:" USERS_DAT_Length ' Returns and Prints Total
  121.                                            ' Records in USERS.DAT
  122.  
  123.     UN = USERS_DAT_GetUN  ' Returns a 32-bit pointer to the User's Name
  124.                           ' string
  125.  
  126.     PRINT UN              ' Prints the User's Name
  127.  
  128.     USERS_DAT_PutUN "New User Name"  ' Let's put a new User Name in for
  129.                                      ' this User's Record
  130.  
  131.     PRINT USERS_DAT_GetUN ' Returns a 32-bit pointer to the User's Name
  132.                           ' string with the new User's Name.
  133.  
  134.   USERS_DAT_Close         ' Closes USERS.DAT file
  135.  
  136.  ' In the example below, we can open, read, close the USERS.DAT file, also
  137.  ' get and print the User's Alais Name from record #1 all in a single
  138.  ' line of code. :)
  139.  
  140.    PRINT    ' Print a blank line
  141.    USERS_DAT_OpenReadClose 1 : PRINT USERS_DAT_GetAN
  142.  
  143. $ENDIF
  144. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145.  
  146. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. '                ** EXAMPLE 2 for USERS.DAT Pointer Calls **
  148. '----------------------------------------------------------------------------
  149. $IF 0 ' Change the '0' to '1' to run this example
  150.  
  151.  USERS_DAT_OpenReadClose 1    ' Will Open and Read in USERS.DAT
  152.                              ' record #1 and Close the file
  153.  
  154.   ' Grab File Area's data from memory using the a 32-bit pointer
  155.  
  156.     PRINT USERS_DAT_GetUN     ' Name
  157.     PRINT USERS_DAT_GetAN     ' Alias Name
  158.     PRINT USERS_DAT_GetUP     ' Password
  159.     PRINT USERS_DAT_GetSA1    ' Street Address 1
  160.     PRINT USERS_DAT_GetSA2    ' Street Address 2
  161.     PRINT USERS_DAT_GetCity   ' City
  162.     PRINT USERS_DAT_GetUS     ' State
  163.     PRINT USERS_DAT_GetUC     ' Country
  164.     PRINT USERS_DAT_GetUZ     ' Zipcode
  165.     PRINT USERS_DAT_GetUPN    ' Phone Number
  166.     PRINT USERS_DAT_GetUBD    ' Birth Date
  167.     PRINT USERS_DAT_GetDOFC   ' Date Of First Call
  168.     PRINT USERS_DAT_GetDOLFC  ' Date Of Last File Check
  169.     PRINT USERS_DAT_GetSED    ' Subscription Expiration Date
  170.     PRINT USERS_DAT_GetDATOLC ' Date And Time Of Last Call
  171.     PRINT USERS_DAT_GetEM     ' Expert Mode
  172.                                ' 0 = Novice mode.
  173.                                ' 1 = Expert mode.
  174.                                ' 2 = Super expert mode.
  175.     PRINT USERS_DAT_GetSL     ' Security Level
  176.     PRINT USERS_DAT_GetNOC    ' Number Of Calls
  177.     PRINT USERS_DAT_GetTLFT   ' Time Left For Today (Minutes)
  178.     PRINT "LMC: ";USERS_DAT_GetLMC    ' Last Message Conference
  179.     PRINT "LFA: ";USERS_DAT_GetLFA    ' Last File Area
  180.     PRINT USERS_DAT_GetDP     ' Default Protocol
  181.                                ' 0        = No default.
  182.                                ' 1 to 255 = ASCII code for the protocol's
  183.                                ' first character.
  184.  
  185.        PRINT
  186.        PRINT "Hit Any Key To Continue"
  187.        DO: LOOP WHILE INKEY$ = ""
  188.        CLS
  189.  
  190.     PRINT USERS_DAT_GetNOCT   ' Number Of Calls Today
  191.     PRINT USERS_DAT_GetDE     ' Default Editor
  192.                                ' 0 = No default editor.
  193.                                ' 1 = Line editor.
  194.                                ' 2 = Full screen editor.
  195.     PRINT USERS_DAT_GetICS    ' Initial Chat Status
  196.                                ' 0 = Available for chat.
  197.                                ' 1 = Not available for chat.
  198.     PRINT USERS_DAT_GetNOFDT  ' Number Of Files Downloaded Today
  199.     PRINT USERS_DAT_GetAUIQ   ' Archive Used In QWK
  200.                                ' 0 = ZIP
  201.                                ' 1 = LZH
  202.                                ' 2 = ARJ
  203.                                ' 3 = ARC
  204.                                ' 4 = PAK
  205.     PRINT USERS_DAT_GetNOFU   ' Number Of Files Uploaded
  206.     PRINT USERS_DAT_GetNOFD   ' Number Of Files Downloaded
  207.     PRINT USERS_DAT_GetNOKBU  ' Number Of KBytes Uploaded
  208.     PRINT USERS_DAT_GetNOKBD  ' Number Of KBytes Downloaded
  209.     PRINT USERS_DAT_GetNOMP   ' Number Of Messages Posted
  210.     PRINT USERS_DAT_GetNOBDT  ' Number Of Bytes Downloaded Today
  211.     PRINT USERS_DAT_GetNWN    ' Gets all of the Network Names for this
  212.                               ' User if he/she has QWK Network Node Status
  213.  
  214.  ' ** These are Bit Fields converted to integers below **
  215.  
  216.     PRINT USERS_DAT_GetNWF(1) ' Gets Network Flag for Record #(nw)
  217.                              ' (nw) = 1 to 16
  218.    ' USERS_DAT_PutNWF(nw, n)  ' Changes Network Flag for Record #(nw, n)
  219.                                ' nw = 1 to 16
  220.                                ' n  = either 0 or 1
  221.                                ' 0 = User does not have netstatus for the
  222.                                '     network 'nw'.
  223.                                ' 1 = The user has netstatus for the
  224.                                '     network 'nw'.
  225.     PRINT USERS_DAT_GetLOF    ' Locked Out Flag
  226.                                ' 0 = The user is not locked out.
  227.                                ' 1 = The user is locked out.
  228.     PRINT USERS_DAT_GetMFDF   ' Marked For Deletion Flag
  229.                                ' 0 = The user is not marked for deletion.
  230.                                ' 1 = The user is marked for deletion.
  231.     PRINT USERS_DAT_GetILIQF  ' Include Logon1 In QWK Flag
  232.                                ' 0 = Do not include LOGON1 in a QWK packet.
  233.                                ' 1 = Include LOGON1 in a QWK packet.
  234.     PRINT USERS_DAT_GetIGIQF  ' Include Goodbye In QWK Flag
  235.                                ' 0 = Do not include GOODBYE in a QWK packet.
  236.                                ' 1 = Include GOODBYE in a QWK packet.
  237.     PRINT USERS_DAT_GetIBIQF  ' Include Bulletins in QWK Flag
  238.                                ' 0 = Do not include Bulletins in a QWK packet.
  239.                                  ' 1 = Include bulletins in a QWK packet.
  240.     PRINT USERS_DAT_GetINFIQF ' Include New Files In QWK Flag
  241.                                ' 0 = Do not include a new files list in a QWK
  242.                                '     packet.
  243.                                ' 1 = Include a new files list in a QWK packet.
  244.     PRINT USERS_DAT_GetINLIQF ' Include News Letter In QWK Flag
  245.                                ' 0 = Do not include a newsletter in a QWK
  246.                                '     packet.
  247.                                ' 1 = Include a newsletter in a QWK packet.
  248.     PRINT USERS_DAT_GetCWMF   ' Check Waiting Messages Flag
  249.                                ' 0 = Check for waiting messages at logon.
  250.                                ' 1 = Do not check for waiting messages at
  251.                                '     logon.
  252.     PRINT USERS_DAT_GetGAUF   ' Goodbye After Upload Flag
  253.                                ' 0 = Do not log off after a REP packet
  254.                                '     upload.
  255.                                ' 1 = Log the user off after a REP packet
  256.                                '     upload.
  257.     PRINT USERS_DAT_GetAFIQF  ' Attach Files In QWK Flag
  258.                                ' 0 = Do not include attached files in a QWK
  259.                                '     packet.
  260.                                ' 1 = Include attached files in a QWK packet.
  261.  
  262. $ENDIF
  263.  
  264. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  265. '                ** EXAMPLE for USERS.DAT Non-Pointer Calls **
  266. '----------------------------------------------------------------------------
  267. '
  268. ' This sample section will show how to use the USERDAT.PBU Unit in it's basic
  269. ' form. This will require more string operations than the pointer section
  270. ' since you will be grabing just basic data straight from the USERS.DAT
  271. ' file. Trimming, and removing and adding null terminators will have to be
  272. ' performed in this manner. If is very important when writting any data
  273. ' back to the USERS.DAT file in this manner, you add the null terminator
  274. ' CHR$(0) to the end of all normal predefined strings based on the USERS.DAT
  275. ' type structure located in the USERDAT.INC file. Follow the example below.
  276. '
  277. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278.  
  279. $IF 0  ' Change the '0' to '1' to run this example
  280.  
  281.  USERS_DAT_OpenRead 1        ' Open USERS.DAT File, and Read in record #1
  282.  
  283.  
  284.   PRINT USERSDAT.UserName   ' Prints User's Name with padded spaces from
  285.                             ' USERS.DAT file
  286.   PRINT LEN(USERSDAT.UserName) ' Prints Len of User's Name
  287.                                ' This shows a string length of 61 characters,
  288.                                ' which is 60 charcaters that you may use for
  289.                                ' data, and the last character, 61, contains the
  290.                                ' null terminator, CHR$(0)
  291.  USERS_DAT_Close               ' Close USERS.DAT File.
  292.  
  293.  
  294.   ' Now, lets trim off the excess spaces and the null terminator.
  295.   ' First I will create a new variable to hold the new data.
  296.  
  297.   DIM Temp AS STRING         ' Dimention a new variable
  298.  
  299.  USERS_DAT_Open              ' Open USERS.DAT File
  300.  USERS_DAT_Read 1            ' Read in Record #1
  301.  
  302.    ' This line below preforms the trim operation
  303.   Temp = RTRIM$(USERSDAT.UserName, ANY " " + CHR$(0))
  304.  
  305.   PRINT Temp                 ' Prints the new string without the extra spaces
  306.                              ' and CHR$(0)
  307.   PRINT LEN(Temp)            ' Prints the True Length of the User's Name
  308.  
  309.  USERS_DAT_Close             ' Closes USERS.DAT File
  310.  
  311. $ENDIF
  312. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  313.  
  314. END                          ' Ends the Program
  315.