If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Discord in Program

My data base has two records)
"D F# A#"
"D Aug"
"D F# A"
"D Maj"
When the program below looks for D F# A,it should return the
second record, but it returns the first because it finds the
string D F# A in it. This is not what I want it to do. I
can't sort 12,000 records, so I need a better solution.

Program:

'Force define all variables
Option Explicit
'Define Type to hold all data
Type myType
Entry As String
Chord As String
Root As String
Third As String
Fifth As String
Other As String
End Type
'Define a constant to indicate maximum entries
Const maxEntries = 5000
Const theFilename = "Chordlup.dat"
'Declare array to hold data
Dim theData(maxEntries) As myType
'Declare other variables
Dim numEntries As Integer, displayedEntry As Integer
'
'Initialize the procedure
'
'
'Search for an entry and display it
'
Sub FindIt()
numEntries = -1 'Initialize numentries
Dim I As Integer
'Look for data file, if there, open it. If not, initialize it.
If Dir(theFilename) <> "" Then
Open theFilename For Input As #1
Input #1, numEntries
For I = 0 To numEntries
Input #1, theData(I).Entry
Input #1, theData(I).Chord
Input #1, theData(I).Root
Input #1, theData(I).Third
Input #1, theData(I).Fifth
Input #1, theData(I).Other
Next I
Close #1
Else
MsgBox ("No data file found")
numEntries = -1 'initialize numentries
End If
For I = 0 To numEntries
If InStr(1, theData(I).Entry, ActiveSheet.Range("Entry").Value, 1) > 0 Then
Exit For
End If
Next I
If I = numEntries + 1 Then
MsgBox ("Not Found")
Else
DisplayIt I
End If
End Sub

Re: Discord in Program

You used InStr to compare your strings, and that function finds whether one
string is a substring of another. Hence the results you see. If you want
to compare two strings for equality, don't use InStr, use =.

N. Richards <ndrich@erols.com> wrote in message
news:39b9a1ac$1@news.devx.com...
>
> My data base has two records)
> "D F# A#"
> "D Aug"
> "D F# A"
> "D Maj"
> When the program below looks for D F# A,it should return the
> second record, but it returns the first because it finds the
> string D F# A in it. This is not what I want it to do. I
> can't sort 12,000 records, so I need a better solution.
>