Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2006
    Posts
    9

    Unanswered: Error instruction at 0x7c9111e0. Memory cannot be read while using BTRCALL

    Hi,

    I'm using PSQL7 WXP and I've tried to access to a btr file using BTRCALL functions in a VB application (to perform speed instead of using ODBC drivers), but I don't understand what is going on.

    It seems the program opens and reads the file correctly and if it is run step by step, it runs ok, reading each record ok and ends ok, but if it runs in one step, or sometimes when I try to wath some variables, it crashes with the error

    "The instruction at "0x7c9111e0" referenced memory at "0x30303024". The memory could not be "read". Click OK to terminate the program..."

    and there is no possibility to start the debugger when I click cancel!!

    Any idea on what is going on?
    Thanks so much!

  2. #2
    Join Date
    Dec 2001
    Posts
    1,109
    Provided Answers: 4
    Usually the "memory cannot be read" message is related to an unitialized variable. Post your code.
    Mirtheil Software
    Certified Pervasive Developer
    Certified Pervasive Technician
    Custom Btrieve/VB development
    http://www.mirtheil.com
    I do not answer questions by email. Please post on the forum.

  3. #3
    Join Date
    Aug 2006
    Posts
    9

    Code

    The structure of the program is that from the main module I try to count the number of boxes of a btr table. I have put the btr functions (open, movefirst, movenext, stopclient, closefile, recordcount) in a class module that returns the key of the record just read and gives the data in a property called data.
    The form in the main module is loaded to see something when it is run as an exe file.
    I have attached the code as well in a zip file.

    Here you can find the code:

    This is the main module:

    Code:
    Dim CodigoLinea As String
    Dim TV As New TablaVel
    Dim rs(20) As String
    Dim lc(20) As Integer
    
    Dim NumCajas As Long
    Dim Producto As String
    
    Public Sub Main()
    On Error GoTo ErrMn
    
        Dim i As Integer
        Dim msg As String
        
        CodigoLinea = "01"
        
        frmEfiPro.Show
        
        IniCampos
        
        With TV
    '        .RutaFichero = "\\esmlsv303\ConPro\ConPro"
    
            .RutaFichero = "C:\Probas Betrieve\ConPro"
            .NombreFichero = "hpco" + VBA.Format$(Now, "YY") + CodigoLinea + ".btr"
        
            .ClavePpal = 4
            
            If Not .AbreFichero Then
                .StopClient
                End
            End If
        '    MsgBox "Recordcount: " & VBA.Format(TablaVel.RecordCount, "#,###"), vbInformation, "Info"
            
            NumCajas = 0
            Producto = ""
            
            msg = "Fecha y hora iniciales: 20060305 06:00:00" & VBA.Chr(10) & _
                  "Fecha y hora finales:   20060312 18:00:00" & VBA.Chr(10)
            While ContarCajasProducto("20060307", "06:00:00", "20060312", "18:00:00")
                msg = msg & VBA.Chr(10) & "Producto: " & Producto & " Cajas: " & NumCajas
            Wend
            
            msg = msg & VBA.Chr(10) & "Producto: " & Producto & " Cajas: " & NumCajas
            MsgBox msg
            .StopClient
            .CloseFile
        End With
        
        End
        
    ErrMn:
        MsgBox "Error en Main: " & Chr(10) & Err.Description & Chr(10) & _
            vbCritical, "Error: " & Err.Number
        End
    
    End Sub
    
    Private Sub IniCampos()
        lc(0) = 8:   lc(1) = 20:
        lc(2) = 8:   lc(3) = 8:
        lc(4) = 8:   lc(5) = 8:
        lc(6) = 2:   lc(7) = 3:
        lc(8) = 10:  lc(9) = 2:
        lc(10) = 20: lc(11) = 1:
        lc(12) = 2:  lc(13) = 8:
        lc(14) = 10: lc(15) = 16:
        lc(16) = 1:  lc(17) = 4:
        lc(18) = 5:  lc(19) = 10
    End Sub
    
    Public Function ContarCajasProducto(FechaIni As String, HoraIni As String, FechaFin As String, HoraFin As String) As Boolean
    On Error GoTo ErrCC
        Dim Key As String
        Dim FechaHoraFin As Date
        
        Key = 0
        NumCajas = 0
        
        While Key <> "-1"
            If Producto = "" Then
                Key = TV.PrimerRegistro("N" + FechaIni + HoraIni)
            Else
                Producto = rs(TVfld.Producto)
                Key = TV.SiguienteRegistro
            End If
            
            If Key = "-1" Then 'EOF
                ContarCajasProducto = False
                Exit Function
            ElseIf Key = "" Then
                End
            Else
                Buf_Mem TV.Data
                If Producto = "" Then
                    Producto = rs(TVfld.Producto)
                End If
                
                FechaHoraFin = "N" + FechaFin + HoraFin
                
                If StrComp(Key, FechaHoraFin, vbTextCompare) = 1 Then
                    ContarCajasProducto = False
                    Exit Function
                ElseIf rs(TVfld.Producto) <> Producto Then 'Producto diferente
                    ContarCajasProducto = True
                    Producto = rs(TVfld.Producto)
                Else 'Seguir contando
                    NumCajas = NumCajas + Val(rs(TVfld.NCajas))
                End If
            End If
        Wend
        
        Exit Function
    ErrCC:
        MsgBox "Error en ContarCajas: " & Chr(10) & Err.Description & Chr(10) & _
            "Data: " & Resultado, vbCritical, "Error: " & Err.Number
        End
    End Function
    
    
    Private Sub Buf_Mem(Data As String)
    'Separa los datos de la variable Dat$ en los campos correspondientes y los pone en Var(I)
        On Error GoTo ErrBM
        
        Dim posi As Integer
        Dim i As Integer
        
        For i = 0 To 19
            rs(i) = Space(lc(i))
        Next
        
        posi = 1
        For i = 0 To 19
            rs(i) = Mid$(Data, posi, lc(i))
            posi = posi + lc(i)
        Next i
        
        Exit Sub
        
    ErrBM:
        MsgBox "Error en Buf_Mem: " & Chr(10) & Err.Description & Chr(10) & _
            "Data: " & Data & Chr(10) & "i: " & i & "; posi: " & posi & "; rs(i): " & rs(i) & "; lc(i): " & lc(i), _
            vbCritical, "Error: " & Err.Number
        End
    End Sub
    And this is the class TablaVel, where the btr file is read (just posted what it crashes because if not the post was too long):

    Code:
    DefInt A-Z
    
    Dim DataBuf As CustRowType
    
    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
    
    
    Dim KeyBufLen As Integer
    Dim PosBlk$
    Dim DBLen As Integer
    Dim KeyNum As Integer
    Dim KeyBuffer$
    
    Property Get Data() As String
        Dim b As Variant
        
        Data = ""
        For Each b In DataBuf.buf
            Data = Data & Chr(b)
        Next
    End Property
    
    Public Function PrimerRegistro(Clave As String) As String
        Dim stat As Integer
    
        DBLen = Len(DataBuf)
        KeyBuffer$ = Clave
        KeyBufLen = Len(KeyBuffer$)
        KeyNum = ClavePpal
        stat = BTRCALL(Btr.GetGreaterEqual, 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
            PrimerRegistro = KeyBuffer$
        End If
    End Function
    
    Public Function SiguienteRegistro() As String
        Dim stat As Integer
    
        stat = 0
        DBLen = Len(DataBuf)
        KeyBufLen = DEFKeyBufLen 'Len(KeyBuffer$)
        KeyNum = ClavePpal
        
        stat = BTRCALL(Btr.GetNext, PosBlk$, DataBuf, DBLen, ByVal KeyBuffer$, KeyBufLen, KeyNum)
        
        Select Case stat
        Case 9
            SiguienteRegistro = "-1"
            Exit Function
        Case 0
            SiguienteRegistro = KeyBuffer$
        Case Else
            ErrBtr stat, "Error en el método MoveFirst de la clase FicheroBtr.", , vbExclamation, "Error"
        End Select
    End Function
    And here you can find part of the global definitons (the post was too long):

    Code:
    'Enums globales
    
    Public Enum TVfld
        N_Registro = 0 ' As String * 8
        Producto = 1 'As String * 20
        Fecha = 2 'As String * 8
        Hora = 3 'As String * 8
        VelTeorica = 4 'As String * 8
        VelReal = 5 'As String * 8
        OperaLinea = 6 'As String * 2
        Maquina = 7 'As String * 3
        CanalCuenteo = 8 'As String * 10
        CodContador = 9 'As String * 2
        ObjContado = 10 'As String * 20
        Rto_SN = 11 'As String * 1
        Linea = 12 'As String * 2
        ValAnterior = 13 'As String * 8
        NLote = 14 'As String * 10
        FechaHora = 15 'As String * 16
        Enviado = 16 'As String * 1
        TmpoComputado = 17 'As String * 4
        NCajas = 18 'As String * 5
        Libres = 19 'As String * 10
    End Enum
    There are other functions you can find in the zip file, as the error management or date conversion.
    Attached Files Attached Files

  4. #4
    Join Date
    Aug 2006
    Posts
    9

    Corrected not declared variables but still the same error

    I have found some non declared variables but still have the same error.
    Attached Files Attached Files

  5. #5
    Join Date
    Dec 2001
    Posts
    1,109
    Provided Answers: 4
    Attached is some code that I got from Pervasive a while back. It doesn't use a class but shows how to call the Btrieve API from VB. It shows how to open a file, perform a Stat operation, read all of the records, and update them.
    It should help you find out what's wrong in your code.
    Attached Files Attached Files
    Mirtheil Software
    Certified Pervasive Developer
    Certified Pervasive Technician
    Custom Btrieve/VB development
    http://www.mirtheil.com
    I do not answer questions by email. Please post on the forum.

  6. #6
    Join Date
    Aug 2006
    Posts
    9

    Still an error but when I close the application

    Thanks very much for the code.
    There is still an error, but when the application is closed.
    I have the same error whe I close the DDF Ease (the database manager of Pervasive) but nothing that can stop now reading the files.
    Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •