 |

06-13-2002, 08:13 PM
|
|
|
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 ?
|
|

06-13-2002, 09:00 PM
|
 |
Code Factory
Retired Moderator * Expert *
|
|
Join Date: Jan 2001
Location: Montreal, Ca.
Posts: 5,565
|
|
|
do you mean vbBinaryCompare or vbTextCompare? These are constants.
|
|

06-14-2002, 02:07 PM
|
|
|
vbBinaryCompare
|
actually either one, i was just wondering if there was a faster way to search records.
|
|

06-14-2002, 02:21 PM
|
 |
Code Factory
Retired Moderator * Expert *
|
|
Join Date: Jan 2001
Location: Montreal, Ca.
Posts: 5,565
|
|
|
Oh yeah...
VB String functions like InStr() are considered slow.
What format is the data you are searching? (file, listbox, etc..)
|
|

06-14-2002, 02:27 PM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,928
|
|
|
As a matter of fact the InStr() function with the parameter vbBinaryCompare is very fast.
|
|

06-14-2002, 05:08 PM
|
|
|
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.
|

06-14-2002, 05:27 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
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
|

06-14-2002, 05:48 PM
|
|
|
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?
|
|

06-14-2002, 05:56 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-14-2002, 06:00 PM
|
|
|
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.
|

06-14-2002, 06:28 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-14-2002, 06:34 PM
|
|
|
compare
|
thanks for the info. at the most, the number of files will not exceed 5000
|
|

06-14-2002, 06:37 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-14-2002, 07:12 PM
|
|
|
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.
|
|

06-14-2002, 07:24 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-14-2002, 07:26 PM
|
|
|
compare
|
ok, thanks again, i will give it a try.
i just have to figure out how to do it.
thanks again!
|
|

06-14-2002, 07:33 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-15-2002, 04:27 AM
|
|
|
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
|
|

06-15-2002, 04:18 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
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
|

06-15-2002, 04:31 PM
|
|
|
vbcompare
|
thanks for the code, i will give it a try!
thanks
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|