Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading records in a binary file

Posted on 1998-08-12
4
Medium Priority
?
153 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 120 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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