Results 1 to 3 of 3

Thread: random access files

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Nr Manchester, England
    Posts
    2

    random access files

    I'm converting an old DOS program written in Borland Turbo Basic to VB.

    When using random access files, TB supports a FIELD statement which defines the field variables in the random access buffer. The FIELD statement uses the same file stream as the file being opened, so

    FIELD #1 4 AS x$, 4 AS y$

    would define the field as two variables.

    You then simply GET the record, e.g.

    rec=1000
    GET #1, rec

    which is written into the variables defined in the field.

    What has happened to the FIELD statement in VB?

    VB seems to want me to GET the field as a single variable, as in

    GET #1, temptext

    I'm trying to read the old DOS data file with VB and it keeps generating a "Bad Record Length" error. I am wondering whether or not this is because I have been unable to convert the FIELD statement?

    Any help would be much appreciated.

    Thanks in advance, David Atherton.

  2. #2
    Medicus
    Guest
    You need to use Type

    Code:
    ' In the decraration part.
    Type MyType
       X As String * 4
       Y As String * 4
    End Type
    
    ' In a procedure.
    
    Dim MT as MyType
    
    Open File$ for Random Access Read As 1 Len = Len(MT)
    
    Get #1, 1000, MT
    
    Debug.Print MT.X
    Debug.Print MT.Y
    
    Close 1
    Report any bugs to Microsoft

    DATA as been droped too, but that's a whole different story...

  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I think you have to use the User-Defined Types available in VB.
    Code:
    Public Type MyField
       X As Integer
       Y As Integer
    End Type
    
    Dim MyType As MyField
    For more details on manipulating the random access files, you can check out any tutorials on VB World or someone will help you out here.

    PS: I guess the question has been answered already. Damn this slow connection!!

    .
    Last edited by honeybee; Jul 13th, 2001 at 06:13 AM.
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width