Create Random access file in VB that is same format as NSBasic

Posted on 2007-08-12
Last Modified: 2013-11-18
I am trying to convert a program that was using an Access database that synchronized between a PocketPC and Microsoft Access. What I am wanting to do is create a random access file in VB that can be copied down to the handheld and then read in by record number. The problem is that when I create a random file in VB, the format doesn't match that of a random file created by NSBasic (which is supposed to be VB script). Is there anyone familiar enough with both of these programs that can tell me how to create a random file that can be read by both programs?
Here is my basic syntax for opening the file in VB:
Open myFile For Random As #1 Len = 500
Here is my syntax for opening the file in NSBasic:
file.Open myFile, 4, 2, 3, 500
Question by:Mach1pro
    LVL 44

    Expert Comment

    the 2 in your file.Open statement indicates it is being opened for write operations.  What do your VB output statements look like and what do your NSBasic read statements look like?
    LVL 48

    Expert Comment

    The SEEK command is used for getting/setting a position within a File.  It takes as a parameters an open file handle.

    Say you have a file, and you know that at position 100, there is some data that you want.  You can use the SEEK command to immediately set a position in the file, so that the next read from the file, starts at position 100.

    You can also use the seek command to find out the current position within the file

    For all files NOT opened in Random Access mode, the seek always deals with a position within the file, counting each byte.

    For files opened in Random mode, the seek deals with a specific record number, for which records can be many bytes each.

    Seek #filehandle,position to set the location
    Seek(filehandle) to get the location

    Dim fh as long
    Dim n as long

    fh = FreeFile

    Open "file" for binary access read as #fh 'open file ready only
    Seek #fh, 100
    get #fh,, n 'read a long value from the file

    LVL 6

    Author Comment

    Here is the code from NSBasic used to create a one record random access file.

     Dim myArray
       Redim myArray(3)
      file.Open strDir, 4, 2, 3, 500
      myArray(1) = 2
      myArray(2) = "75"
      file.Put myArray

    Here is a link to the file that it created:
    NOW... How do I write the VB6 syntax to read these values back in on the desktop???
    LVL 44

    Accepted Solution

    Dim myArray
    ReDim myArray(3)
    Open strDir For Random As #1
    Get #1, 1, myArray
    Close #1

    After these statements, the myArray variable has these values, as displayed in the Immediate/Debug window:

    ?myarray(0), myarray(1), myarray(2)
                               2            75


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    With Windows Embedded Handheld, called Windows Mobile, Microsoft re-designed the user interface. The Start Icon moved down to the bottom, inside the menu bar area.   If you need to hide the Start Icon and/or the SIP (soft input panel, softwar…
    A short article about problems I had with the new location API and permissions in Marshmallow
    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…
    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…

    755 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

    21 Experts available now in Live!

    Get 1:1 Help Now