Dec 222017
This is a sample application illustrates the coding needed to use a Random Access file in conjunction with a Grid Control using Visual Basic.
File RANDGR.ZIP from The Programmer’s Corner in
Category BASIC Language
This is a sample application illustrates the coding needed to use a Random Access file in conjunction with a Grid Control using Visual Basic.
File Name File Size Zip Size Zip Type
RANDGRID.BAS 99 63 deflated
RANDGRID.DOC 7205 3064 deflated
RANDGRID.FRM 11043 5032 deflated
RANDGRID.MAK 85 66 deflated
TPCREAD.ME 199 165 deflated

Download File RANDGR.ZIP Here

Contents of the RANDGRID.DOC file

RandGrid 1.0
Copyright 1991 Nelson Ford, PsL
P.O.Box 35705 Houston, TX 77235-5705


1. You may freely use and distributed this code in applications in which
this code makes up a small part of the program.

2. You may freely distribute this code to other VB programmers, including
uploading it to BBS's or for a disk fee, as long as all related files
are distributed together and without any changes.

All I ask for the use of this code is that if you find a better way to do
something than the methods I've used, I would appreciate your letting me know.


Visual Basic is required, of course, and GRID.VBX.

GRID.VBX is not included with this set of files. It is available on the MSLANG
Forum's Data Libraries for downloading or you can get them on disk from PsL.
(See the end of this file.)


This is a sample application whose only purpose is to illustrate the coding
needed to use a Random Access file in conjunction with a Grid Control. Even if
you are using one but not the other, this sample code should come in handy.

The code in this program is almost identical to the code in the HugeGrid
program that links a huge array to a random access file. My testing on a
386-33 with a 1-meg disk cache shows that the response time when using a
random access file instead of a Huge Array is close enough to the same to make
using the random access file preferable.

(Note: One thing I didn't do in this sample program is save the Pointers to
disk when done. You'll need to do that in your own applications, obviously.)


The Huge Array DLL and the Grid Control VBX were produced by Microsoft and
given to beta testers, but not included with Visual Basic when released.

It appears that they are bug-free, but probably were not included because they
are not very robust. For example, getting Text out of a Grid cell by having to
change the Grid.Row and Grid.Col is a very inefficient way to do things,
neither is having to access a Huge Array like you would a data file.

Nevertheless, if you HAVE to have either an array larger than 64k (VB's usual
limit) or a Grid control - you'll be glad that MS decided to release these to
the public as freebies.


As you will see, sorting a 5000-record file takes a lot of time. However, in
your own application, you would presumably be updating pointers each time you
added a record, and would never have to sort the data.

With a sufficiently large disk cache, a random access file appears to be about
as fast as the Huge Array and has the advantage of being more secure, since
data is written to the disk when added or deleted. However, if your user is
not using a large enough cache, then performance could be seriously degraded
by using a random access disk file.

Because getting data to and from a Huge Array is more like accessing a Random
access data file than using an actual in-memory data array, the routines for
both are nearly identical.


RANDGRID.FRM/.BAS - These files should be put in a subdirectory off your VB

GRID.VBX - This file should go in your VB subdirectory.


DecrLastEl & IncrLastEl

When you delete an entry, several pointers have to be adjusted. This Sub
makes sure that everything gets done.

Sub FillGrid(StartPt, StopPt, StartRow)

This routine gets data from the File and puts it in the grid.
StartPt and StopPt are the pointer numbers to start and stop with.
StartRow says what row of the grid to start with.

Function GetEl(x)

Gets the record from the file that Pointer(x) points to.
You could format or otherwise manipulate the data at this point if needed.

ScrollUp & ScrollDown
Lets you scroll selected rows in the Grid up or down. Given the kludgy way
that data has to moved from one Grid cell to another, it may be just as quick
to use the FillGrid routine to read the data in from the File again, and
it would save all this code.


In setting up your grids, you may have to experiment (going back and forth
between design and run-time) to find the desired column widths, since I
haven't found any way to change them during design time.

Most of the VScroll values shown can be set at design time. They are included
here to make them easier to see.

For ease of coming up with a lot of different text, numbers were used to fill
the array. However, these ARE strings and when sorted, they are sorted as
strings, not as numbers. (So you will see 1.1 10.1 100.1 ... 2.1 20.1, etc.)

If you enter a number in the Text box and select Insert, it will be entered
alphabetically, not numerically. You could easily change the code to treat the
data as numbers rather than text simply by using VAL() everywhere that data
variables are used.

After loading up the array, the end of the array is displayed in the Grid. You
could just as easily pick any other part of the array for the initial display,
but don't forget to change Vscroll1.Value accordingly. (eg: If you display
elements 1 - 10, set Vscroll1.Value to 10.)

This is a QuickSort algorithm, which is one of the fastest general sorting
algorithm available. Although numeric data is used for ease of filling up an
array with different data, the numbers are store as strings and will be sorted
in string order. (eg: 10 100 1000 before 20)

Deletes a record from the File. To save time, the record is not actually
removed from the File. An array (Deleted) is set up for keeping track of
deleted records and reusing that space on subsequent Adds.

Does a binary search of the file for a specified record. The sample routine
will only search for data in the first column. In an application, you could
set up pointers for as many columns as you wish.

This is an alphabetic insert. It calls B_Find and then inserts the new data.
This took a lot of time to work out the special cases, such as inserting a
number at the beginning or end of the file.


This program was written by Nelson Ford, PsL.

You can find a lot of routines, sample programs, custom controls, and DLL's on
Microsoft's MSLANG forum on CompuServe.

My company, Public (software) Library, also distributes a lot of VB goodies
and programs written with VB. Call or write for a free copy of our monthly
magazine and catalog:

Public (software) Library
P.O.Box 35705
Houston, TX 77235-5705
Orders: 800-242-4PsL
Tech Support: 713-524-6394
FAX: 713-524-6398
CIS: 71355,470

 December 22, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>