Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > vbcompare


Reply
 
Thread Tools Display Modes
  #1  
Old 06-13-2002, 08:13 PM
Rockinron
Guest
 
Posts: n/a
Default vbcompare


is the Vbcompare any faster than the Instr command??

in other words, if i am searching a large amount of data, would the Vbcompare run faster??


isn't there a VbBinaryCompare ?
Reply With Quote
  #2  
Old 06-13-2002, 09:00 PM
Robby's Avatar
Robby Robby is offline
Code Factory

Retired Moderator
* Expert *
 
Join Date: Jan 2001
Location: Montreal, Ca.
Posts: 5,565
Default

do you mean vbBinaryCompare or vbTextCompare? These are constants.
__________________
Visit...Bassic Software
Reply With Quote
  #3  
Old 06-14-2002, 02:07 PM
Rockinron
Guest
 
Posts: n/a
Default vbBinaryCompare

actually either one, i was just wondering if there was a faster way to search records.
Reply With Quote
  #4  
Old 06-14-2002, 02:21 PM
Robby's Avatar
Robby Robby is offline
Code Factory

Retired Moderator
* Expert *
 
Join Date: Jan 2001
Location: Montreal, Ca.
Posts: 5,565
Default

Oh yeah...

VB String functions like InStr() are considered slow.

What format is the data you are searching? (file, listbox, etc..)
__________________
Visit...Bassic Software
Reply With Quote
  #5  
Old 06-14-2002, 02:27 PM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,928
Default

As a matter of fact the InStr() function with the parameter vbBinaryCompare is very fast.
Reply With Quote
  #6  
Old 06-14-2002, 05:08 PM
Rockinron
Guest
 
Posts: n/a
Default vbcompare

to answer robby, i am searching files.

i tried adding the vbbinarycompare to the instr function and it did not change the speed. about 2 seconds for 500 files with a 1.6 gig
processor.

am i doing something wrong or is this the best it will do??

here is basically how i do it:

dim searchname$ as string

Numrecs1 = LOF(1) / Len(data)

For Z = 1 To numrecs1
Get #1, Z, data

Found2 = InStr(UCase$(Trim$(data.name), UCase$(SearchName$))

if found2 => 1 then call Addnames

Next

Last edited by Rockinron; 06-14-2002 at 05:20 PM.
Reply With Quote
  #7  
Old 06-14-2002, 05:27 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

You might be able to speed things up by getting rid of the UCase$ functions. In particular, you could ucase$ searchname OUTSIDE of the for loop. Trim also appears to be redundant...

Code:
SearchName = ucase$(SearchName)

For Z = 1 To numrecs1 
     Get #1, Z, data 
     if InStr(UCase$(data.name), SearchName) then addnames
Next z
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #8  
Old 06-14-2002, 05:48 PM
Rockinron
Guest
 
Posts: n/a
Default vbcompare

thanks for the tip, i made the changes and it may have helped some.

if someone wants to search files is this the way it is done?
am i doing something out of ordinary?
Reply With Quote
  #9  
Old 06-14-2002, 05:56 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

For very large amounts of data, most people use a database....
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #10  
Old 06-14-2002, 06:00 PM
Rockinron
Guest
 
Posts: n/a
Default compare

i have heard of that.


does it take much code to set it up??

is it possible for me to change the big file to a database and still use support files that are not from a database??

everything else works great but i need more speed

Last edited by Rockinron; 06-14-2002 at 06:06 PM.
Reply With Quote
  #11  
Old 06-14-2002, 06:28 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

I don't really want to get into questions about "how to create a DB"...there are lots of books out there that can do a better job than I can.

A suggestion though....you are currently reading data one record at a time. You might try reading in multiple records into an array. I suspect your main bottleneck is your disk access time.

For instance:

Dim aData(99) as datatype 'array of 100 records

....
get #1,,aData
for i = 0 to 99
if instr(aData(i),searchname) then addnames
next i

This shows a static array but I would use a dynamic array. This way, when I get near the end of the file (ie. where there are less than 100 records) I can REDIM the array to match the remaining records.


Alternatively, if your recordsize is very large, you might try opening the file in BINARY mode and simply reading the Name field instead of the whol record.

a) open the file in binary
b) move the file pointer to the first name field
c) Get the name
d) increment the file pointer by one record size
e) goto c
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #12  
Old 06-14-2002, 06:34 PM
Rockinron
Guest
 
Posts: n/a
Default compare

thanks for the info. at the most, the number of files will not exceed 5000
Reply With Quote
  #13  
