Cheetah Indexing with PureBasic
Cheetah Indexing with PureBasic
Using Cheetah2PureBASIC wrapper w/ PB 3.94 
; DBF is "Current.dbf"
; Wish to index on a field "TITLE C 48" to index named "Curr1.idx"
; and console list field in index order.
;-Begin-----------------------------------------------------------------
IncludeFile "Cheetah2.pbi"
xdbUseDLL()
hdb1 = xdbOpen("current.dbf", "")
     
xdbCreateIndex("curr1.idx", hdb1, "TITLE", 0)
   
xdbOpenIndex("curr1.idx", hdb1)
xdbReindexAll(curr1, 0)
xdbMoveFirst(hdb1, curr1)
OpenConsole()
While xdbEOF(hdb1) = 0
    
PrintN("cTITLE: " + xdbFieldValue(hdb1, "TITLE", 0))
      
xdbMoveNext(hdb1, curr1)
       
Wend
 
PrintN("")
PrintN("Press any key to exit...")
Input()
CloseConsole()
;-Close database------------------------------------------------------
xdbCloseIndex(hdb1,curr1)
xdbClose(hdb1)
xdbClose(hdb2)
;-Free resources------------------------------------------------------
xdbFreeDLL()
End
			
			
													; DBF is "Current.dbf"
; Wish to index on a field "TITLE C 48" to index named "Curr1.idx"
; and console list field in index order.
;-Begin-----------------------------------------------------------------
IncludeFile "Cheetah2.pbi"
xdbUseDLL()
hdb1 = xdbOpen("current.dbf", "")
xdbCreateIndex("curr1.idx", hdb1, "TITLE", 0)
xdbOpenIndex("curr1.idx", hdb1)
xdbReindexAll(curr1, 0)
xdbMoveFirst(hdb1, curr1)
OpenConsole()
While xdbEOF(hdb1) = 0
PrintN("cTITLE: " + xdbFieldValue(hdb1, "TITLE", 0))
xdbMoveNext(hdb1, curr1)
Wend
PrintN("")
PrintN("Press any key to exit...")
Input()
CloseConsole()
;-Close database------------------------------------------------------
xdbCloseIndex(hdb1,curr1)
xdbClose(hdb1)
xdbClose(hdb2)
;-Free resources------------------------------------------------------
xdbFreeDLL()
End
					Last edited by nicksteel on Tue Jun 12, 2007 8:07 pm, edited 2 times in total.
									
			
									
						- 
				PaulSquires
- New User 
- Posts: 2
- Joined: Sun Aug 13, 2006 3:29 am
I don't really know PureBasic but I expect that you are not assigning the index handle to a variable?
Should be:  ?????
...and...
Should be: ?????
Just a guess.
			
			
									
									
						Code: Select all
 xdbOpenIndex("curr1.idx", hdb1)
Code: Select all
curr1 = xdbOpenIndex("curr1.idx", hdb1)
Code: Select all
xdbReindexAll(curr1, 0) 
Code: Select all
xdbReindexAll(hdb1, 0) 
A couple of mistakes...
1. You didn't assign the index handle to curr1
2. xdbReindexAll needs the database handle, not the index handle
3. database close for an apparently unopened database
The xdbCreateIndex function will index the records so you don't really need to xdbReindexAll function
So the final program looks like this:
			
			
									
									
						1. You didn't assign the index handle to curr1
2. xdbReindexAll needs the database handle, not the index handle
3. database close for an apparently unopened database
The xdbCreateIndex function will index the records so you don't really need to xdbReindexAll function
So the final program looks like this:
Code: Select all
; DBF is "Current.dbf" 
; Wish to index on a field "TITLE C 48" to index named "Curr1.idx" 
; and console list field in index order. 
;-Begin----------------------------------------------------------------- 
IncludeFile "Cheetah2.pbi" 
xdbUseDLL() 
hdb1 = xdbOpen("current.dbf", "") 
xdbCreateIndex("curr1.idx", hdb1, "TITLE", 0) 
curr1 = xdbOpenIndex("curr1.idx", hdb1) 
xdbMoveFirst(hdb1, curr1) 
OpenConsole() 
While xdbEOF(hdb1) = 0 
  PrintN("cTITLE: " + xdbFieldValue(hdb1, "TITLE", 0)) 
  xdbMoveNext(hdb1, curr1) 
Wend 
PrintN("") 
PrintN("Press any key to exit...") 
Input() 
CloseConsole() 
;-Close database------------------------------------------------------ 
xdbCloseIndex(hdb1,curr1) 
xdbClose(hdb1) 
;-Free resources------------------------------------------------------ 
xdbFreeDLL() 
EndThanks, but.........
Now using PureBasic v4.02
Using cheetah2.dll from Paul's site, dated 09/25/2005.
Now getting (with the above Tipperton corrected code):
[COMPILER]Line 777:'ProcedureReturn' expects a numerical value, not a string.
From: Cheetah2.pbi:
776 Procedure xdbTempFileName()
777 ProcedureReturn PeekS(CallFunction(xdbhDLL, "XDBTEMPFILENAME_Z"))
778 EndProcedure
Please don't give up on me. This is step-by-step transition from Clipper (and I am proficient with Xbase). I need the procedural approach of PureBasic and Cheetah and sincerely appreciate any help to get started.
			
			
													Now using PureBasic v4.02
Using cheetah2.dll from Paul's site, dated 09/25/2005.
Now getting (with the above Tipperton corrected code):
[COMPILER]Line 777:'ProcedureReturn' expects a numerical value, not a string.
From: Cheetah2.pbi:
776 Procedure xdbTempFileName()
777 ProcedureReturn PeekS(CallFunction(xdbhDLL, "XDBTEMPFILENAME_Z"))
778 EndProcedure
Please don't give up on me. This is step-by-step transition from Clipper (and I am proficient with Xbase). I need the procedural approach of PureBasic and Cheetah and sincerely appreciate any help to get started.
					Last edited by nicksteel on Wed Jun 13, 2007 2:36 pm, edited 2 times in total.
									
			
									
						Using code exactly as modified by Tipperton above.gnozal wrote:I don't know the rest of your code, but try this :
Procedure.s xdbTempFileName()
This got rid of compiler error, but I now get console screen:
cTITLE:
Press any key to exit...
From:
PrintN("cTITLE: " + xdbFieldValue(hdb1, "TITLE", 0))
					Last edited by nicksteel on Wed Jun 13, 2007 2:32 pm, edited 1 time in total.
									
			
									
						- 
				gnozal
- PureBasic Expert 
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
I don't have the include.nicksteel wrote:The code is exactly as modified by Tipperton above.gnozal wrote:I don't know the rest of your code, but try this :
Procedure.s xdbTempFileName()
Line 776 ?nicksteel wrote:Where do I insert this?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
						Interesting...nicksteel wrote:When I add:
xdbReindexAll(hdb1, 0)
it works!
In dBase, FoxPro, and Clipper I assume when you create an index it automatically does a reindex so you can just begin using it without having to explicitly build it.
Apparently in Cheetah, creating an index only defines it, you still have to actually build the index with the reindex call...
Sorry for steering you wrong on that...

I've found that I only have to reindex immediately after creating.  After that, it opens and runs without. 
So far, I'm able to open multiple dbf's with multiple indices and manipulate pretty well. The Cheetah commands are similiar to Clipper.
My current quest is for a browse function ( a data grid with dbf fields). Not much luck so far, but I've found ListIconGadget() to play with. It would involve reference arrays to contain cell xy positions for mouse location, etc. Haven't been able to locate anything better so far. Have written browse in Clipper, so have something to start with.
ListIconGadget() seems only able to directly click onn the 1st column, so need to develop something to expand upon this.
If you have any ideas, would really appreciate.
			
			
									
									
						So far, I'm able to open multiple dbf's with multiple indices and manipulate pretty well. The Cheetah commands are similiar to Clipper.
My current quest is for a browse function ( a data grid with dbf fields). Not much luck so far, but I've found ListIconGadget() to play with. It would involve reference arrays to contain cell xy positions for mouse location, etc. Haven't been able to locate anything better so far. Have written browse in Clipper, so have something to start with.
ListIconGadget() seems only able to directly click onn the 1st column, so need to develop something to expand upon this.
If you have any ideas, would really appreciate.

That's normal, once the index is created, Cheetah will keep it up to date as long as you remember to open them.nicksteel wrote:I've found that I only have to reindex immediately after creating. After that, it opens and runs without.
You probably won't find anything like that, instead you'll have to use a general purpose grid control such as eGrid (http://www.purecoder.net/egrid.htm) or Microsoft's FlexGrid, and write code to fill it with data from the database.nicksteel wrote:My current quest is for a browse function ( a data grid with dbf fields).
Thanks,
Like a dummy, I'm going to have a go at playing with ListIconGadget() and trying some other ideas. I always wrote low level browse in Clipper by cutting/pasting screen areas and painting "new" areas only with functions containing attributes from arrays. I should be able to expand this concept to variable screen/font sizes. (Some of my Clipper screens were actually C graphic primatives).
Will post later if I have any success. I am only interested in vertical scrolling at present, anyway, not vertical/horizonal "spreadsheet" grids. I like doing my own functions, as I can modify them readily and only concentrate on my own immediate needs.
I probably don't know enough to realize I can't do it this way in PB, but sometimes ignorance results in something that actually works.
			
			
									
									
						Like a dummy, I'm going to have a go at playing with ListIconGadget() and trying some other ideas. I always wrote low level browse in Clipper by cutting/pasting screen areas and painting "new" areas only with functions containing attributes from arrays. I should be able to expand this concept to variable screen/font sizes. (Some of my Clipper screens were actually C graphic primatives).
Will post later if I have any success. I am only interested in vertical scrolling at present, anyway, not vertical/horizonal "spreadsheet" grids. I like doing my own functions, as I can modify them readily and only concentrate on my own immediate needs.
I probably don't know enough to realize I can't do it this way in PB, but sometimes ignorance results in something that actually works.



