*************
* Deck "TestDrive2"
*************

*************
* Card(s) in deck.
*  Card "CARD#1"
*************
* 1 Card(s), 1 were printed.
*************

*************
* Natural order of Cards
*  Card "CARD#1"
*************

*************
* Global Routine(s) in deck.
*  Routine "Add Entry"
*  Routine "Delete Entry"
*  Routine "Display Entry"
*  Routine "Load Database"
*  Routine "Next Entry"
*  Routine "Previous Entry"
*  Routine "Save Database"
*  Routine "Search For Entry"
*  Routine "Sort DataBase"
*************
* 9 Global routines(s), 9 were printed.
*************

*************
* Card "CARD#1"
	AfterAttachment
		Let DataFile = "TestDB.DAT"
		Do "Load Database"
	EndScript
	PictureWindow "UserWindow"
		Definition
			Origin 0,0
			BackgroundImage "CanDo:Images/MovieBackdrop.ilbm" ; size and depth comes from image
			Title ""
			DefaultColors 0,1,0
			WindowObjects CLOSEBUTTON DEPTHBUTTONS DRAGBAR 
			WindowFlags ACTIVATE SEPARATESCREEN TOFRONT 
			VisualEffects NONE ,WAIT 
		EndScript
		OnCloseButton
			Quit
		EndScript
	EndObject
	AltImageButton "Previous Button"
		Definition
			Origin 15,50
			Image "CanDo:Brushes/left1.grab"
			AltImage "CanDo:Brushes/left2.grab"
			Shape "CanDo:Brushes/left1.grab"
			ButtonFlags NONE 
		EndScript
		OnRelease
			Do "Previous Entry"
		EndScript
	EndObject
	AltImageButton "Next Button"
		Definition
			Origin 60,50
			Image "CanDo:Brushes/right1.grab"
			AltImage "CanDo:Brushes/right2.grab"
			Shape "CanDo:Brushes/right1.grab"
			ButtonFlags NONE 
		EndScript
		OnRelease
			Do "Next Entry"
		EndScript
	EndObject
	TextButton "Add Button"
		Definition
			Origin 20,75
			Font "topaz",8 ; FontName, PointSize
			Style SHADOW ,2,3
			TextColors 3,0,JAM1  ; PenA, PenB, DrawMode
			Text "  Add  "
			Border SHADOW ,1,2 ; BorderStyle, MainPen, ExtraPen
			Highlight COMPLEMENT 
			ButtonFlags NONE 
		EndScript
		OnRelease
			Do "Add Entry"
		EndScript
	EndObject
	TextField ".Name"
		Definition
			Origin 230,52
			Size 320,8
			Justification LEFT 
			MaxFieldLength 40
			InitialText ""
			Border DOUBLEBEVEL ,1,2 ; BorderStyle, MainPen, ExtraPen
		EndScript
	EndObject
	IntegerField ".Number"
		Definition
			Origin 230,70
			Size 80,8
			Justification LEFT 
			MaxFieldLength 10
			Limits 0,2147483647
			InitialInteger 0
			Border DOUBLEBEVEL ,1,2 ; BorderStyle, MainPen, ExtraPen
		EndScript
	EndObject
	Memo ".Description"
		Definition
			Origin 230,88
			Size 320,64
			Font "topaz",8 ; FontName, PointSize
			Style PLAIN ,2,3
			TextColors 1,0,JAM2  ; PenA, PenB, DrawMode
			Border DOUBLEBEVEL ,1,2 ; BorderStyle, MainPen, ExtraPen
			MemoDocument "Description - Doc" ; where the text comes from
			ScrollBars RIGHT 
			InputStyle NORMAL 
		EndScript
	EndObject
	TextField "SearchField"
		Definition
			Origin 230,165
			Size 320,8
			Justification LEFT 
			MaxFieldLength 40
			InitialText ""
			Border OUTLINE ,1,2 ; BorderStyle, MainPen, ExtraPen
		EndScript
		OnRelease
			Do "Search For Entry",TextFrom("SearchField"),".Name"
			SetObjectState "SearchField",ON
		EndScript
	EndObject
	TextMenu "Save"
		Definition
			AttachTo MENU ,"Project"
			Font "topaz",8 ; FontName, PointSize
			Style PLAIN ,2,3
			TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
			Text "Save"
			MenuFlags NONE 
			Highlight COMPLEMENT 
			ShortCutKey "S"
		EndScript
		Occurred
			Do "Save Database"
		EndScript
	EndObject
	TextMenu "Load"
		Definition
			AttachTo MENU ,"Project"
			Font "topaz",8 ; FontName, PointSize
			Style PLAIN ,2,3
			TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
			Text "Load"
			MenuFlags NONE 
			Highlight COMPLEMENT 
			ShortCutKey "L"
		EndScript
		Occurred
			Do "Load Database"
		EndScript
	EndObject
	TextMenu "Sort"
		Definition
			AttachTo MENU ,"Options"
			Font "topaz",8 ; FontName, PointSize
			Style PLAIN ,2,3
			TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
			Text "Sort"
			MenuFlags NONE 
			Highlight COMPLEMENT 
			ShortCutKey ""
		EndScript
		Occurred
			Do "Sort DataBase",".Name"
		EndScript
	EndObject
	TextMenu "Delete"
		Definition
			AttachTo MENU ,"Options"
			Font "topaz",8 ; FontName, PointSize
			Style PLAIN ,2,3
			TextColors 0,1,JAM1  ; PenA, PenB, DrawMode
			Text "Delete"
			MenuFlags NONE 
			Highlight COMPLEMENT 
			ShortCutKey ""
		EndScript
		Occurred
			Do "Delete Entry"
		EndScript
	EndObject
* End of Card "CARD#1"
*************

*************
* Global routine "Add Entry"
	Let DataBase[Index] = GetDBOBjects	; save current entry
	Let Index = Index + 1				; insert it at next index
	InsertArrayEntry DataBase,Index		; make space for it
	Do "Display Entry"
* End of routine "Add Entry"
*************

*************
* Global routine "Delete Entry"
	DeleteArrayEntry DataBase,Index			; delete this dude
	If VarType(DataBase[Index]) = "Nothing"	; check if last(end) entry
		Let Index = LastArrayIndex(DataBase); find new last(end) entry
	EndIf
	Do "Display Entry"
* End of routine "Delete Entry"
*************

*************
* Global routine "Display Entry"
	SetDBObjects DataBase[Index]				; display Entry
	SetWindowTitle "Entry #" || Index
* End of routine "Display Entry"
*************

*************
* Global routine "Load Database"
	Dispose DataBase							; get rid of current
	If Exists(DataFile)							; check if file exists
		Let DataBase = LoadVariable(DataFile)	; load it
		IfError	;this simple example does nothing for an error
		EndIf	;you can do something like display a requester
	EndIf
	Let Index = FirstArrayIndex(DataBase)		; go to first entry
	Do "Display Entry"
* End of routine "Load Database"
*************

*************
* Global routine "Next Entry"
	Let DataBase[Index] = GetDBOBjects			; Save Entry
	Let Index = NextArrayIndex(DataBase,Index)	; Look for Next entry
	If Not SearchFound							; Check if at end
		Let Index = FirstArrayIndex(DataBase)	; go to first one
	EndIf
	Do "Display Entry"
* End of routine "Next Entry"
*************

*************
* Global routine "Previous Entry"
	Let DataBase[Index] = GetDBOBjects				; save entry
	Let Index = PreviousArrayIndex(DataBase,Index)	; find previous
	If Not SearchFound								; if not one
		Let Index = LastArrayIndex(DataBase)		; go to last one
	EndIf
	Do "Display Entry"
* End of routine "Previous Entry"
*************

*************
* Global routine "Save Database"
	Let DataBase[Index] = GetDBObjects		; save current entry
	SaveVariable DataBase,DataFile			; save it
	IfError ;this simple example does not do anything for an error
	EndIf	;however, you can do something like display a requester
* End of routine "Save Database"
*************

*************
* Global routine "Search For Entry"
	Nop; ARG1 = "Search Value"
	Nop; ARG2 = "Search Key"
	Nop; example - Do "Search For Entry","Henry",".Name"
	Nop
	Let DataBase[Index] = GetDBOBjects			; Save Entry
	SetSearchArrayFlags NOCASE SUBSTRING 
	Let OldIndex = Index ;save index in case Arg1 is not found
	Let Index = SearchArray(DataBase,Arg1,Arg2,Index+1)	; search from next index
	If Not SearchFound							; Check if found it
		Let Index = SearchArray(DataBase,Arg1,Arg2)	; search from beginning
		If Not SearchFound
			Let Index = OldIndex	;not found - goto original index
		EndIf
	EndIf
	Do "Display Entry" ; Display it!
* End of routine "Search For Entry"
*************

*************
* Global routine "Sort DataBase"
	Nop ; ARG1 = "Sort key"
	Nop ; example - Do "Sort DataBase",".Name"
	Nop
	Let DataBase[Index] = GetDBOBjects		; Save Entry
	SortArray DataBase,NOCASE STRING ,ARG1	; Sort Data
	Let Index = FirstArrayIndex(DataBase)	; go to first one
	Do "Display Entry"
* End of routine "Sort DataBase"
*************

