Solved

Reading records in a binary file

Posted on 1998-08-12
4
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 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