Thanks, Bonne - I tried, but it's the return from the function that causes a problem.
As requested, this is the code I have now, but it still lacks a proper GetField function, so I guess I shall have to go back to Tsunami, which I find a lot clumsier than MyDB.
Code: Select all
;MyDB.dll is available from http://www.mghsoft.com
;It is shareware, with a nag screen whenever a database is created or opened
;so you can check to see if it will fulfill your purpose before you buy it
; Thanks to aXend for the variant stuff
#VT_I4 = 3 ;Don't know what to use for a float variant
#VT_INT = 22 ;an integer variant
Structure VARIANT ; 16 bytes
vt.w
wReserved1.w
wReserved2.w
wReserved3.w
StructureUnion
bVal.b ; 1 byte, 8-bits
iVal.w ; 2 bytes, 16-bits
lVal.l ; 4 bytes, 32-bits
value.l ; same as lVal, defined for compatibility reasons
high.l ; 8 bytes, 64-bits
low.l
boolVal.w ; boolean TRUE ($FFFF) or FALSE ($0000), see below
bstrVal.l ; pointer to BSTR (unicode string)
scode.l ; special code, e.g. for optional parameters, see below
EndStructureUnion
EndStructure
m.VARIANT ; Define a variant structure
; define constants needed for MyDB interface
#FIELD_INTEGER = 1
#FIELD_LONG = 2
#FIELD_SINGLE = 3
#FIELD_DOUBLE = 4
#FIELD_STRING = 5
#FIELD_BOOLEAN = 6
#FIELD_BINARY = 7
#FIELD_AUTOINC = 8
#KEY_DUPLICATED = 1
#KEY_UNDUPLICATED = 2
#KEY_FIELD_CASE = 1
#KEY_FIELD_NOCASE = 2
#MODE_READ = 0
#MODE_READ_WRITE = 2
#MODE_SHARE = 64
#MODE_READ_SHARE = #MODE_READ | #MODE_SHARE
If OpenLibrary(0, "MyDB.DLL") = 0
MessageRequester("Error", "Sorry, Can't find the Database Engine", 0)
End
EndIf
DB.l = CallFunction(0, "mOpen", "test.sdb", #MODE_READ_WRITE)
If DB < 0
If CallFunction(0,"mCreateField", "Number", #FIELD_LONG) = 1
If CallFunction(0, "mCreateField", "Name", #FIELD_STRING,12) = 1
If CallFunction(0,"mCreateField", "Score", #FIELD_SINGLE) = 1
If CallFunction(0, "mCreateKey", "key_num", #KEY_UNDUPLICATED, 0) = 1
CallFunction(0, "mCreateDB", "test.sdb")
DB = CallFunction(0, "mOpen", "test.sdb", #MODE_READ_WRITE)
Debug "Database Created"
EndIf
EndIf
EndIf
EndIf
EndIf
Debug "No Of Records in Database:"
Debug CallFunction(0, "mGetRecordNum", DB)
;set up a record in the Database
;set up the key field
m\vt = #VT_INT ; this describes type of variant
m\value = 1
CallFunction(0, "mSetField", DB, m, 0)
;set up the name field using mSetFieldStr, which does not need a variant
b.s = "John Smith"
CallFunction(0, "mSetFieldStr", DB, b,1)
;set up the score field
m\vt = #VT_I4 ; a float variant (?)
m\value = 22.2
CallFunction(0, "mSetField", DB, m, 2)
CallFunction(0, "mInsert", DB)
Debug "Record Inserted"
Debug "No Of Records in Database:"
Debug CallFunction(0, "mGetRecordNum", DB)
Debug "Move to First Record"
CallFunction(0, "mMoveFirst",DB, 0)
;This is where I have my problem, that I want to use mGetField, but that function
;returns a variant, which PB will not accept back.
;CallFunction() seems to return a 4 byte integer(?).
Debug Val(PeekS(CallFunction(0, "mGetFieldStr", DB, 0)))
Debug PeekS(CallFunction(0,"mGetFieldStr", DB, 1))
Debug Val(PeekS(CallFunction(0,"mGetFieldStr", DB, 2)))
; and I just realised my float isn't working either :(
CallFunction(0, "mClose", DB)
End