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