Hi, ive bought dark data and have been playing around with it, it does all I need to do in the example program, however when I try to take the code from that project and apply it in a simple learning exercise I cant seem to get it to behave.
im trying to build a very simple database to get my head around it, here is the code.
//create file for key search
kfs create 1,"model_no.kfs",6,0,0
//create file to hold data
dfs create 2,"model_list.dat",0
//add some fields to my database
DFS Add Field 2, "number"
DFS Add Field 2, "posx"
DFS Add Field 2, "posy"
DFS Add Field 2, "posz"
DFS Add Field 2, "yrot"
DFS Add Field 2, "scale"
DFS finish 2
//for loop to add some random data
for x = 1 to 100
posx = rnd(500)
posy = rnd(50)
posz = rnd(500)
yrot = rnd(360)
scale = rnd(100)
record = DFS Add(2)
//adding data to fields in data file
DFS Put 2, "number", x
DFS Put 2, "posx", posx
DFS Put 2, "posy", posy
DFS Put 2, "posz", posz
DFS Put 2, "yrot", yrot
DFS Put 2, "scale", scale
DFS Save 2, record
//adding data to key search file
KFS Add 1, str$(x), record
next x
//for loop to retrieve data
for x = 1 to 100
//find record in key search, which is the loop number
record = kfs find(1, str$(x))
// load record from data file
DFS Load 2, record
//extract data from fields
number = DFS Get(2, "number")
posx = DFS Get(2, "posx")
posy = DFS Get(2, "posy")
posz = DFS Get(2, "posz")
yrot = DFS Get(2, "yrot")
scale= DFS Get(2, "scale")
//print data to screen
print number
print posx
print posy
print posz
print yrot
print scale
wait key
cls
next x
//close system to preserve data
KFS Close 1
DFS Close 2
end
it seems very straight forward, however all data is returned as 0
edit: fixed one problem with code, but still no data/:edit
can anyone good with dark data help me figure out what I am missing.
thankyou.
update:
ok, ive made some breakthroughs, Still not clear enough to post a fix for this, but at this point I can say that the issues is not using string variables.
Dark data seems to operate with string variables for its internal structure.
Even if your value is an int or float etc, you still have to use string variables.
Just convert back after extracting the data from the database.
if you use an int then you will just get zeros for all your data.
I will post fixed code when i get the above version working.
but here's a working example adapted from TGC store Dark data page.
Rem Project: Dark Basic Pro Project
Rem Created: Saturday, February 18, 2012
Rem ***** Main Source File *****
//make a file to hold data=================================================
DFS Create 1, "test.dat",0
//add some fields to the data -all must be floats or strings================
DFS Add Field 1, "string 6 as number"
DFS Add Field 1, "string 6 as posx"
DFS Add Field 1, "string 6 as posy"
DFS Add Field 1, "string 6 as posz"
DFS Finish 1
//make some key lookup files=================================================
KFS Create 2, "CheckNumber.kfs", 4, 0, 0 `0 - unique
KFS Create 3, "Checkposx.kfs", 10, 1, 0 `1 - non unique
KFS Create 4, "Checkposz.kfs", 20, 1, 0
//for loop to insert random data=====================================
maximum = 100
for i = 1 to maximum
number$ = str$(i)
posx$ = str$(rnd(500))
posy$ = str$(rnd(50))
posz$ = str$(rnd(500))
// add a new record to the database========================================
record = DFS Add(1)
// add data to the new record==============================================
DFS Put 1, "number", number$
DFS Put 1, "posx", posx$
DFS Put 1, "posy", posy$
DFS Put 1, "posz", posz$
// save new record=======================================================
DFS Save 1, record
//save key file data=====================================================
KFS Add 2, number$, record
KFS Add 3, posx$, record
KFS Add 4, posz$, record
next i
// close files=================================================================
DFS Close 1
KFS Close 2
KFS Close 3
KFS Close 4
`*** New program ***
`Open the database
DFS Open 1, "test.dat"
`Open the indexes
KFS Open 2, "CheckNumber.kfs"
KFS Open 3, "Checkposx.kfs"
KFS Open 4, "Checkposz.kfs"
`Show off
print "List by number": print "==============": print
GetList(2)
print "List by xpos": print "============": print
GetList(3)
print "List by zpos": print "=============": print
GetList(4)
print "dfs list"
naturalist()
`Close the database
DFS Close 1
`Close the indexes
KFS Close 2
KFS Close 3
KFS Close 4
wait key
end
function GetList(idx)
KFS Reset idx `Point to the start of the table.
for x = 1 to KFS Count(idx)
`Get the page number found in the index
record = KFS Next(idx)
`Load the page
DFS Load 1, record
`Get the information from each field
number = int(DFS Get(1, "number"))
xpos = int(DFS Get(1, "posx"))
ypos = int(DFS Get(1, "posy"))
zpos = int(DFS Get(1, "posz"))
`Display it
print number; " "; xpos; " "; ypos; " "; zpos; " "
wait 200
next x
print: print: print "Press any key to continue..."
wait key
endfunction
//extra function to test straight DFS lookup
function naturalist()
for x = 1 to 100
DFS Load 1, x
`Get the information from each field
number = int(DFS Get(1, "number"))
xpos = int(DFS Get(1, "posx"))
ypos = int(DFS Get(1, "posy"))
zpos = int(DFS Get(1, "posz"))
`Display it
print number; " "; xpos; " "; ypos; " "; zpos; " "
wait 200
next x
print: print: print "Press any key to continue..."
wait key
endfunction
I found it difficult to learn the dark data syntax with so many functions and subroutines to jump through.
I hope this is helpful to other dark data beginners.
Sometimes I like to use words out of contents