Solved

Reading records in a binary file

Posted on 1998-08-12
4
146 Views
Last Modified: 2011-09-20
I get an error in my Get statement when I try to compile my program.  My program is supposed to read a record from a binary file.  The error says:

       Can't Get or Put an object reference variable or a variable of user-defined type containing an object reference

I don't see or I can't identify any object reference in my user-defined type.  The following is the code:

Enum TCategory
    DFAULT
    NOUN
    PRO
    ADVERB
    ADJECTIVE
    VRB
    ARTICLE
    INDEF_ART
    CONJ
    PREPOSITION
    SUFFIX
    PREFIX
End Enum

Type TMeaning
    TWord As String * 50
    Category As TCategory
    Attrib1 As Integer
End Type

Type TElement
    Word As String * 20
    Meaning0 As TMeaning
    Meaning1 As TMeaning
    Meaning2 As TMeaning
    Meaning3 As TMeaning
    Meaning4 As TMeaning
    Meaning5 As TMeaning
    Meaning6 As TMeaning
    Meaning7 As TMeaning
    Meaning8 As TMeaning
    Meaning9 As TMeaning
    Meaning10 As TMeaning
    Meaning11 As TMeaning
    Meaning12 As TMeaning
    Meaning13 As TMeaning
    Meaning14 As TMeaning
    Meaning15 As TMeaning
    Meaning16 As TMeaning
    Meaning17 As TMeaning
    Meaning18 As TMeaning
    Meaning19 As TMeaning
End Type
      
Dim LookForElement As TElement, MaxSize, RecordNumber

Open FileName For Binary Access Read Lock Read As #1 Len = Len(LookForElement)

 ...

RecordNumber = 1

 ...

Seek #1, RecordNumber
Get #1, ,  LookForElement          ' THIS IS WHERE I GET THE ERROR

 ...


What's wrong with my code?
0
Comment
Question by:wsanchez
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:swilt
ID: 1468686
The compilier is telling you that it cannot compile because LookForElement is a user defined type and the get #1 statement cannot handle user defined types !

    Dim LookForElement As TElement, MaxSize, RecordNumber
    Dim sBuf As String
   
    Open "C:\Temp.bin" For Binary Access Read Lock Read As #1 Len = Len(LookForElement)
   ...
    RecordNumber = 1
   ...

    Seek #1, RecordNumber
    Get #1, , sBuf

But then you have to chop up sBuf into LookForElement
0
 

Author Comment

by:wsanchez
ID: 1468687
Adjusted points to 30
0
 

Author Comment

by:wsanchez
ID: 1468688
thank you for the suggestion, swilt, but I believe the get statement can handle user-defined types.  There is an example of the get statement using a user-defined type in the VB Help.  My problem is why it doesn't work for my code.
0
 
LVL 2

Accepted Solution

by:
swilt earned 30 total points
ID: 1468689
Change Category to an Integer and it will compile, it does not like enumerated types

Type TMeaning
        TWord As String * 50
        Category As Integer
        Attrib1 As Integer
End Type

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question