Hi!
I don't understand what is going on:
I'm writting a macro in Excel to read data from a .btr file, so I created a class called clssFicheroBtr where I have written the necessary code to operate with the .btr file. I'm working under PSQL7.
What it happens is that once the file is Opened correctly (with 0 BTRCALL operation), when any Get/Step (12, 33, ...) operation is called by BTRCALL, inmediatelly the Excel crashes without any sweet message like "Hope you have enjoyed the dedicated time..." or something like that. I have tried with Access too, but it happens exactly the same. I know it works, because I get success with other test .btr files, and I'm sure I'm using the correct record size, and almost sure I'm using the correct parametrers, but I don't know what is going on.
Does anybody know what happens? Thanks a lot.
The
VB-code I'm using is this one:
PHP Code:
DefInt A-Z
Const DEFKeyBufLen = 255
Private Declare Function BTRCALL Lib "wbtrv32.dll" (ByVal OP, ByVal Pb$, Db As Any, DL As Integer, Kb As Any, ByVal Kl, ByVal Kn) As Integer
Public NombreFichero As String
Public RutaFichero As String
Public FicheroAbierto As Boolean
Public ClavePpal As Integer
Public Marcadores As clssMarcador
Dim iclNregistros As Long
Dim iclNumCampos As Integer
Dim iclCampos() As clssCampos
Dim KeyBufLen As Integer
Dim PosBlk$
Dim DataBuf As String
Dim DBLen As Integer
Dim KeyNum As Integer
Property Get LongReg() As Integer
Dim I As Integer
LongReg = 0
For I = 0 To NumCampos - 1
LongReg = LongReg + iclCampos(I).LongitudCampo
Next
End Property
Property Get NumCampos() As Integer
NumCampos = iclNumCampos
End Property
Property Let NumCampos(NC As Integer)
Dim i As Integer
If iclNumCampos <> 0 Then
MsgBox "Error en la propiedad NumCampos de la clase clssFicheroBtr:" + Chr(10) + _
"No se puede cambiar el número de campos una vez ya asignados", vbExclamation, "Error"
Else
ReDim iclCampos(NC - 1)
For i = 0 To NC - 1
Set iclCampos(i) = New clssCampos
Next
iclNumCampos = NC
End If
End Property
Public Function AbreFichero() As Boolean
Dim I As Integer
Dim Stat As Integer
AbreFichero = True
If Not FicheroAbierto Then
DataBuf = Space(LongReg)
DBLen = Len(DataBuf)
KeyBufLen = DEFKeyBufLen
KeyBuffer$ = RutaFichero + "\\" + NombreFichero
KeyNum = BtrOpenMode.Read_Only
Stat = BTRCALL(Btr.Abrir, PosBlk$, DataBuf, DBLen, ByVal KeyBuffer$, KeyBufLen, KeyNum)
End If
Fin:
If Stat <> 0 Then
Beep
ErrBtr Stat, "Error en el método AbreFichero de la clase FicheroBtr.", , vbCritical, "Error"
AbreFichero = False
FicheroAbierto = False
Else
FicheroAbierto = True
StepFirst
End If
End Function
Public Sub StepFirst()
Dim Stat As Integer
DataBuf = Space(LongReg)
DBLen = LongReg
KeyBufLen = DEFKeyBufLen
KeyBuffer$ = Space(KeyBufLen)
KeyNum = 0
Stat = BTRCALL(Btr.StepFirst, PosBlk$, DataBuf, DBLen, KeyBuffer$, KeyBufLen, KeyNum)
If Stat <> 0 Then
ErrBtr Stat, "Error en el método StepFirst de la clase FicheroBtr.", , vbExclamation, "Error"
Else: Buf_Mem
End If
End Sub
Public Sub MoveFirst()
Dim Stat As Integer
DataBuf = Space(LongReg)
DBLen = LongReg
KeyBufLen = DEFKeyBufLen
KeyBuffer$ = Space(KeyBufLen)
KeyNum = ClavePpal
Stat = BTRCALL(Btr.GetFirst, PosBlk$, DataBuf, DBLen, ByVal KeyBuffer$, KeyBufLen, KeyNum)
If Stat <> 0 Then
ErrBtr Stat, "Error en el método MoveFirst de la clase FicheroBtr.", , vbExclamation, "Error"
Else: Buf_Mem
End If
End Sub
Private Sub Class_Initialize()
iclNumCampos = 0
FicheroAbierto = False
KeyBufLen = DEFKeyBufLen 'Por defecto la longitud de clave está a 255
ClavePpal = 0 'Por defecto se utiliza el índice 0
PosBlk$ = Space$(128)
End Sub