Old 06-14-2002, 06:37 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Yeah, but how big is a record, and how many records are in each file? Also, how big is the name field within that record?

These questions can help you tune your app for better speed.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #14  
Old 06-14-2002, 07:12 PM
Rockinron
Guest
 
Posts: n/a
Default compare

505 records is about 4,214KB


the name field can be up to 55 charactors, there are many fields
in this record, maybe 65. a lot of data is stored.
Reply With Quote
  #15  
Old 06-14-2002, 07:24 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Thats better than 8K per record. Since the name field is only 55 bytes (or 110 bytes in unicode), you can probably get much better performance using the binary method I suggested.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #16  
Old 06-14-2002, 07:26 PM
Rockinron
Guest
 
Posts: n/a
Default compare

ok, thanks again, i will give it a try.

i just have to figure out how to do it.


thanks again!
Reply With Quote
  #17  
Old 06-14-2002, 07:33 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Post the Type definition. I'll take a look at it....

If it is huge, you could zip it an attach it....
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #18  
Old 06-15-2002, 04:27 AM
Rockinron
Guest
 
Posts: n/a
Default VBcompare

here is the type def's


Type IncidentType
ClientName As String * 55
EntryPerson As String * 45
Special2 As String * 25
'---------------------------
'incident reports
IncidentTime As String * 10
IncidentDayOfWeek As String * 16
IncidentLocation As String * 300
IncidentDate As String * 12
EntryPersonDate As String * 45
IncidentSpare2 As String * 45
IncidentSpare3 As String * 45
IncidentSpare4 As String * 45
IncidentNumber As String * 45

Description As String * 300
Comments As String * 300
Hour24 As String * 8
Aid1 As String * 35
Aid2 As String * 35
Aid3 As String * 35
Aid4 As String * 35
Aid5 As String * 35
Aid6 As String * 35
Aid7 As String * 35
Aid8 As String * 35
Aid9 As String * 35
Aid10 As String * 35
Aid11 As String * 35
Aid12 As String * 35
Aid13 As String * 35
Aid14 As String * 35
Aid15 As String * 35
Aid16 As String * 35
Aid17 As String * 35
Aid18 As String * 35
Aid19 As String * 35
Aid20 As String * 35
Aid21 As String * 35
Aid22 As String * 35
Aid23 As String * 35
Aid24 As String * 35
Aid25 As String * 35

SpareString1 As String * 65
SpareString2 As String * 65
SP1 As String * 15
SuppIncidentNumber As String * 20
SpareString5 As String * 45

Notes1 As String * 6000

ReportPerson As String * 35
ClientNumber As Integer
Agency As Integer
DayNumber As Integer
CompStatus As Integer
Intensity As Integer
LockStatus As Integer
SourceStatus As Integer
RemoteReport As Integer
Spare1I As Integer
Spare1J As Integer
ConvertedTime As Integer

Location As Integer
FileStatus As Integer
IncidentStatus As Integer
GuidanceStatus As Integer
Restraint As Integer
SavedStatus As Integer
Status1 As Integer
Status2 As Integer
Status3 As Integer
Status4 As Integer
Status5 As Integer
Status6 As Integer
Status7 As Integer
Status8 As Integer
Status9 As Integer
Status10 As Integer
Status11 As Integer
Status12 As Integer
Status13 As Integer
SendReport As Integer
UpdatesExist As Integer

Spare1 As Double
Spare2 As Double
Spare3 As Double
spare4 As Double
Spare5 As Double
Spare6 As Double
Spare7 As Double
Spare8 As Double
End Type

Global Incident As IncidentType
Reply With Quote
  #19  
Old 06-15-2002, 04:18 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

It really helps that the client name you want is at the start of the record...you don't need to offset by anything....

Try this:

Code:
Dim nSize as long
Dim rec as IncidentType
Dim name as string * 55
dim ptr as long
dim ff as freefile


SearchName = ucase$(SearchName)
ff = freefile   'get first available file handle (probably 1)
open "datafile.dat" for BINARY as #ff
nSize=lof(ff)
For ptr = 1 To nSize STEP len(rec) 
     Get #ff, ptr, name 'load only the name field
     if InStr(UCase$(name), SearchName) then 'found a match
          get #ff,ptr,rec   'load the entire record now
          addnames
     end if
Next ptr
close #ff
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #20  
Old 06-15-2002, 04:31 PM
Rockinron
Guest
 
Posts: n/a
Default vbcompare

thanks for the code, i will give it a try!


thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->