home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Basic / GridOne / setup.EXE / BOUNDDATA.CLS < prev    next >
Encoding:
Visual Basic class definition  |  2001-09-09  |  6.6 KB  |  256 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "CSimpleOLEDB"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. '-----------------------------------------------------------------------------
  15. ' This is a part of the BeeGrid ActiveX control.
  16. ' Copyright ⌐ 2000 Stinga
  17. ' All rights reserved.
  18. '
  19. ' You have a right to use and distribute the BeeGrid sample files in original
  20. ' form or modified, provided that you agree that Stinga has no warranty,
  21. ' obligations, or liability for any sample application files.
  22. '-----------------------------------------------------------------------------
  23. Option Explicit
  24. Implements OLEDBSimpleProvider
  25.  
  26. Private mlRowsCount As Long
  27. Private miColCount As Integer
  28.  
  29. Private Const COL_COUNT = 7
  30.  
  31. Private colListeners As New Collection
  32.  
  33. Private marPlayersList() As Variant
  34. Public Filename As String
  35.  
  36.  
  37. Private Sub SaveData()
  38.    Dim sData As String, iFreeFile As Integer
  39.    Dim i As Long, j As Integer
  40.    
  41.    On Error GoTo ErrorTrap
  42.    
  43.    For i = 0 To mlRowsCount
  44.       For j = 0 To COL_COUNT - 2
  45.          sData = sData & marPlayersList(j, i) & vbTab
  46.       Next
  47.       
  48.       sData = sData & marPlayersList(COL_COUNT - 1, i)
  49.       sData = sData & vbCrLf
  50.    Next
  51.    
  52.    If Len(sData) > 0 Then
  53.       sData = Left(sData, Len(sData) - 2)
  54.    End If
  55.    iFreeFile = FreeFile
  56.    
  57.    Kill Filename
  58.    Open Filename For Binary _
  59.       Access Write Lock Write As #iFreeFile
  60.    
  61.    Put #iFreeFile, , sData
  62.    Close #iFreeFile
  63.    
  64.    Exit Sub
  65. ErrorTrap:
  66.     MsgBox VBA.Error, vbExclamation
  67.     Exit Sub
  68. End Sub
  69. Private Sub Class_Terminate()
  70.    Set colListeners = Nothing
  71.    SaveData
  72. End Sub
  73.  
  74.  
  75. Private Sub OLEDBSimpleProvider_addOLEDBSimpleProviderListener(ByVal pospIListener As MSDAOSP.OLEDBSimpleProviderListener)
  76.    'Add a listener to the Listeners collection
  77.    If Not (pospIListener Is Nothing) Then
  78.       Dim ospl As OLEDBSimpleProviderListener
  79.       
  80.       Set ospl = pospIListener
  81.       colListeners.Add ospl
  82.       
  83.       Set ospl = Nothing
  84.    End If
  85.  
  86. End Sub
  87.  
  88. Private Function OLEDBSimpleProvider_deleteRows _
  89.    (ByVal iRow As Long, ByVal cRows As Long) As Long
  90.    Dim i As Long, j As Integer
  91.    Dim listener As OLEDBSimpleProviderListener
  92.    Dim v As Variant
  93.    
  94.    For Each v In colListeners
  95.       Set listener = v
  96.       listener.aboutToDeleteRows iRow, cRows
  97.    Next
  98.       
  99.    mlRowsCount = mlRowsCount - 1
  100.    
  101.    For i = iRow To mlRowsCount
  102.       For j = 0 To UBound(marPlayersList, 1)
  103.          marPlayersList(j, i) = marPlayersList(j, i + 1)
  104.       Next
  105.    Next
  106.    
  107.    For Each v In colListeners
  108.       Set listener = v
  109.       listener.deletedRows iRow, cRows
  110.    Next
  111.    
  112.    OLEDBSimpleProvider_deleteRows = 1
  113. End Function
  114.  
  115.  
  116. Private Function OLEDBSimpleProvider_find(ByVal iRowStart As Long, ByVal iColumn As Long, ByVal val As Variant, ByVal findFlags As MSDAOSP.OSPFIND, ByVal compType As MSDAOSP.OSPCOMP) As Long
  117.  
  118. End Function
  119.  
  120.  
  121. Private Function OLEDBSimpleProvider_getColumnCount() As Long
  122.    OLEDBSimpleProvider_getColumnCount = COL_COUNT
  123. End Function
  124.  
  125.  
  126. Private Function OLEDBSimpleProvider_getEstimatedRows() As Long
  127.    OLEDBSimpleProvider_getEstimatedRows = mlRowsCount
  128. End Function
  129.  
  130.  
  131. Private Function OLEDBSimpleProvider_getLocale() As String
  132.  
  133. End Function
  134.  
  135.  
  136. Private Function OLEDBSimpleProvider_getRowCount() As Long
  137.    OLEDBSimpleProvider_getRowCount = mlRowsCount
  138. End Function
  139.  
  140.  
  141.  
  142. Public Sub LoadData()
  143.    Dim iFreeFile As Integer
  144.    Dim sData As String, arRows() As String, arRow() As String
  145.    Dim i As Long, j As Integer
  146.    
  147.    On Error GoTo ErrorTrap
  148.    'get data from file
  149.    iFreeFile = FreeFile
  150.    
  151.    sData = String(FileLen(Filename), " ")
  152.    Open Filename For Binary Access Read As #iFreeFile
  153.    Get #iFreeFile, , sData
  154.    Close #iFreeFile
  155.    
  156.    If Len(sData) = 0 Then
  157.       ReDim marPlayersList(COL_COUNT - 1, 30)
  158.       Exit Sub
  159.    End If
  160.    'add data to an array
  161.    arRows = Split(sData, vbCrLf)
  162.    mlRowsCount = UBound(arRows)
  163.       
  164.    ReDim marPlayersList(COL_COUNT - 1, mlRowsCount + 30)
  165.    
  166.    For i = 0 To mlRowsCount
  167.       arRow = Split(arRows(i), vbTab)
  168.       For j = 0 To COL_COUNT - 1
  169.          marPlayersList(j, i) = arRow(j)
  170.       Next
  171.    Next
  172.    
  173.    Exit Sub
  174. ErrorTrap:
  175.    MsgBox VBA.Error, vbExclamation
  176.    Resume Next
  177. End Sub
  178. Private Function OLEDBSimpleProvider_getRWStatus(ByVal iRow As Long, ByVal iColumn As Long) As MSDAOSP.OSPRW
  179.    OLEDBSimpleProvider_getRWStatus = OSPRW_READWRITE
  180. End Function
  181.  
  182.  
  183. Private Function OLEDBSimpleProvider_getVariant(ByVal iRow As Long, ByVal iColumn As Long, ByVal format As MSDAOSP.OSPFORMAT) As Variant
  184.    OLEDBSimpleProvider_getVariant = marPlayersList(iColumn - 1, iRow)
  185. End Function
  186.  
  187.  
  188. Private Function OLEDBSimpleProvider_insertRows _
  189.    (ByVal iRow As Long, ByVal cRows As Long) As Long
  190.    Dim listener As OLEDBSimpleProviderListener
  191.    Dim v As Variant
  192.    
  193.    mlRowsCount = mlRowsCount + 1
  194.    
  195.    For Each v In colListeners
  196.       Set listener = v
  197.       listener.aboutToInsertRows iRow, cRows
  198.    Next
  199.    
  200.    If mlRowsCount > UBound(marPlayersList, 2) Then
  201.       ReDim Preserve marPlayersList _
  202.          (UBound(marPlayersList, 1), mlRowsCount + 30) As Variant
  203.    End If
  204.    
  205.    For Each v In colListeners
  206.       Set listener = v
  207.       listener.insertedRows iRow, cRows
  208.    Next
  209. End Function
  210.  
  211.  
  212. Private Function OLEDBSimpleProvider_isAsync() As Long
  213.     OLEDBSimpleProvider_isAsync = False
  214. End Function
  215.  
  216.  
  217. Private Sub OLEDBSimpleProvider_removeOLEDBSimpleProviderListener(ByVal pospIListener As MSDAOSP.OLEDBSimpleProviderListener)
  218.     Dim i As Integer
  219.     
  220.     'Remove the listener:
  221.     For i = 1 To colListeners.Count
  222.         If colListeners(i) Is pospIListener Then
  223.             colListeners.Remove i
  224.         End If
  225.     Next
  226.  
  227. End Sub
  228.  
  229.  
  230. Private Sub OLEDBSimpleProvider_setVariant _
  231.    (ByVal iRow As Long, ByVal iColumn As Long, _
  232.    ByVal format As MSDAOSP.OSPFORMAT, ByVal Var As Variant)
  233.     Dim listener As OLEDBSimpleProviderListener
  234.     Dim v As Variant
  235.     
  236.     For Each v In colListeners
  237.         Set listener = v
  238.         listener.aboutToChangeCell iRow, iColumn    'Pre-notification
  239.     Next
  240.     
  241.     marPlayersList(iColumn - 1, iRow) = Var
  242.     
  243.     For Each v In colListeners
  244.         Set listener = v
  245.         listener.cellChanged iRow, iColumn          'Post-notification
  246.     Next
  247.  
  248. End Sub
  249.  
  250.  
  251. Private Sub OLEDBSimpleProvider_stopTransfer()
  252.  
  253. End Sub
  254.  
  255.  
  256.