Solved

Reading records in a binary file

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
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.
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now