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

  1. ' ─────────────────────────────────────────────────────────────────────────
  2. ' Program Title: Sample Program for TriBBS's NETWORK.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 "netwk" to make calls to the TriBBS API NETWORK.PBU Unit.
  14. ' Also there are some examples showing how to use the NETWORK.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 NETWORK 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 NETWORK.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 NETWORK.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 "NETWORK.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. ' NETWORK.DAT API which are located in the NETWORK.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 NETWORK.DAT Pointer Calls **
  111. '----------------------------------------------------------------------------
  112. $IF 0  ' Change the '0' to '1' to run this example
  113.  
  114. DIM NWN AS STRING   ' Dimention Local Varible to hold the Network Name for
  115.                     ' this example
  116.  
  117.  NETWORK_DAT_Open                 ' Opens NETWORK.DAT
  118.  
  119.   IF NETWORK_DAT_Length <> 0 THEN ' Check and make sure record doesn't have
  120.                                   ' 0 bytes
  121.  
  122.     NETWORK_DAT_Read 1            ' Reads in a record
  123.  
  124.     PRINT "Total Records:" NETWORK_DAT_Length ' Returns and Prints Total
  125.                                               ' Records in NETWORK.DAT
  126.  
  127.     NWN = NETWORK_DAT_GetNWN     ' Returns a 32-bit pointer to the Network
  128.                                  ' Name string
  129.  
  130.     PRINT NWN                    ' Prints the File Area Name
  131.  
  132.     NETWORK_DAT_PutNWN "New Network Name" ' Let's put a new Network Name in
  133.                                           ' for this this Network
  134.  
  135.     PRINT NETWORK_DAT_GetNWN     ' Returns a 32-bit pointer to the Network
  136.                                  ' Name string with the new Network Name.
  137.  
  138.   END IF                         ' End the check network file for records
  139.                                  ' condition
  140.  
  141.  NETWORK_DAT_Close               ' Closes Network.dat file
  142.  
  143. $ENDIF
  144. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145.  
  146. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. '                ** EXAMPLE 2 for NETWORK.DAT Pointer Calls **
  148. '----------------------------------------------------------------------------
  149. $IF 0  ' Change the '0' to '1' to run this example
  150.  
  151. 'Dimention some local variables for this example
  152. DIM NWN                   AS STRING      ' Local Varible to hold the Network
  153.                                          ' Name
  154. DIM NetLength             AS INTEGER     ' Local Varible to hold Record
  155.                                          ' length for Network.dat
  156. DIM x                     AS INTEGER     ' Local Varible for FOR/NEXT Counter
  157.  
  158.  
  159.  NETWORK_DAT_Open                 ' Opens NETWORK.DAT
  160.  
  161.   IF NETWORK_DAT_Length <> 0 THEN ' Check and make sure record doesn't have
  162.                                   ' 0 bytes
  163.  
  164.    NetLength = NETWORK_DAT_Length ' Local varible to hold record for
  165.                                   ' Network.dat
  166.  
  167.    FOR x = 1 TO NetLength         ' Set x for a FOR/NEXT Counter
  168.  
  169.     NETWORK_DAT_Read x            ' Reads in a record
  170.  
  171.     PRINT NETWORK_DAT_GetNWN      ' Returns a 32-bit pointer to the Network
  172.                                   ' Name string with the new Network Name.
  173.  
  174.    NEXT x                         ' Add 1 to x
  175.  
  176.   END IF                          ' End the check network file for records
  177.                                   ' condition
  178.  
  179.  NETWORK_DAT_Close                ' Closes Network.dat file
  180.  
  181. $ENDIF
  182. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183.  
  184.  END                              ' Ends the Program