home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 #6 / Datatid_1999-06.iso / internet / Tango352Promo / P.SQL / PTKPKG.1 / BTRV32VB.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-15  |  14.7 KB  |  421 lines

  1. VERSION 5.00
  2. Begin VB.Form frmBtrv32 
  3.    Caption         =   "Btrieve Visual Basic Sample"
  4.    ClientHeight    =   7425
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   8055
  8.    Icon            =   "btrv32vb.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   7425
  11.    ScaleWidth      =   8055
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.TextBox txtOutput 
  14.       Height          =   495
  15.       Left            =   2520
  16.       TabIndex        =   4
  17.       Top             =   960
  18.       Width           =   4575
  19.    End
  20.    Begin VB.TextBox txtInput 
  21.       Height          =   495
  22.       Left            =   2520
  23.       TabIndex        =   3
  24.       Top             =   240
  25.       Width           =   4575
  26.    End
  27.    Begin VB.CommandButton cmdExit 
  28.       Caption         =   "E&xit"
  29.       Height          =   375
  30.       Left            =   4560
  31.       TabIndex        =   2
  32.       Top             =   6720
  33.       Width           =   1095
  34.    End
  35.    Begin VB.ListBox lstBtrv 
  36.       Height          =   4740
  37.       ItemData        =   "btrv32vb.frx":000C
  38.       Left            =   720
  39.       List            =   "btrv32vb.frx":000E
  40.       TabIndex        =   1
  41.       Top             =   1680
  42.       Width           =   6375
  43.    End
  44.    Begin VB.CommandButton cmdRunTest 
  45.       Caption         =   "&Run Test"
  46.       Height          =   375
  47.       Left            =   2400
  48.       TabIndex        =   0
  49.       Top             =   6720
  50.       Width           =   1095
  51.    End
  52.    Begin VB.Label Label2 
  53.       Caption         =   "Output Path"
  54.       Height          =   255
  55.       Left            =   960
  56.       TabIndex        =   6
  57.       Top             =   1080
  58.       Width           =   1095
  59.    End
  60.    Begin VB.Label Label1 
  61.       Caption         =   "Input Path"
  62.       Height          =   255
  63.       Left            =   960
  64.       TabIndex        =   5
  65.       Top             =   360
  66.       Width           =   1095
  67.    End
  68. Attribute VB_Name = "frmBtrv32"
  69. Attribute VB_GlobalNameSpace = False
  70. Attribute VB_Creatable = False
  71. Attribute VB_PredeclaredId = True
  72. Attribute VB_Exposed = False
  73. '{*************************************************************************
  74. '**  Copyright 1998 Pervasive Software Inc. All Rights Reserved
  75. '*************************************************************************}
  76. '{*************************************************************************
  77. '**  btrv32vb.frm
  78. '**  This software is part of the Pervasive Software Developer Kit.
  79. '**  This source code is only intended as a supplement to the
  80. '**  Pervasive.SQL documentation; see that documentation for detailed
  81. '**  information regarding the use of Pervasive.SQL.
  82. '*************************************************************************}
  83. Option Explicit
  84. Dim sPersonPosBlk As PosBlock  'Person position block
  85. Dim sPersonPosBlk2 As PosBlock      'Person position block
  86. Dim nPersonKeyNum As Integer      'Person index number
  87. Dim nKeyBufLen As Integer         'Key Buffer Length
  88. Dim nKeyBufLen2 As Integer        'Key Buffer Length
  89. Dim sKeyBuffer As String          'Key Buffer for the Person table
  90. Dim sKeyBuffer2 As String         'Key Buffer for the Person table
  91. Dim NewFileSpec As BtrFileSpec    'Used for getting STAT on the file
  92. Dim PersonRow As PersonRowType    'Types created in BTR32VBFieldMap.bas
  93. Private Sub cmdExit_Click()
  94.   Unload Me
  95. End Sub
  96. '***********************************************************************
  97. '   This is the 'main' procedure of the sample
  98. '************************************************************************
  99. Private Sub cmdRunTest_Click()
  100. Dim lPersonID As Long
  101. Dim recordaddress As Long
  102. Dim prebuffer As PRE_GNE_BUFFER
  103. Dim prebufftype As pregnebuffertype
  104. Dim postbuffer As POST_GNE_BUFFER
  105. Dim postbufftype As postgnebuffertype
  106. Dim msg As String
  107. Dim DataLen As Integer
  108. Dim nStatus As Integer
  109. Dim versionBuffer As VersionType
  110. Dim versionstruct As Version_Struct
  111. Dim i As Integer
  112. Dim FileOpen As Boolean
  113. Dim File2Open As Boolean
  114. Dim personRecord As PersonRecType
  115. Dim personRec As PersonRowType
  116. Dim client As Client_ID
  117. Dim clientrow As ClientIDType
  118. Dim s As String
  119. Dim s2 As String
  120. Dim PosBlockSize As Integer
  121.   PosBlockSize = 128
  122.   sKeyBuffer = Space$(KEY_BUF_LEN)
  123.   sKeyBuffer2 = Space$(KEY_BUF_LEN)
  124.   nKeyBufLen = KEY_BUF_LEN
  125.   nKeyBufLen2 = KEY_BUF_LEN
  126.   s = String(PosBlockSize, 0)
  127.   s2 = String(PosBlockSize, 0)
  128.   CopyMemory sPersonPosBlk, s, PosBlockSize
  129.   CopyMemory sPersonPosBlk2, s2, PosBlockSize
  130.   'Read the users destination paths
  131.   sKeyBuffer = Trim(txtInput.Text)
  132.   sKeyBuffer2 = Trim(txtOutput.Text)
  133.   nPersonKeyNum = 0
  134.   'Version Btrieve Call
  135.   For i = 0 To 11
  136.     client.networkandnode(i) = CByte(0)
  137.   Next i
  138.   client.applicationID(0) = Asc("M")
  139.   client.applicationID(1) = Asc("T")
  140.   client.applicationID(2) = CByte(0)   ' must be greater than "AA"
  141.   client.threadID = 50
  142.   'Convert structure to a packed row.
  143.   StructToRow clientrow.buf, ClientIDFldMap, client, LenB(client)
  144.   nStatus = BTRCALLID(BVERSION, _
  145.                      0, _
  146.                      versionBuffer, _
  147.                      LenB(versionBuffer), _
  148.                      sKeyBuffer, _
  149.                      nKeyBufLen, _
  150.                      0, _
  151.                      client)
  152.                  
  153.                       
  154.   If nStatus = B_NO_ERROR Then
  155.     'Convert the packed row to a structure
  156.     RowToStruct versionBuffer.buf, Version_StructMap, versionstruct, _
  157.                 LenB(versionstruct)
  158.                 
  159.     For i = 0 To 2
  160.       If (versionstruct.ver(i).version > 0) Then
  161.         msg = "Btrieve Versions returned are: " & _
  162.                versionstruct.ver(i).version & "." & _
  163.                versionstruct.ver(i).revision & _
  164.                " " & versionstruct.ver(i).MKDEId
  165.         PrintLB (msg)
  166.       End If
  167.     Next i
  168.   Else
  169.     msg = "Btrieve B_VERSION status = " & nStatus
  170.     PrintLB (msg)
  171.   End If
  172.   If nStatus = B_NO_ERROR Then
  173.     ' Open Person table. (sample.btr)
  174.    nStatus = BTRCALL(BOPEN, _
  175.                        sPersonPosBlk, _
  176.                       PersonRow, _
  177.                       LenB(PersonRow), _
  178.                       ByVal sKeyBuffer, _
  179.                       nKeyBufLen, _
  180.                       nPersonKeyNum)
  181.                       
  182.     msg = "Btrieve B_OPEN status = " & nStatus
  183.     PrintLB (msg)
  184.     If nStatus = B_NO_ERROR Then
  185.       FileOpen = True
  186.     End If
  187.   End If
  188.   If nStatus = B_NO_ERROR Then
  189.     'GetEqual Btrieve Call
  190.     lPersonID = 263512477 'find a person with this SSN
  191.     nStatus = BTRCALL(BGETEQUAL, _
  192.                       sPersonPosBlk, _
  193.                       PersonRow, _
  194.                       LenB(PersonRow), _
  195.                       lPersonID, _
  196.                       LenB(lPersonID), _
  197.                       nPersonKeyNum)
  198.                       
  199.     msg = "Btrieve B_GETEQUAL status = " & nStatus
  200.     PrintLB (msg)
  201.     If nStatus = B_NO_ERROR Then
  202.       'Print out the Selected Record
  203.       
  204.       PrintData PersonRow.buf
  205.       
  206.     End If
  207.   End If
  208.   'Get stats on the file.
  209.   nStatus = BTRCALL(BSTAT, _
  210.                     sPersonPosBlk, _
  211.                     NewFileSpec, _
  212.                     100, _
  213.                     ByVal sKeyBuffer, _
  214.                     nKeyBufLen, _
  215.                     -1)
  216.                       
  217.   msg = "Btrieve B_STAT status = " & nStatus
  218.   PrintLB (msg)
  219.   If nStatus = B_NO_ERROR Then
  220.     'create and open sample2.btr
  221.     nStatus = BTRCALL(BCREATE, _
  222.                       0, _
  223.                       NewFileSpec, _
  224.                       100, _
  225.                       ByVal sKeyBuffer2, _
  226.                       nKeyBufLen2, _
  227.                       0)
  228.                       
  229.     msg = "Btrieve B_CREATE status = " & nStatus
  230.     PrintLB (msg)
  231.   End If
  232.   If nStatus = B_NO_ERROR Then
  233.     nPersonKeyNum = 0
  234.     nStatus = BTRCALL(BOPEN, _
  235.                       sPersonPosBlk2, _
  236.                       PersonRow, _
  237.                       LenB(PersonRow), _
  238.                       ByVal sKeyBuffer2, _
  239.                       nKeyBufLen2, _
  240.                       nPersonKeyNum)
  241.                       
  242.     'now extract data from the original file, insert into new one
  243.     If nStatus = B_NO_ERROR Then
  244.       File2Open = True
  245.     End If
  246.   End If
  247.   If nStatus = B_NO_ERROR Then
  248.     ' getFirst to establish currency
  249.     nPersonKeyNum = 2 'STATE-CITY index
  250.     nStatus = BTRCALL(BGETFIRST, _
  251.                       sPersonPosBlk, _
  252.                       PersonRow, _
  253.                       LenB(PersonRow), _
  254.                       ByVal sKeyBuffer, _
  255.                       nKeyBufLen, _
  256.                       nPersonKeyNum)
  257.                       
  258.     msg = "Btrieve B_GETFIRST status = " & nStatus
  259.     PrintLB (msg)
  260.   End If
  261.   prebuffer.gneHeader.currencyConst = "UC"
  262.   While nStatus = B_NO_ERROR
  263.     prebuffer.gneHeader.rejectCount = 0
  264.     prebuffer.gneHeader.numberTerms = 2
  265.     'fill in the first condition
  266.     prebuffer.term1.fieldType = 11
  267.     prebuffer.term1.fieldLen = 3
  268.     prebuffer.term1.fieldOffset = 108
  269.     prebuffer.term1.comparisonCode = 1
  270.     prebuffer.term1.connector = 2
  271.     prebuffer.term1.value = "TX" & Chr(0)
  272.     'fill in the second condition
  273.     prebuffer.term2.fieldType = 11
  274.     prebuffer.term2.fieldLen = 3
  275.     prebuffer.term2.fieldOffset = 108
  276.     prebuffer.term2.comparisonCode = 1
  277.     prebuffer.term2.connector = 0
  278.     prebuffer.term2.value = "CA" & Chr(0)
  279.     'fill in the projection header to retrieve whole record
  280.     prebuffer.retrieval.maxRecsToRetrieve = 20
  281.     prebuffer.retrieval.noFieldsToRetrieve = 1
  282.     prebuffer.recordRet.fieldLen = 157
  283.     prebuffer.recordRet.fieldOffset = 0
  284.     prebuffer.gneHeader.descriptionLen = Len(prebuffer)
  285.     'Make a packed array from the defined rows in the prebuffer.
  286.     StructToRow prebufftype.buf, pregnebufferMap, prebuffer, LenB(prebuffer)
  287.     'Make a packed array from the defined rows in the postbuffer.
  288.     StructToRow postbufftype.buf, Post_GNE_BUFFERFieldMap, postbuffer, _
  289.                 LenB(postbuffer)
  290.     'copy prebuffer to postbuffer area
  291.     CopyMemory postbufftype, prebufftype, LenB(prebufftype)
  292.     'GetNextExtended Btrieve Call
  293.     nStatus = BTRCALL(BGETNEXTEXTENDED, _
  294.                       sPersonPosBlk, _
  295.                       postbufftype, _
  296.                       LenB(postbufftype), _
  297.                       ByVal sKeyBuffer, _
  298.                       nKeyBufLen, _
  299.                       nPersonKeyNum)
  300.                       
  301.     msg = "Btrieve B_GETNEXTEXTENDED status = " & nStatus
  302.     PrintLB (msg)
  303.     'Get Next Extended can reach end of file and still return some records
  304.     If ((nStatus = B_NO_ERROR) Or (nStatus = B_END_OF_FILE)) Then
  305.       InsertNewData postbufftype.buf
  306.       
  307.     End If
  308.     prebuffer.gneHeader.currencyConst = "EG"
  309.   Wend
  310.   nPersonKeyNum = 0
  311.   msg = " "
  312.   PrintLB (msg$)
  313.   If FileOpen = True Then
  314.     'close open files
  315.     nStatus = BTRCALL(BCLOSE, _
  316.                       sPersonPosBlk, _
  317.                       0, 0, 0, 0, 0)
  318.                       
  319.     msg = "Btrieve B_CLOSE (sample.btr) status = " & nStatus
  320.     PrintLB (msg)
  321.   End If
  322.   If File2Open = True Then
  323.     nStatus = BTRCALL(BCLOSE, _
  324.                       sPersonPosBlk2, _
  325.                       0, 0, 0, 0, 0)
  326.                       
  327.     msg = "Btrieve B_CLOSE (sample2.btr) status = " & nStatus
  328.     PrintLB (msg)
  329.   End If
  330.   'FREE RESOURCES
  331.   nStatus = BTRCALL(BRESET, _
  332.                     "", _
  333.                     0, _
  334.                     0, _
  335.                     CLng(0), _
  336.                     0, _
  337.                     0)
  338.                     
  339.   msg = "Btrieve B_RESET status = " & nStatus
  340.   PrintLB (msg)
  341. End Sub
  342. Private Sub Form_Load()
  343.   InitFieldMaps
  344.   txtInput.Text = "d:\pvsw\samples\sample.btr"
  345.   txtOutput.Text = "d:\pvsw\samples\sample2.btr"
  346. End Sub
  347. '***********************************************************************
  348. '   A helper procedure to write to the ListBox
  349. '************************************************************************
  350. Sub PrintLB(Item As String)
  351.   frmBtrv32.lstBtrv.AddItem Item
  352. End Sub
  353. '******************************************************************
  354. '  This Subroutine Inserts the data from the first file into the
  355. '  second file.
  356. '******************************************************************
  357. Private Sub InsertNewData(row() As Byte)
  358. Dim rec As POST_GNE_BUFFER
  359. Dim msg As String
  360. Dim i As Integer
  361. Dim personRecord As PersonRecType
  362. Dim personRec As PersonRowType
  363. Dim DataLen As Integer
  364. Dim nStatus As Integer '
  365.   'Convert the packed row to a structure.
  366.   RowToStruct row, Post_GNE_BUFFERFieldMap, rec, LenB(rec)
  367.   msg = "GetNextExtended returned " & rec.numReturned & " record(s)."
  368.   PrintLB (msg)
  369.   For i = 0 To rec.numReturned - 1
  370.     personRecord = rec.recs(i).personRecord
  371.     StructToRow personRec.buf, PersonFldMap, personRecord, LenB(personRecord)
  372.     nStatus = BTRCALL(BINSERT, _
  373.                       sPersonPosBlk2, _
  374.                       personRec, _
  375.                       LenB(personRec), _
  376.                       ByVal sKeyBuffer2, _
  377.                       nKeyBufLen2, _
  378.                       -1) 'no currency change
  379.     If (nStatus <> B_NO_ERROR) Then
  380.       msg = "Btrieve B_INSERT status = " & nStatus
  381.       PrintLB (msg)
  382.     End If
  383.   Next i
  384.   msg = "Inserted " & rec.numReturned & _
  385.         " records in new file, status = " & nStatus
  386.   PrintLB (msg)
  387. End Sub
  388. '*****************************************************************
  389. '  This subroutine prints out the data for the selected record.
  390. '*****************************************************************
  391. Private Sub PrintData(row() As Byte)
  392. Dim rec As PersonRecType
  393. Dim msg As String
  394.   'Convert the packed row to a structure.
  395.   RowToStruct row, PersonFldMap, rec, LenB(rec)
  396.   msg = " "
  397.   PrintLB (msg$)
  398.   msg = "Selected fields from the retrieved record are: "
  399.   PrintLB (msg)
  400.   msg = "ID =         " & Chr$(9) & rec.ID
  401.   PrintLB (msg)
  402.   msg = "First Name = " & Chr$(9) & rec.FirstName
  403.   PrintLB (msg)
  404.   msg = "Last Name =  " & Chr$(9) & rec.LastName
  405.   PrintLB (msg)
  406.   msg = "Address =    " & Chr$(9) & rec.Street
  407.   PrintLB (msg)
  408.   msg = "City =       " & Chr$(9) & rec.City
  409.   PrintLB (msg)
  410.   msg = "State =      " & Chr$(9) & rec.State
  411.   PrintLB (msg)
  412.   msg = "Country =    " & Chr$(9) & rec.Country
  413.   PrintLB (msg)
  414.   msg = "Zip =        " & Chr$(9) & rec.Zip
  415.   PrintLB (msg)
  416.   msg = "Phone =      " & Chr$(9) & rec.Phone
  417.   PrintLB (msg)
  418.   msg = " "
  419.   PrintLB (msg$)
  420. End Sub
  421.