home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / CanDo / Decks1 / CanDoV2 / DBBaseDeck.ctx < prev    next >
Encoding:
Text File  |  1998-06-28  |  4.2 KB  |  158 lines

  1. *************
  2. * Deck "DBBaseDeck"
  3. *************
  4.  
  5. *************
  6. * Card(s) in deck.
  7. *  Card "CARD#1"
  8. *************
  9. * 1 Card(s), 1 were printed.
  10. *************
  11.  
  12. *************
  13. * Natural order of Cards
  14. *  Card "CARD#1"
  15. *************
  16.  
  17. *************
  18. * Global Routine(s) in deck.
  19. *  Routine "Add Entry"
  20. *  Routine "Delete Entry"
  21. *  Routine "Display Entry"
  22. *  Routine "Load Database"
  23. *  Routine "Next Entry"
  24. *  Routine "Previous Entry"
  25. *  Routine "Save Database"
  26. *  Routine "Search For Entry"
  27. *  Routine "Sort DataBase"
  28. *************
  29. * 9 Global routines(s), 9 were printed.
  30. *************
  31.  
  32. *************
  33. * Card "CARD#1"
  34.     AfterAttachment
  35.         Let DataFile = "Ram:TestDB.DAT"
  36.         Do "Load Database"
  37.     EndScript
  38.     Window "UserWindow"
  39.         Definition
  40.             Origin 0,0
  41.             Size 320,200
  42.             Title ""
  43.             NumberOfColors 16
  44.             DefaultColors 0,1,0
  45.             WindowObjects CLOSEBUTTON DEPTHBUTTONS DRAGBAR 
  46.             WindowFlags ACTIVATE TOFRONT WORKBENCH 
  47.             VisualEffects NONE ,WAIT 
  48.         EndScript
  49.         OnCloseButton
  50.             Quit
  51.         EndScript
  52.     EndObject
  53. * End of Card "CARD#1"
  54. *************
  55.  
  56. *************
  57. * Global routine "Add Entry"
  58.     Let DataBase[Index] = GetDBOBjects    ; save current entry
  59.     Let Index = Index + 1                ; insert it at next index
  60.     InsertArrayEntry DataBase,Index        ; make space for it
  61.     Do "Display Entry"
  62. * End of routine "Add Entry"
  63. *************
  64.  
  65. *************
  66. * Global routine "Delete Entry"
  67.     DeleteArrayEntry DataBase,Index            ; delete this dude
  68.     If VarType(DataBase[Index]) = "Nothing"    ; check if last(end) entry
  69.         Let Index = LastArrayIndex(DataBase); find new last(end) entry
  70.     EndIf
  71.     Do "Display Entry"
  72. * End of routine "Delete Entry"
  73. *************
  74.  
  75. *************
  76. * Global routine "Display Entry"
  77.     SetDBObjects DataBase[Index]                ; display Entry
  78.     SetWindowTitle "Entry #" || Index
  79. * End of routine "Display Entry"
  80. *************
  81.  
  82. *************
  83. * Global routine "Load Database"
  84.     Dispose DataBase                            ; get rid of current
  85.     If Exists(DataFile)                            ; check if file exists
  86.         Let DataBase = LoadVariable(DataFile)    ; load it
  87.         IfError    ;this simple example does nothing for an error
  88.         EndIf    ;you can do something like display a requester
  89.     EndIf
  90.     Let Index = FirstArrayIndex(DataBase)        ; go to first entry
  91.     Do "Display Entry"
  92. * End of routine "Load Database"
  93. *************
  94.  
  95. *************
  96. * Global routine "Next Entry"
  97.     Let DataBase[Index] = GetDBOBjects            ; Save Entry
  98.     Let Index = NextArrayIndex(DataBase,Index)    ; Look for Next entry
  99.     If Not SearchFound                            ; Check if at end
  100.         Let Index = FirstArrayIndex(DataBase)    ; go to first one
  101.     EndIf
  102.     Do "Display Entry"
  103. * End of routine "Next Entry"
  104. *************
  105.  
  106. *************
  107. * Global routine "Previous Entry"
  108.     Let DataBase[Index] = GetDBOBjects                ; save entry
  109.     Let Index = PreviousArrayIndex(DataBase,Index)    ; find previous
  110.     If Not SearchFound                                ; if not one
  111.         Let Index = LastArrayIndex(DataBase)        ; go to last one
  112.     EndIf
  113.     Do "Display Entry"
  114. * End of routine "Previous Entry"
  115. *************
  116.  
  117. *************
  118. * Global routine "Save Database"
  119.     Let DataBase[Index] = GetDBObjects        ; save current entry
  120.     SaveVariable DataBase,DataFile            ; save it
  121.     IfError ;this simple example does not do anything for an error
  122.     EndIf    ;however, you can do something like display a requester
  123. * End of routine "Save Database"
  124. *************
  125.  
  126. *************
  127. * Global routine "Search For Entry"
  128.     Nop; ARG1 = "Search Value"
  129.     Nop; ARG2 = "Search Key"
  130.     Nop; example - Do "Search For Entry","Henry",".Name"
  131.     Nop
  132.     Let DataBase[Index] = GetDBOBjects            ; Save Entry
  133.     SetSearchArrayFlags NOCASE SUBSTRING 
  134.     Let OldIndex = Index ;save index in case Arg1 is not found
  135.     Let Index = SearchArray(DataBase,Arg1,Arg2,Index+1)    ; search from next index
  136.     If Not SearchFound                            ; Check if found it
  137.         Let Index = SearchArray(DataBase,Arg1,Arg2)    ; search from beginning
  138.         If Not SearchFound
  139.             Let Index = OldIndex    ;not found - goto original index
  140.         EndIf
  141.     EndIf
  142.     Do "Display Entry" ; Display it!
  143. * End of routine "Search For Entry"
  144. *************
  145.  
  146. *************
  147. * Global routine "Sort DataBase"
  148.     Nop ; ARG1 = "Sort key"
  149.     Nop ; example - Do "Sort DataBase",".Name"
  150.     Nop
  151.     Let DataBase[Index] = GetDBOBjects        ; Save Entry
  152.     SortArray DataBase,NOCASE STRING ,ARG1    ; Sort Data
  153.     Let Index = FirstArrayIndex(DataBase)    ; go to first one
  154.     Do "Display Entry"
  155. * End of routine "Sort DataBase"
  156. *************
  157.  
  158.