Page 1 of 2
Posted: Sun Jan 26, 2003 6:29 pm
by BackupUser
Restored from previous forum. Originally posted by redacid.
Hello,
has anyone tried to use the Tsunami Record Manager DLL within PureBasic?
I don't really know if it's even possible to use it. But I wasn't very successful when I tried it myself.
You can find more about it at
http://www.trm-ug.com/.
Some sampel-source-code for PB would be very appreciated.
regards,
Redacid
---
Viva Los Tioz!
registered user of PB3.50 on WinXP SP1
Posted: Sun Jan 26, 2003 9:03 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.
Hi,
Sounds great to manage a database without the need of all that huge files usually needed.
Just translate the VB code samples at
http://www.trm-ug.com/samples.htm
I dont test it as i dont download the dll, but looking at one sample, its not difficult, just need to copy all the stuff and transalte it to PureBasic.
OverWrite = 1
FileName$ = "C:\My Data\Customers.dat"
If OpenLibrary(1, "wavemp3.dll")
Result = CallFunction(1, trm_Create,FileName$, FileDef$,OverWrite)
If Result& Then
Messagerequester("Error","Error " + str(Result),0)
;display message
Else
;file created successfully
Messagerequester("Msg","File created succesfully",0)
EndIf
EndIf
Best Regards
Ricardo
Dont cry for me Argentina...
Posted: Sun Jan 26, 2003 9:50 pm
by BackupUser
Restored from previous forum. Originally posted by redacid.
That's what I tried - without success...
regards,
Redacid
---
Viva Los Tioz!
registered user of PB3.50 on WinXP SP1
Posted: Sun Jan 26, 2003 10:15 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.
Originally posted by redacid
That's what I tried - without success...
I repeat that i dont test it, but after a speed review, the error could be:
1.- The string must be 25 bytes one
Dim SegName As String * 25
In PB will be
SehName.b[25]
2.- FileDef$
Its not difficult to translate the way they make it
I make a fast translation... hope dont make a mistake:
Code: Select all
KeyLen.b[6]
KeyLen1.b[43]
PageSize = 1; page size = 1K
Compress = 1; record compression = yes
Segments = 2; 2 key segments will be defined
FileDef$ = Chr(PageSize) + Chr(Compress) + Chr(Segments)
SegName = "Account Number" ; Must be 25 bytes long
KeyNo = 1
KeyPos = 1; key segment starts at byte #1 in record
KeyLen = 6; key segment is 6 bytes long
;I dont know if MOD 256 its possible in PureBasic
FileDef$ = FileDef$ + SegName + Chr(KeyNo) + Chr(KeyPos Mod 256) +Chr(KeyPos \ 256) +Chr(KeyLen) +Chr(KeyFlags)
; add the "Name" key definition (1 segment)
SegName = "Last Name, First Name, MI"
KeyNo = 2
KeyPos = 7 ; key segment starts at byte #7 in record
KeyLen1 = 43; key segment is 43 bytes long
KeyFlags = 0
FileDef$ = FileDef$ +SegName + Chr(KeyNo) +Chr(KeyPos Mod 256) +Chr(KeyPos \ 256) + Chr(KeyLen1) + Chr(KeyFlags)
3.- #NO_COMPRESSION + #NO_DUPLICATES
You need to search the values of the Constants, cause i cant found it in the VB sample. Im sure its on the Help file.
Best Regards
Ricardo
Dont cry for me Argentina...
Posted: Sun Jan 26, 2003 10:22 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.
Adding a record file is pretty straight
Code: Select all
' assign "field" values
AcctNo$ = " 1234"
FullName$ = "JONES, TOM "
Street$ = "345 E HOLLYWOOD AVE "
City$ = "BEVERLY HILLS "
State$ = "CA"
Zip$ = "90210"
' concatenate the "fields" to create the record string
Record$ = AcctNo$ & FullName$ & Street$ & City$ & State$ & Zip$
Result& = trm_Insert(hFile&, Record$)
If Result& Then
Msg$ = "Error inserting record:" & Str(Result&)
' display message
Else
' record inserted successfully
End If
The VB samples -if you take a look of all them- are not such complicated.
Only Create a new file is a little more com plicated, but the other ones are straight ones.
http://www.trm-ug.com/samples.htm
Best Regards
Ricardo
Dont cry for me Argentina...
Posted: Tue Jun 17, 2003 7:40 pm
by TerryHough
Has anyone been able to get Tsunami to work with PB?
I sure would appreciate know if you have, and an example code would
be nice.
TIA,
Terry
Posted: Tue Jun 17, 2003 9:23 pm
by TerryHough
Here is the VB code example for Tsunami Record Manager Create file.
I took a shot at translating it, but since I have zero knowledge of VB and
not much more of PB, however it doesn't work. Anybody care to try to
help?
The Tsunami DLL and sample codes are available at
http://www.trm-ug.com/
Code: Select all
' each key segment's SegName variable MUST be 25 bytes long
Dim SegName As String * 25
' construct the File Definition string --------------------------
PageSize& = 1 ' page size = 1K
Compress& = 1 ' record compression = yes
Segments& = 2 ' 2 key segments will be defined
FileDef$ = Chr(PageSize&) & _
Chr(Compress&) & _
Chr(Segments&)
' add the "Account Number" key definition (1 segment)
SegName = "Account Number"
KeyNo& = 1
KeyPos& = 1 ' key segment starts at byte #1 in record
KeyLen& = 6 ' key segment is 6 bytes long
KeyFlags& = NO_COMPRESSION + NO_DUPLICATES
FileDef$ = FileDef$ & _
SegName & _
Chr(KeyNo&) & _
Chr(KeyPos& Mod 256) & _
Chr(KeyPos& \ 256) & _
Chr(KeyLen&) & _
Chr(KeyFlags&)
' add the "Name" key definition (1 segment)
SegName = "Last Name, First Name, MI"
KeyNo& = 2
KeyPos& = 7 ' key segment starts at byte #7 in record
KeyLen& = 43 ' key segment is 43 bytes long
KeyFlags& = 0
FileDef$ = FileDef$ & _
SegName & _
Chr(KeyNo&) & _
Chr(KeyPos& Mod 256) & _
Chr(KeyPos& \ 256) & _
Chr(KeyLen&) & _
Chr(KeyFlags&)
' create the Tsunami file ---------------------------------------
OverWrite& = 1
FileName$ = "C:\My Data\Customers.dat"
Result& = trm_Create(FileName$, FileDef$, OverWrite&)
If Result& Then
Msg$ = "Error creating file:" + Str(Result&)
' display message
Else
' file created successfully
End If
Here is my attempt which fails to work:
Code: Select all
#NO_DUPLICATES = 2
#NO_COMPRESSION = 4
Procedure Mod(a,b)
ProcedureReturn a-(a/b)*b
EndProcedure
OpenResult.l = OpenLibrary(1, "TRM.DLL")
If OpenResult
FuncResult.l = IsFunction(1, "trm_Create")
If FuncResult
MessageRequester("Info","TRM function is available: "+"trm_Create "+Str(FuncResult),#MB_ICONWARNING)
; each key segment's SegName variable MUST be 25 bytes long
SegName.s = Space(25)
; construct the File Definition string --------------------------
PageSize = 1 ; page size = 1K
Compress = 1 ; record compression = yes
Segments = 2 ; 2 key segments will be defined
FileDef$ = Chr(PageSize) + Chr(Compress) + Chr(Segments)
; add the "Account Number" key definition (1 segment)
SegName = "Account Number"
KeyNo = 1
KeyPos = 1 ; key segment starts at byte #1 in record
KeyLen = 6 ; key segment is 6 bytes long
KeyFlags = #NO_COMPRESSION + #NO_DUPLICATES
FileDef$ = FileDef$ + SegName + Chr(KeyNo) + Chr(Mod(KeyPos,256)) + Chr(KeyPos / 256) + Chr(KeyLen) + Chr(KeyFlags)
; add the "Name" key definition (1st segment)
SegName = "Last Name, First Name, MI"
KeyNo = 2
KeyPos = 7 ; key segment starts at byte #7 in record
KeyLen = 43 ; key segment is 43 bytes long
KeyFlags = 0
FileDef$ = FileDef$ + SegName + Chr(KeyNo) + Chr(Mod(KeyPos,256)) + Chr(KeyPos / 256) + Chr(KeyLen) + Chr(KeyFlags)
; create the Tsunami file ---------------------------------------
OverWrite = 1
FileName$ = "Customer.dat"
CreateResult = CallFunction(1,"trm_Create",FileName$, FileDef$, OverWrite)
If CreateResult
MessageRequester("Error","Error creating file:" + Str(CreateResult),0)
; display message
Else
MessageRequester("Debug","Tsunami file created successfully. " + Str(CreateResult),0)
; file created successfully
EndIf
CloseLibrary(0)
Else
MessageRequester("Error","TRM function not available: "+"trm_Create",#MB_ICONERROR)
EndIf
Else
MessageRequester("Error","Tsunami Record Manager not available.",#MB_ICONERROR)
EndIf
; ---------------- This is the main processing loop ----------------------
Repeat
EventID = WaitWindowEvent()
; ------------------- Process the menu events --------------------------
If EventID = #PB_EventMenu
Select EventMenuID() ; see which menu item was selected
Case 1 ; Import
Case 2 ; Open
Case 3 ; Save menu chosen
Case 4 ; Import Records
Case 5 ; Exit menu chosen
Quit = 1 ; Set the exit flag
EndSelect
EndIf
; ------------------ Process the gadget events -------------------------
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 1 ; Panel gadget chosen
EndSelect
EndIf
If EventID = #WM_CLOSE ; #PB_EventCloseWindow
Quit = 1
EndIf
; ------------ Insure changes are saved when quit received ---------------
If Quit = 1
If ModifiedFlg$="Y"
MessageRequester("Warning","You have not saved your modifications to the file!",#MB_ICONSTOP)
Quit=0
EndIf
EndIf
Until Quit = 1
; -------------------End of the main processing loop ---------------------
End
; ---------------------------------------------------------------------
; End of Main program code
; ---------------------------------------------------------------------
TIA,
Terry
Posted: Wed Jun 18, 2003 2:02 am
by HarryO
Terry,
Off the top of my head and looking at Ricardo's previous example,
do NOT use the 'String' (.s) type for SegName.
Try useing - 'SegName.b[25]' instead.
HarryO
Posted: Wed Jun 18, 2003 7:03 pm
by TerryHough
Thanks for your reply HarryO. Unfortunately it doesn't solve the problem.
Ricardo's quick conversion doesn't work either.
Tsunami expects a 33 byte "string" parameter passed to it defining the
file. At least one of those bytes can be a NUL which means PB doesn't
see the entire parameter
Byte 1 = Chr(PageSize) ; 1 - 8 Ascii value
Byte 2 = Chr(Compress) : #True or #False
Byte 3 = Chr(Segments) ; 1 - 128 Ascii value
Byte 4 - 28 = Description ; a 25 byte description of the key
Byte 29 = Chr(KeyNo) ; 1 - 128 Ascii value
Byte 30 - 31 = key position in string 1 - 65535
shown as Chr(Mod(KeyPos,256)) + Chr(KeyPos / 256)
Byte 32 = Chr(KeyLen) ; 1 - 255 Ascii value
Byte 33 = Chr(KeyFlags) : a bit mask created by adding possible flag
values
Byte 30 is most often a value of 0, so PB can' t handle this entire
parameter as a string.
Anybody know a way to pass this parameter in a CallFunction()?
such as:
CreateResult = CallFunction(1,"trm_Create",FileName$, KeyDef$, OverWrite)
Posted: Thu Jun 19, 2003 2:37 am
by HarryO
Terry,
This looks like a structure which has a type of 'BYTE'.
Code: Select all
Strucutre FileDef
Pge_Sze.b ;Byte 1 = Chr(PageSize) ; 1 - 8 Ascii value
Compress.b ;Byte 2 = Chr(Compress) : #True or #False
Seg.b ;Byte 3 = Chr(Segments) ; 1 - 128 Ascii value
Desc.b[25] ;Byte 4 - 28 = Description ; a 25 byte description of the key
KeyNo.b ;Byte 29 = Chr(KeyNo) ; 1 - 128 Ascii value
KeyPos.b[2] ;Byte 30 - 31 = key position in string 1 - 65535
;shown as Chr(Mod(KeyPos,256)) + Chr(KeyPos / 256)
KeyLen.b ;Byte 32 = Chr(KeyLen) ; 1 - 255 Ascii value
KeyFlg.b ;Byte 33 = Chr(KeyFlags) : a bit mask created by adding possible flag values
Endstructure
Now just define a variable with this structure and pass it in place of the FileDef$ string.
As long as the values are the same you should be ok!
And even if one of the elements has a value of '0', PB won't care.
HarryO
Posted: Thu Jun 19, 2003 9:42 pm
by TerryHough
@HarryO
Thanks for the suggestion. I have already "been there, done that" without
success.
Terry
Posted: Thu Jun 19, 2003 10:36 pm
by Edwin Knoppert
Great syntax checker isn't
'Strucutre'
Posted: Fri Jun 20, 2003 3:26 am
by HarryO
Spelign was not my graetset stregnht! 8O
HarryO (sometimes it amazes me that I can spel my name)
Posted: Fri Jun 20, 2003 11:34 am
by LarsG
Tehn I tink yuo nead a crahs course ni egnlish...
I cna hepl you witt taht!!!

Posted: Wed Jul 09, 2003 6:57 pm
by Kale
hmmm. i can't seem to get Tsunami working with PB either

which is a pity, it looks really nice and small
Anyone else care to have a go?