Solved

Reading records in a binary file

Posted on 1998-08-12
4
150 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 84
How to Add / Edit Windows Menu 4 74
How to make an ADE file by code? 11 101
Win 10 Automation Error with .doCmd in Access 2 31
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

730 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