Cheetah Indexing with PureBasic

For everything that's not in any way related to PureBasic. General chat etc...
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Cheetah Indexing with PureBasic

Post by nicksteel »

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
Last edited by nicksteel on Tue Jun 12, 2007 8:07 pm, edited 2 times in total.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

?????
Tranquil
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

I get list of field for each record, but not in index order.
PaulSquires
New User
New User
Posts: 2
Joined: Sun Aug 13, 2006 3:29 am

Post by PaulSquires »

I don't really know PureBasic but I expect that you are not assigning the index handle to a variable?

Code: Select all

 xdbOpenIndex("curr1.idx", hdb1)
Should be: ?????

Code: Select all

curr1 = xdbOpenIndex("curr1.idx", hdb1)
...and...

Code: Select all

xdbReindexAll(curr1, 0) 
Should be: ?????

Code: Select all

xdbReindexAll(hdb1, 0) 
Just a guess.
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

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:

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() 

End
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

Thanks, 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.
Last edited by nicksteel on Wed Jun 13, 2007 2:36 pm, edited 2 times in total.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

I don't know the rest of your code, but try this :

Procedure.s xdbTempFileName()
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

gnozal wrote:I don't know the rest of your code, but try this :

Procedure.s xdbTempFileName()
Using code exactly as modified by Tipperton above.

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
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

nicksteel wrote:
gnozal wrote:I don't know the rest of your code, but try this :
Procedure.s xdbTempFileName()
The code is exactly as modified by Tipperton above.
I don't have the include.
nicksteel wrote:Where do I insert this?
Line 776 ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

When I add:


xdbReindexAll(hdb1, 0)

it works!

I get indexed list of records in console window. Without the xdbReindexAll(), I get nothing.

Thanks guys! (until my next stumble in the world of PureBasic) :shock:
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

nicksteel wrote:When I add:

xdbReindexAll(hdb1, 0)

it works!
Interesting...

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... :(
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

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. :D
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

nicksteel wrote:I've found that I only have to reindex immediately after creating. After that, it opens and runs without.
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:My current quest is for a browse function ( a data grid with dbf fields).
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
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

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.
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

It might work, I read somewhere that a grid was just a bunch of list gadgets placed side-by-side...

Don't know how true that remark is but if you're not looking for horizontal scrolling, it might be very true...

Have fun! :mrgreen:
Post Reply