Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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

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
0
Mach1pro
Asked:
Mach1pro
  • 2
1 Solution
 
aikimarkCommented:
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?
0
 
Mikal613Commented:
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

0
 
Mach1proAuthor Commented:
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
file.close

Here is a link to the file that it created: http://www.gadatapro.com/tlcomp.txt
NOW... How do I write the VB6 syntax to read these values back in on the desktop???
0
 
aikimarkCommented:
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

?IsEmpty(myarray(0))
True
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now