home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_refer / vb_pxen / vbpxeng.txt < prev    next >
Text File  |  1992-01-03  |  30KB  |  736 lines

  1. 'I am placing this code and documentation in the public 
  2. 'domain in the hopes that others may find it useful. You are 
  3. 'free to use, modify and distribute it as you see fit. This 
  4. 'code is provided on an as-is basis; I have tested much of it 
  5. 'but it is not guaranteed to be bug-free. If you find errors 
  6. 'or have suggestions for improvement, you can send them to me 
  7. 'if you'd like. 
  8. 'Sharon F. Dooley
  9. 'January 2, 1992
  10. 'CompuServe ID 70740,2330
  11. 'PAL and PARADOX are trademarks of Borland.  Visual Basic is 
  12. 'a trademark of Microsoft.
  13.  
  14. ' Declare a TRUE and FALSE in case they didn't do it in their global
  15.  Const TRUE = -1
  16.  Const FALSE = 0
  17. ' Constants used in this module only
  18. ' Paradox uses 1 for true
  19.  Const PXTRUE = 1
  20. ' Paradox blank values
  21.  Const PXBLANKDATE = &H80000000
  22.  Const PXBLANKLONG = &H80000000
  23.  Const PXBLANKSHORT = &H8000
  24. '   Paradox Engine Function Declarations
  25.  
  26. '   INITIALIZATION AND FINALIZATION FUNCTIONS
  27.  
  28.                     
  29. Declare Function PXWinInit Lib "pxengwin.dll" (ByVal ClientName$, ByVal ShareMode%) As Integer
  30. Declare Function PXNetInit Lib "pxengwin.dll" (ByVal netNamePath$, ByVal netType%, ByVal UserName$) As Integer
  31. Declare Function PXExit Lib "pxengwin.dll" () As Integer
  32. Declare Function PXSetDefaults Lib "pxengwin.dll" (ByVal bufSize%, ByVal maxTables%, ByVal maxRecBufs%, ByVal maxLocks%, ByVal maxFiles%, ByVal sortOrder%) As Integer
  33. Declare Function PXGetDefaults Lib "pxengwin.dll" (swapSize%, maxTables%, maxRecBufs%, maxLocks%, maxFiles%, ByVal sortOrder$) As Integer
  34.  
  35.  
  36. '   UTILITY FUNCTIONS
  37. Declare Function ISBLANKDOUBLE Lib "pxengwin.dll" (ByVal X#) As Integer
  38. Declare Function BLANKDOUBLE Lib "pxengwin.dll" (X#) As Integer
  39.  
  40. '   TABLE FUNCTIONS
  41. Declare Function PXTblOpen Lib "pxengwin.dll" (ByVal tblName$, ptblHandle%, ByVal indexId%, ByVal saveEveryChange%) As Integer
  42. Declare Function PXTblClose Lib "pxengwin.dll" (ByVal tblHandle%) As Integer
  43. 'NOTE: VB does not easily handle the arrays of pointers to char required by
  44. 'this routine.  See the information in the readme about how to use this
  45. 'routine from VB
  46. Declare Function PXTblCreate Lib "pxengwin.dll" (ByVal tblName$, ByVal nFields%, fieldptrs As Long, typeptrs As Long) As Integer
  47. Declare Function PXTblEmpty Lib "pxengwin.dll" (ByVal tblName$) As Integer
  48. Declare Function PXTblDelete Lib "pxengwin.dll" (ByVal tblName$) As Integer
  49. Declare Function PXTblCopy Lib "pxengwin.dll" (ByVal fromName$, ByVal toName$) As Integer
  50. Declare Function PXTblRename Lib "pxengwin.dll" (ByVal fromName$, ByVal toName$) As Integer
  51. Declare Function PXTblAdd Lib "pxengwin.dll" (ByVal srcName$, ByVal destName$) As Integer
  52.  
  53.  
  54. '   RECORD FUNCTIONS
  55.  
  56. Declare Function PXRecAppend Lib "pxengwin.dll" (ByVal tblHandle%, ByVal recHandle%) As Integer
  57. Declare Function PXRecInsert Lib "pxengwin.dll" (ByVal tblHandle%, ByVal recHandle%) As Integer
  58. Declare Function PXRecUpdate Lib "pxengwin.dll" (ByVal tblHandle%, ByVal recHandle%) As Integer
  59. Declare Function PXRecDelete Lib "pxengwin.dll" (ByVal tblHandle%) As Integer
  60. Declare Function PXRecBufOpen Lib "pxengwin.dll" (ByVal tblHandle%, recHandle%) As Integer
  61. Declare Function PXRecBufClose Lib "pxengwin.dll" (ByVal recHandle%) As Integer
  62. Declare Function PxRecBufEmpty Lib "pxengwin.dll" (ByVal recHandle%) As Integer
  63. Declare Function PXRecBufCopy Lib "pxengwin.dll" (ByVal fromHandle%, ByVal toHandle%) As Integer
  64. Declare Function PXRecGet Lib "pxengwin.dll" (ByVal tblHandle%, ByVal recHandle%) As Integer
  65.  
  66. '   FIELD FUNCTIONS
  67.  
  68. Declare Function PXPutShort Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, ByVal Value%) As Integer
  69. Declare Function PXPutDoub Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, ByVal Value#) As Integer
  70. Declare Function PXPutLong Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, ByVal Value&) As Integer
  71. Declare Function PXPutAlpha Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, ByVal Value$) As Integer
  72. Declare Function PXPutDate Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, ByVal Value&) As Integer
  73. Declare Function PXPutBlank Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%) As Integer
  74. Declare Function PXGetShort Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, Svalue%) As Integer
  75. Declare Function PXGetDoub Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, Dvalue#) As Integer
  76. Declare Function PXGetLong Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, Lvalue&) As Integer
  77. Declare Function PXGetAlpha Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, ByVal bufSize%, ByVal dest$) As Integer
  78. Declare Function PXGetDate Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, pvalue&) As Integer
  79. Declare Function PXFldBlank Lib "pxengwin.dll" (ByVal recHandle%, ByVal fldHandle%, Blank%) As Integer
  80.  
  81.  
  82. '  NAVIGATION FUNCTIONS
  83.  
  84. Declare Function PXRecGoto Lib "pxengwin.dll" (ByVal tblHandle%, ByVal recnum&) As Integer
  85. Declare Function PxRecFirst Lib "pxengwin.dll" (ByVal tblHandle%) As Integer
  86. Declare Function PXRecLast Lib "pxengwin.dll" (ByVal tblHandle%) As Integer
  87. Declare Function PXRecNext Lib "pxengwin.dll" (ByVal tblHandle%) As Integer
  88. Declare Function PXRecPrev Lib "pxengwin.dll" (ByVal tblHandle%) As Integer
  89.  
  90.  
  91. '   INDEX FUNCTIONS
  92.  
  93.                  '   PRIMARY/SECONDARY/INCSECONDARY
  94. Declare Function PXKeyAdd Lib "pxengwin.dll" (ByVal tblName$, ByVal nflds%, ByVal fldHandle%, ByVal Mode%) As Integer
  95. Declare Function PXKeyDrop Lib "pxengwin.dll" (ByVal tblName$, ByVal indexId%) As Integer
  96.  
  97. '   DATE FUNCTIONS
  98.  
  99. Declare Function PXDateDecode Lib "pxengwin.dll" (ByVal dateval&, Mo%, da%, Yr%) As Integer
  100. Declare Function PXDateEncode Lib "pxengwin.dll" (ByVal Mo%, ByVal da%, ByVal Yr%, pdate&) As Integer
  101.  
  102. '   SEARCH FUNCTIONS
  103. Declare Function PXSrchKey Lib "pxengwin.dll" (ByVal tblHandle%, ByVal recHandle%, ByVal nflds%, ByVal Mode%) As Integer
  104. Declare Function PXSrchFld Lib "pxengwin.dll" (ByVal tblHandle%, ByVal recHandle%, ByVal fldHandle%, ByVal Mode%) As Integer
  105.  
  106. '   PASSWORD FUNCTIONS
  107. Declare Function PXTblProtected Lib "pxengwin.dll" (ByVal tblName$, Protected%) As Integer
  108. Declare Function PXPswAdd Lib "pxengwin.dll" (ByVal Password$) As Integer
  109. Declare Function PXPswDel Lib "pxengwin.dll" (ByVal Password$) As Integer
  110. Declare Function PXTblEncrypt Lib "pxengwin.dll" (ByVal tblName$, ByVal Password$) As Integer
  111. Declare Function PXTblDecrypt Lib "pxengwin.dll" (ByVal tblName$) As Integer
  112.  
  113. '   INFORMATIONAL FUNCTIONS
  114.  
  115. Declare Function PXTblExist Lib "pxengwin.dll" (ByVal tblName$, Exist%) As Integer
  116. Declare Function PXTblName Lib "pxengwin.dll" (ByVal tblHandle%, ByVal bufSize%, ByVal tblName$) As Integer
  117. Declare Function PXRecNum Lib "pxengwin.dll" (ByVal tblHandle%, recnum&) As Integer
  118. Declare Function PXTblNRecs Lib "pxengwin.dll" (ByVal tblHandle%, NRecs&) As Integer
  119. Declare Function PXRecNFlds Lib "pxengwin.dll" (ByVal tblHandle%, nflds%) As Integer
  120. Declare Function PXKeyNFlds Lib "pxengwin.dll" (ByVal tblHandle%, nKeyFlds%) As Integer
  121. Declare Function PXFldHandle Lib "pxengwin.dll" (ByVal tblHandle%, ByVal fieldName$, fldHandle%) As Integer
  122. Declare Function PXFldType Lib "pxengwin.dll" (ByVal tblHandle%, ByVal fldHandle%, ByVal bufSize%, ByVal fldType$) As Integer
  123. Declare Function PXFldName Lib "pxengwin.dll" (ByVal tblHandle%, ByVal fldHandle%, ByVal bufSize%, ByVal fldName$) As Integer
  124.  
  125.  
  126. '   MISCELLANEOUS FUNCTIONS
  127. Declare Function PXTblMaxSize Lib "pxengwin.dll" (ByVal maxsize%) As Integer
  128. Declare Function PXSave Lib "pxengwin.dll" () As Integer
  129.  
  130. '   CONCURRENCY FUNCTIONS
  131. '   can be used only if PXNetInit() or PXWinInit() was successful
  132.  
  133. Declare Function PXNetUserName Lib "pxengwin.dll" (ByVal bufSize%, ByVal UserName$) As Integer
  134. Declare Function PXNetFileLock Lib "pxengwin.dll" (ByVal fileName$, ByVal lockType%) As Integer
  135. Declare Function PXNetFileUnlock Lib "pxengwin.dll" (ByVal fileName$, ByVal lockType%) As Integer
  136. Declare Function PXNetTblLock Lib "pxengwin.dll" (ByVal tblHandle%, ByVal lockType%) As Integer
  137. Declare Function PXNetTblUnlock Lib "pxengwin.dll" (ByVal tblHandle%, ByVal lockType%) As Integer
  138. Declare Function PXNetRecLock Lib "pxengwin.dll" (ByVal tblHandle%, lckHandle%) As Integer
  139. Declare Function PXNetRecUnlock Lib "pxengwin.dll" (ByVal tblHandle%, ByVal lckHandle%) As Integer
  140. Declare Function PXNetRecLocked Lib "pxengwin.dll" (ByVal tblHandle%, Locked%) As Integer
  141. Declare Function PXNetRecGotoLock Lib "pxengwin.dll" (ByVal tblHandle%, ByVal lckHandle%) As Integer
  142. Declare Function PXNetTblChanged Lib "pxengwin.dll" (ByVal tblHandle%, Changed%) As Integer
  143. Declare Function PXNetTblRefresh Lib "pxengwin.dll" (ByVal tblHandle%) As Integer
  144.  
  145.  
  146. '   ERROR FUNCTIONS
  147. Declare Function PXErrMsg Lib "pxengwin.dll" (ByVal errcode%) As Long
  148. Declare Function PXNetErrUser Lib "pxengwin.dll" (ByVal bufSize%, ByVal UserName$) As Integer
  149. '********************************************************************************************
  150.  
  151.  
  152. '*************************************************************************************
  153. ' Windows API Declarations for API functions used in the interface
  154. Declare Function lstrcpy Lib "Kernel" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
  155.  
  156. 'The following declaration is modified from the declaration provided in
  157. ' WINAPI.TXT so that it can be used to trick VB into building the
  158. ' arrays of pointers required by PXTblCreate. It normally returns String
  159. ' Hence the Alias
  160. Declare Function PXAnsiUpper Lib "User" Alias "AnsiUpper" (ByVal lpString As String) As Long
  161.  
  162.  
  163. '**************************************************************************************
  164. ' VB-Paradox Interface Layer.  This section contains the VB routines that
  165. ' invoke the actual Paradox Engine DLL.  This interface layer serves to
  166. ' mask some of the nitty-gritty details like Paradox data types from the
  167. ' VB programmer.  Note that VB.... routines return VB values for TRUE and
  168. ' FALSE, not Paradox values.
  169.  
  170. Sub BLANKSHORT (X As Integer)
  171.     X = PXBLANKSHORT
  172. End Sub
  173.  
  174. Sub BLANKDATE (X As Double)
  175.     X = VBPXBLANKDATE
  176. End Sub
  177.  
  178. Sub BLANKLONG (X As Long)
  179.     X = PXBLANKLONG
  180. End Sub
  181.  
  182. Function VBISBLANKSHORT (X As Integer) As Integer
  183.     If X = PXISBLANKSHORT Then
  184.     VBISBLANKSHORT = TRUE
  185.     Else
  186.     VBISBLANKSHORT = FALSE
  187.     End If
  188.  
  189. End Function
  190.  
  191. Function VBISBLANKLONG (X As Long) As Integer
  192.     If X = PXBLANKLONG Then
  193.     VBISBLANKLONG = TRUE
  194.     Else
  195.     VBISBLANKLONG = FALSE
  196.     End If
  197. End Function
  198.  
  199. Function VBISBLANKDOUBLE (X As Double) As Integer
  200.     If ISBLANKDOUBLE(X) = PXTRUE Then
  201.     VBISBLANKDOUBLE = TRUE
  202.     Else
  203.     VBISBLANKDOUBLE = FALSE
  204.     End If
  205. End Function
  206.  
  207. Function VBISBLANKDATE (X As Double) As Integer
  208.     If X = VBPXBLANKDATE Then
  209.     VBISBLANKDATE = TRUE
  210.     Else
  211.     VBISBLANKDATE = FALSE
  212.     End If
  213. End Function
  214.  
  215. Function VBPXERRMSG (errcode As Integer) As String
  216. ' Returns the text for a Paradox Error code
  217.     Dim Dummy As Long
  218.     Dim MsgPtr As Long
  219.     ErrMsg$ = String$(255, 0)
  220.     MsgPtr = PXErrMsg(errcode)
  221.     Dummy = lstrcpy(ErrMsg$, MsgPtr)
  222.     Dummy = InStr(ErrMsg$, Chr$(0))
  223.     VBPXERRMSG = Left$(ErrMsg$, Dummy)
  224. End Function
  225.  
  226. Function VBPXExit ()
  227.     VBPXExit = PXExit()
  228. End Function
  229.  
  230. Function VBPXFldBlank (Record As RECORDHANDLE, Field As FIELDHANDLE) As Integer
  231. 'returns TRUE (-1) if field is blank, 0 if field is not blank, error code otherwise
  232.     Dim Result As Integer
  233.     Dim Status As Integer
  234.     Status = PXFldBlank(Record.rHandle, Field.fHandle, Result)
  235.     If Status = PXSUCCESS Then
  236.        If Result = PXTRUE Then
  237.     VBPXFldBlank = TRUE
  238.        Else
  239.     VBPXFldBlank = FALSE
  240.        End If
  241.     Else
  242.        Status = showPDOXError(Status)
  243.     End If
  244. End Function
  245.  
  246. Function VBPXFldHandle (table As TABLEHANDLE, fldName As String, Field As FIELDHANDLE) As Integer
  247.     VBPXFldHandle = PXFldHandle(table.thandle, fldName, Field.fHandle)
  248. End Function
  249.  
  250. Function VBPXFldName (table As TABLEHANDLE, Field As FIELDHANDLE, fldName As String) As Integer
  251.     fldName = String$(FldNameLen + 1, 0)
  252.     VBPXFldName = PXFldName(table.thandle, Field.fHandle, FldNameLen, fldName)
  253. End Function
  254.  
  255. Function showPDOXError (errcode As Integer) As Integer
  256.     showPDOXError = MsgBox(VBPXERRMSG(errcode), MB_ICONSTOP, "Paradox Error")
  257.     Stop
  258.     Status = VBPXExit()
  259.     End
  260. End Function
  261.  
  262. Function VBPXFldType (table As TABLEHANDLE, Field As FIELDHANDLE, fldType As String) As Integer
  263.     fldType = String$(fldTypeLen + 1, 0)
  264.     VBPXFldType = PXFldType(table.thandle, Field.fHandle, fldTypeLen, fldType)
  265. End Function
  266.  
  267. Function VBPXGetAlpha (Record As RECORDHANDLE, Field As FIELDHANDLE, dest As String) As Integer
  268.     Dim Status As Integer
  269.     Dim WorkLen As Integer
  270.     Dim WorkStr As String
  271.     Dim NullPos As Integer
  272.     WorkLen = Len(dest) + 1
  273.     WorkStr = String$(WorkLen, 0)
  274.     Status = PXGetAlpha(Record.rHandle, Field.fHandle, WorkLen, WorkStr)
  275.     If Status = PXSUCCESS Then
  276. '       Find the first null and truncate the string from
  277. '       there on
  278.     NullPos = InStr(1, WorkStr, Chr$(0))
  279.  
  280.     dest = Mid$(WorkStr, 1, NullPos - 1)
  281.     End If
  282.     VBPXGetAlpha = Status
  283. End Function
  284.  
  285. Function VBPXGetDefaults (swapSize As Integer, maxTables As Integer, maxRecBufs As Integer, maxLocks As Integer, maxFiles As Integer, sortOrder As String) As Integer
  286.     VBPXGetDefaults = PXGetDefaults(swapSize, maxTables, maxRecBufs, maxLocks, maxFiles, sortOrder)
  287. End Function
  288.  
  289. Function VBPXGetDoub (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Double) As Integer
  290.     VBPXGetDoub = PXGetDoub(Record.rHandle, Field.fHandle, Value)
  291. End Function
  292.  
  293. Function VBPXGetLong (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Long) As Integer
  294.     VBPXGetLong = PXGetLong(Record.rHandle, Field.fHandle, Value)
  295. End Function
  296.  
  297. Function VBPXGetShort (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Integer) As Integer
  298.     VBPXGetShort = PXGetShort(Record.rHandle, Field.fHandle, Value)
  299. End Function
  300.  
  301. Function VBPXKeyDrop (tblName As String, indexId As Integer) As Integer
  302.     VBPXKeyDrop = PXKeyDrop(tblName, indexId)
  303. End Function
  304.  
  305. Function VBPXKeyNFlds (table As TABLEHANDLE, nKeyFlds As Integer) As Integer
  306.     VBPXKeyNFlds = PXKeyNFlds(table.thandle, nKeyFlds)
  307. End Function
  308.  
  309. Function VBPXNetErrUser (UserName As String) As Integer
  310. Dim WorkName As String
  311. Dim Status As Integer
  312. Dim NullPos As Integer
  313. WorkLen = UserNetNameLen + 1
  314. WorkName = String$(WorkLen, 0)
  315. Status = PXNetErrUser(WorkLen, WorkName)
  316. If Status = PXSUCCESS Then
  317. '       trim the null terminator
  318.     NullPos = InStr(1, WorkName, Chr$(0))
  319.     UserName = Mid$(WorkName, 1, NullPos - 1)
  320. End If
  321. VBPXNetErrUser = Status
  322. End Function
  323.  
  324. Function VBPXWinInit (ClientName As String, ShareMode As Integer) As Integer
  325.     VBPXWinInit = PXWinInit(ClientName, ShareMode)
  326. End Function
  327.  
  328. Function VBPXNetFileLock (fileName As String, lockType As Integer) As Integer
  329.     VBPXNetFileLock = PXNetFileLock(fileName, lockType)
  330. End Function
  331.  
  332. Function VBPXNetFileUnlock (fileName As String, lockType As Integer) As Integer
  333.     VBPXNetFileUnlock = PXNetFileUnlock(fileName, lockType)
  334. End Function
  335.  
  336. Function VBPXNetInit (netNamePath As String, netType As Integer, UserName As String) As Integer
  337.     VBPXNetInit = PXNetInit(netNamePath, netType, UserName)
  338. End Function
  339.  
  340. Function VBPXNetRecGotoLock (table As TABLEHANDLE, PXlock As LOCKHANDLE) As Integer
  341.     VBPXNetRecGotoLock = PXNetRecGotoLock(table.thandle, PXlock.lhandle)
  342. End Function
  343.  
  344. Function VBPXNetRecLock (table As TABLEHANDLE, PXlock As LOCKHANDLE) As Integer
  345.     VBPXNetRecLock = PXNetRecLock(table.thandle, PXlock.lhandle)
  346. End Function
  347.  
  348. Function VBPXNetRecUnlock (table As TABLEHANDLE, PXlock As LOCKHANDLE) As Integer
  349.     VBPXNetRecUnlock = PXNetRecUnlock(table.thandle, PXlock.lhandle)
  350. End Function
  351.  
  352. Function VBPXNetRecLocked (table As TABLEHANDLE) As Integer
  353. 'returns TRUE (-1) if the current record of table is locked
  354.     Dim Result As Integer
  355.     Dim Status As Integer
  356.     Status = PXNetRecLocked(table.thandle, Result)
  357.     If Status = PXSUCCESS Then
  358.        If Result = PXTRUE Then
  359.     VBPXNetRecLocked = TRUE
  360.        Else
  361.     VBPXNetRecLocked = FALSE
  362.        End If
  363.     Else
  364.        Status = showPDOXError(Status)
  365.     End If
  366. End Function
  367.  
  368. Function VBPXNetTblChanged (table As TABLEHANDLE) As Integer
  369. 'returns TRUE (-1) if table has changed
  370.     Dim Result As Integer
  371.     Dim Status As Integer
  372.     Status = PXNetTblChanged(table.thandle, Result)
  373.     If Status = PXSUCCESS Then
  374.        If Result = PXTRUE Then
  375.     VBPXNetTblChanged = TRUE
  376.        Else
  377.     VBPXNetTblChanged = FALSE
  378.        End If
  379.     Else
  380.        Status = showPDOXError(Status)
  381.     End If
  382. End Function
  383.  
  384. Function VBPXNetTblLock (table As TABLEHANDLE, lockType As Integer) As Integer
  385.     VBPXNetTblLock = PXNetTblLock(table.thandle, lockType)
  386. End Function
  387.  
  388. Function VBPXNetTblRefresh (table As TABLEHANDLE) As Integer
  389.     VBPXNetTblRefresh = PXNetTblRefresh(table.thandle)
  390. End Function
  391.  
  392. Function VBPXNetTblUnlock (table As TABLEHANDLE, lockType As Integer) As Integer
  393.     VBPXNetTblUnlock = PXNetTblUnlock(table.thandle, lockType)
  394. End Function
  395.  
  396. Function VBPXNetUserName (UserName As String) As Integer
  397. Dim WorkName As String
  398. Dim Status As Integer
  399. Dim NullPos As Integer
  400. WorkLen = UserNetNameLen + 1
  401. WorkName = String$(WorkLen, 0)
  402. Status = PXNetUserName(WorkLen, WorkName)
  403. If Status = PXSUCCESS Then
  404. '       trim the null terminator
  405.     NullPos = InStr(1, WorkName, Chr$(0))
  406.     UserName = Mid$(WorkName, 1, NullPos - 1)
  407. End If
  408. VBPXNetUserName = Status
  409. End Function
  410.  
  411. Function VBPXPswAdd (Password As String) As Integer
  412.     VBPXPswAdd = PXPswAdd(Password)
  413. End Function
  414.  
  415. Function VBPXPswDel (Password As String) As Integer
  416.     VBPXPswDel = PXPswDel(Password)
  417. End Function
  418.  
  419. Function VBPXPutAlpha (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As String) As Integer
  420.     VBPXPutAlpha = PXPutAlpha(Record.rHandle, Field.fHandle, Value)
  421. End Function
  422.  
  423. Function VBPXPutBlank (Record As RECORDHANDLE, Field As FIELDHANDLE) As Integer
  424.     VBPXPutBlank = PXPutBlank(Record.rHandle, Field.fHandle)
  425. End Function
  426.  
  427. Function VBPXPutDoub (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Double) As Integer
  428.     VBPXPutDoub = PXPutDoub(Record.rHandle, Field.fHandle, Value)
  429. End Function
  430.  
  431. Function VBPXPutLong (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Long) As Integer
  432.     VBPXPutLong = PXPutLong(Record.rHandle, Field.fHandle, Value)
  433. End Function
  434.  
  435. Function VBPXPutShort (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Integer) As Integer
  436.     VBPXPutShort = PXPutShort(Record.rHandle, Field.fHandle, Value)
  437. End Function
  438.  
  439. Function VBPXRecAppend (table As TABLEHANDLE, Record As RECORDHANDLE) As Integer
  440.     VBPXRecAppend = PXRecAppend(table.thandle, Record.rHandle)
  441. End Function
  442.  
  443. Function VBPXRecBufClose (Record As RECORDHANDLE) As Integer
  444.     VBPXRecBufClose = PXRecBufClose(Record.rHandle)
  445. End Function
  446.  
  447. Function VBPXRecBufCopy (SrcRecord As RECORDHANDLE, DestRecord As RECORDHANDLE) As Integer
  448.     VBPXRecBufCopy = PXRecBufCopy(SrcRecord.rHandle, DestRecord.rHandle)
  449. End Function
  450.  
  451. Function VBPXRecBufEmpty (Record As RECORDHANDLE) As Integer
  452.     VBPXRecBufEmpty = PxRecBufEmpty(Record.rHandle)
  453. End Function
  454.  
  455. Function VBPXRecBufOpen (table As TABLEHANDLE, Record As RECORDHANDLE) As Integer
  456.     VBPXRecBufOpen = PXRecBufOpen(table.thandle, Record.rHandle)
  457. End Function
  458.  
  459. Function VBPXRecDelete (table As TABLEHANDLE) As Integer
  460.     VBPXRecDelete = PXRecDelete(table.thandle)
  461. End Function
  462.  
  463. Function VBPXRecFirst (table As TABLEHANDLE) As Integer
  464.     VBPXRecFirst = PxRecFirst(table.thandle)
  465. End Function
  466.  
  467. Function VBPXRecGet (table As TABLEHANDLE, Record As RECORDHANDLE) As Integer
  468.     VBPXRecGet = PXRecGet(table.thandle, Record.rHandle)
  469. End Function
  470.  
  471. Function VBPXRecGoto (table As TABLEHANDLE, Record As RECORDHANDLE) As Integer
  472.     VBPXRecGoto = PXRecGoto(table.thandle, Record.rHandle)
  473. End Function
  474.  
  475. Function VBPXRecInsert (table As TABLEHANDLE, Record As RECORDHANDLE) As Integer
  476.     VBPXRecInsert = PXRecInsert(table.thandle, Record.rHandle)
  477. End Function
  478.  
  479. Function VBPXRecLast (table As TABLEHANDLE) As Integer
  480.     VBPXRecLast = PXRecLast(table.thandle)
  481. End Function
  482.  
  483. Function VBPXRecNext (table As TABLEHANDLE) As Integer
  484.     VBPXRecNext = PXRecNext(table.thandle)
  485. End Function
  486.  
  487. Function VBPXRecNFlds (table As TABLEHANDLE, nflds As Integer) As Integer
  488.     VBPXRecNFlds = PXRecNFlds(table.thandle, nflds)
  489. End Function
  490.  
  491. Function VBPXRecNum (table As TABLEHANDLE, RNum As RECORDNUMBER) As Integer
  492.     VBPXRecNum = PXRecNum(table.thandle, RNum.recnum)
  493. End Function
  494.  
  495. Function VBPXRecPrev (table As TABLEHANDLE) As Integer
  496.     VBPXRecPrev = PXRecPrev(table.thandle)
  497. End Function
  498.  
  499. Function VBPXSave () As Integer
  500.     VBPXSave = PXSave()
  501. End Function
  502.  
  503. Function VBPXSetDefaults (bufSize As Integer, maxTables As Integer, maxRecBufs As Integer, maxLocks As Integer, maxFiles As Integer, sortOrder As String) As Integer
  504.     Dim PXSORT As Integer
  505. '       The engine wants a C single character, not a string for the sort order
  506. '       VB doesn't know from single characters.  So put its ascii code in an int, and
  507. '       the engine will be happy and so will VB
  508.     PXSORT = Asc(sortOrder)
  509.     VBPXSetDefaults = PXSetDefaults(bufSize, maxTables, maxRecBufs, maxLocks, maxFiles, PXSORT)
  510. End Function
  511.  
  512. Function VBPXSrchFld (table As TABLEHANDLE, Record As RECORDHANDLE, Field As FIELDHANDLE, SearchMode As Integer) As Integer
  513.     VBPXSrchFld = PXSrchFld(table.thandle, Record.rHandle, Field.fHandle, SearchType)
  514. End Function
  515.  
  516. Function VBPXSrchKey (table As TABLEHANDLE, Record As RECORDHANDLE, nflds As Integer, SearchMode As Integer) As Integer
  517.     VBPXSrchKey = PXSrchKey(table.thandle, Record.rHandle, nflds, SearchMode)
  518. End Function
  519.  
  520. Function VBPXTblAdd (srcTableName As String, destTableName As String) As Integer
  521.     VBPXTblAdd = PXTblAdd(srcTableName, destTableName)
  522. End Function
  523.  
  524. Function VBPXTblClose (table As TABLEHANDLE) As Integer
  525.     VBPXTblClose = PXTblClose(table.thandle)
  526. End Function
  527.  
  528. Function VBPXTblCopy (srcTableName As String, destTableName As String) As Integer
  529.     VBPXTblCopy = PXTblCopy(srcTableName, destTableName)
  530. End Function
  531.  
  532. Function VBPXTblCreate (TableName As String, NumFields As Integer, Fields() As String, Types() As String) As Integer
  533. ' This function uses a technique provided by Jim Nech of OutRider Systems.
  534. ' This was posted on Compuserve last Fall ('91)
  535. '
  536. ' I needed a way to use The Paradox Engine to create Paradox tables in
  537. ' VB. At  first this seemed impossible because VB doesn't provide for
  538. ' arrays of  pointers to strings. The solution is to use arrays of
  539. ' longs. The problem  with this is that basic will not allow conversion
  540. ' of one type to another.   This had me stumped because I could not get
  541. ' the address of a string into  the elements of an array of longs. The
  542. ' solution was to make a Windows API  call that accepts a pointer to a
  543. ' string, and a return value that is also a  pointer to that same
  544. ' string. When you declare the function within VB you  have to LIE to
  545. ' VB about its return value. Instead of declaring it as  returning a
  546. ' string value you declare it as returning a long. This is not  a
  547. ' problem since they are both the same size. You can now assign the
  548. ' returned  long value to an element of an array of longs and VB will
  549. ' not complain.   When you call the PXTblCreate function you can pass
  550. ' the array to it. Since  arrays are passed by reference you end up
  551. ' passing a pointer to an array  of pointers to strings.
  552. '
  553.  
  554. ' Jim Nech
  555. ' OutRider Systems  -   (Producers of Custom Controls for Visual Basic)
  556. ' 3701 Kirby DR. STE. 1196
  557. ' Houston, TX 77098
  558. ' Voice:(713)521-0486    Fax:(713)523-0386
  559.  
  560.     ReDim PXFieldPtrs(NumFields) As Long
  561.     ReDim PXTypePtrs(NumFields) As Long
  562.     Dim i As Integer
  563.  
  564.     For i = 0 To NumFields - 1 Step 1
  565.     '   Make the field and type null terminated
  566.     Fields(i) = Fields(i) + Chr$(0)
  567.     Types(i) = Types(i) + Chr$(0)
  568. '               Asssign the addresses of the field names and the field
  569. '               types to the field and type arrays
  570.     PXFieldPtrs(i) = PXAnsiUpper(Fields(i))
  571.     PXTypePtrs(i) = PXAnsiUpper(Types(i))
  572.     Next
  573.     VBPXTblCreate = PXTblCreate(TableName, NumFields, PXFieldPtrs(0), PXTypePtrs(0))
  574. End Function
  575.  
  576. Function VBPXTblDecrypt (TableName As String) As Integer
  577.     VBPXTblDecrypt = PXTblDecrypt(TableName)
  578. End Function
  579.  
  580. Function VBPXTblDelete (TableName As String) As Integer
  581.     VBPXTblDelete = PXTblDelete(TableName)
  582. End Function
  583.  
  584. Function VBPXTblEmpty (TableName As String) As Integer
  585.     VBPXTblEmpty = PXTblEmpty(TableName)
  586. End Function
  587.  
  588. Function VBPXTblEncrypt (TableName As String, Password As String) As Integer
  589.     VBPXTblEncrypt = PXTblEncrypt(TableName, Password)
  590. End Function
  591.  
  592. Function VBPXTblExist (TableName As String) As Integer
  593.     Dim Result As Integer
  594.     Dim Status As Integer
  595.     Status = PXTblExist(TableName, Result)
  596.     If Status = PXSUCCESS Then
  597.     If Result = PXTRUE Then
  598.         VBPXTblExist = TRUE
  599.     Else
  600.         VBPXTblExist = FALSE
  601.     End If
  602.     Else
  603.     Status = showPDOXError(Status)
  604.     End If
  605. End Function
  606.  
  607. Function VBPXTblMaxSize (maxTblSize As Integer) As Integer
  608.     VBPXTblMaxSize = PXTblMaxSize(maxTblSize)
  609. End Function
  610.  
  611. Function VBPXTblName (table As TABLEHANDLE, TableName As String) As Integer
  612.     Dim NullPos As Integer
  613.     Dim WorkName As String
  614.     Dim Status As Integer
  615.     WorkName = String$(TblNameLen + 1, 0)
  616.     Status = PXTblName(table.thandle, TblNameLen + 1, WorkName)
  617.     If Status = PXSUCCESS Then
  618.         NullPos = InStr(WorkName, Chr$(0))
  619.         TableName = Mid$(WorkName, 1, NullPos - 1)
  620.     End If
  621.     VBPXTblName = Status
  622. End Function
  623.  
  624. Function VBPXTblNRecs (table As TABLEHANDLE, NRecs As RECORDNUMBER) As Integer
  625.     VBPXTblNRecs = PXTblNRecs(table.thandle, NRecs.recnum)
  626. End Function
  627.  
  628. Function VBPXTblOpen (TableName As String, table As TABLEHANDLE, indexId As Integer, saveEveryChange As Integer) As Integer
  629.     VBPXTblOpen = PXTblOpen(TableName, table.thandle, indexId, saveEveryChange)
  630. End Function
  631.  
  632. Function VBPXTblProtected (TableName As String) As Integer
  633.     Dim Result As Integer
  634.     Dim Status As Integer
  635.     Status = PXTblProtected(TableName, Result)
  636.     If Status = PXSUCCESS Then
  637.     If Result = PXTRUE Then
  638.         VBPXTblProtected = TRUE
  639.     Else
  640.         VBPXTblProtected = FALSE
  641.     End If
  642.     Else
  643.     Status = showPDOXError(Status)
  644.     End If
  645. End Function
  646.  
  647. Function VBPXTblRename (srcTableName As String, destTableName As String) As Integer
  648.     VBPXTblRename = PXTblRename(srcTableName, destTableName)
  649. End Function
  650.  
  651. Function VBPXGetDate (Record As RECORDHANDLE, Field As FIELDHANDLE, dateval As Double)
  652. 'VB Dates are Double Serial numbers; Paradox dates are some bizzare internal format
  653. ' Manage the conversion from PDOX to VB here.  See also VBPXPutDate
  654.     Dim pxdate As Long
  655.     Dim Mo As Integer
  656.     Dim Dy As Integer
  657.     Dim Yr As Integer
  658.     Dim Status As Integer
  659. '   See if we have a blank date
  660.     If VBPXFldBlank(Record, Field) Then
  661.     dateval = VBPXBLANKDATE
  662.     VBPXGetDate = PX_SUCCESS
  663.     Else
  664. '        Have a non-blank, get the value
  665.     Status = PXGetDate(Record.rHandle, Field.fHandle, pxdate)
  666.     If Status = PXSUCCESS Then
  667. '               now, get the mo, day & year out of it
  668.         Status = PXDateDecode(pxdate, Mo, Dy, Yr)
  669.         If Status = PXSUCCESS Then
  670. '                       turn it into a VB date
  671.         dateval = DateSerial(Yr, Mo, Dy)
  672.         End If
  673.     End If
  674.     VBPXGetDate = Status
  675.     End If
  676.  
  677. End Function
  678.  
  679. Function VBPXPutDate (Record As RECORDHANDLE, Field As FIELDHANDLE, dateval As Double) As Integer
  680.     Dim pxdate As Long
  681.     Dim Mo As Integer
  682.     Dim Dy As Integer
  683.     Dim Yr As Integer
  684.     Dim Status As Integer
  685.     If dateval = VBPXBLANKDATE Then
  686.     Status = PXPutBlank(Record.rHandle, Field.fHandle)
  687.     If Status <> PXSUCCESS Then
  688.         Status = showPDOXError(Status)
  689.     End If
  690.     Else
  691. '       have valid date
  692. '       now, decompose the VB date into mo, day, yr
  693.     Dy = Day(dateval)
  694.     Mo = Month(dateval)
  695.     Yr = Year(dateval)
  696. '       Now let paradox encode the date
  697.     Status = PXDateEncode(Mo, Dy, Yr, pxdate)
  698.     If Status = PXSUCCESS Then
  699. '               Now shove the date into the database
  700.         Status = PXPutDate(Record.rHandle, Field.fHandle, pxdate)
  701.     End If
  702.     End If
  703.     VBPXPutDate = Status
  704. End Function
  705.  
  706. Function VBPXKeyAdd (tblName As String, nflds As Integer, Fields() As FIELDHANDLE, IndexType As Integer) As Integer
  707.     VBPXKeyAdd = PXKeyAdd(tblName, nflds, Fields(1).fHandle, IndexType)
  708. End Function
  709.  
  710. Function VBPXRecUpdate (table As TABLEHANDLE, Record As RECORDHANDLE) As Integer
  711.     VBPXRecUpdate = PXRecUpdate(table.thandle, Record.rHandle)
  712. End Function
  713.  
  714. Function VBPXGetCurrency (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Currency) As Integer
  715.     Dim Result As Double
  716.     Dim Status As Integer
  717.     Status = PXGetDoub(Record.rHandle, Field.fHandle, Result)
  718.     If Status <> PXSUCCESS Then
  719.     Status = showPDOXError(Status)
  720.     End If
  721.     Value = Result
  722.     VBPXGetCurrency = Status
  723. End Function
  724.  
  725. Function VBPXPutCurrency (Record As RECORDHANDLE, Field As FIELDHANDLE, Value As Currency) As Integer
  726.     Dim Result As Double
  727.     Dim Status As Integer
  728.     Result = Value
  729.     Status = PXPutDoub(Record.rHandle, Field.fHandle, Result)
  730.     If Status <> PXSUCCESS Then
  731.     Status = showPDOXError(Status)
  732.     End If
  733.     VBPXPutCurrency = Status
  734. End Function
  735.  
  736.