[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

VB Searching Random Access Data Files

Hello...

I have a type - what_done, that i have declared as cinfo.
I want to have a user type into text1, click Search (sv1) and then searches through a random access data file (data.vcr) and tries to find a record in the database so that cinfo.verb = text1.text.

I have heard about indexing and binary searching but I cant understand them very well...

Could someone help me with one of these?
PS: There will only be one result of the search.
0
qcl0wn
Asked:
qcl0wn
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
(1) Indexing - Basically you have a secondary file which is the index file.  Each index file represents a different field from your record, which in your case is "verb".  In the file, you store two pieces of information per record: the value of verb and the byte location (or record number) of the location in the main database file where that value can be found.  The advantage of the index file is it takes less time to search thru and/or move/update records in the index file involving only those two pieces of information as opposed to reading a much larger database record potentially involving many more fields per record.

(2) Binary Searching - This technique can be used in an index file or directly in the databse itself.  The key though is that the records must be sorted first.  Basically you start in the middle of the file and check the value there.  It if matches what you are looking for then you are done.  If it doesn't, then you only have two choices, left or right.  Since the file is sorted, if the value you are looking for is less than the value in the middle then the value you want is somewhere in the left half of the file...otherwise it must be in the right half.  So then you take the appropriate half and look at the middle element of that half.  You repeat the process until you have found the item you are looking for or you only have one element left in your "half" that you are currently searching...in which case the value you desire is not in the file.  So it is called a "Binary Search" because each time you narrow the available records to search by half.
0
 
qcl0wnAuthor Commented:
Could you give me an example of the binary searching/indexing?

I have:

Private Type what_done

verb as string * 100
sub_act as string * 100
min as integer

End Type

and the database file is data.dat.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Approximately how many records are in your database?

Rather than reinventing the wheel, have you considered using a database system that already has this capability?  They are optimized for this kind of searching and sorting.

I can certainly give you code on how to do this but I can guarantee that it won't be very optimized.  Database systems are complex beasts...
0
 
qcl0wnAuthor Commented:
Actually, I found the example code in another place (your explanations helped so much!)...

I just need to know how I can load all records into a listbox (list1).  Could you help me with this (get me a code)?

Thanks!

-q-
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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