●シーケンシャルファイルでのサーチ(SEQ\SEARCH.FRM 部分)
Option Explicit
Private pos As Integer
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdSearch_Click()
pos = SearchList(pos)
If pos = -1 Then
MsgBox "Not Found", vbInformation, "Search"
Else
frmMain.lstData.ListIndex = pos
frmMain.lstData.Refresh
pos = pos + 1
End If
End Sub
' 指定位置から検索
Private Function SearchList(st As Integer) As Integer
Dim i As Integer
SearchList = -1
For i = st To frmMain.lstData.ListCount - 1
If InStr(frmMain.lstData.List(i), txtSearch.Text) <> 0 Then
SearchList = i
Exit For
End If
Next i
End Function
Private Sub txtSearch_Change()
pos = 0
End Sub
●ランダムアクセスファイルでのサーチ(RND\SEARCH.FRM 部分)
Option Explicit
Private pos As Long
Private Sub cmdClose_Click()
If pos <> 1 Then
curPos = pos - 1
End If
Unload Me
End Sub
Private Sub cmdSearch_Click()
pos = SearchList(pos)
If pos = -1 Then
MsgBox "Not Found", vbInformation, "Search"
Else
frmMain.DispData
frmMain.lblRec.Caption = "Rec:" & CStr(pos)
frmMain.Refresh
pos = pos + 1
End If
End Sub
' 指定位置から検索
Private Function SearchList(st As Long) As Integer
Dim i As Long
SearchList = -1
For i = st To LOF(fd) \ Len(recTitle)
If GetData(i) Then
If InStr(recTitle.Title, txtSearch.Text) <> 0 Then
SearchList = i
Exit For
End If
End If
Next i
End Function
Private Sub Form_Load()
pos = curPos
End Sub
Private Sub txtSearch_Change()
pos = 1
End Sub
●バイナリサーチを含むISAMでのサーチ(ISAM\SEARCH.FRM 部分)
Option Explicit
Option Compare Text
Private pos As Long
Private Sub cboSelIdx_Click()
pos = 1
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdSearch_Click()
If chkBSearch.value = 1 Then
pos = BSearchList(pos)
Else
pos = SearchList(pos)
End If
If pos = -1 Then
MsgBox "Not Found", vbInformation, "Search"
Else
frmMain.DispFromIdx cboSelIdx.ListIndex, pos
pos = pos + 1
End If
End Sub
' 指定位置からバイナリ検索
Private Function BSearchList(st As Long) As Integer
Dim nextpos As Long
Dim lastpos As Long
Dim minpos As Long
Dim maxpos As Long
Dim s As String
BSearchList = -1
minpos = 0
maxpos = frmMain.cboIdx(cboSelIdx.ListIndex).ListCount
Do
nextpos = (maxpos + minpos) \ 2
If lastpos = nextpos Then Exit Do
s = frmMain.cboIdx(cboSelIdx.ListIndex).List(nextpos)
If InStr(s, txtSearch.Text) <> 0 Then
BSearchList = nextpos
Exit Do
Else
If s > txtSearch.Text Then
maxpos = nextpos
Else
minpos = nextpos
End If
lastpos = nextpos
End If
Loop
End Function
' 指定位置から検索
Private Function SearchList(st As Long) As Integer
Dim i As Long
SearchList = -1
For i = st To frmMain.cboIdx(cboSelIdx.ListIndex).ListCount - 1
If InStr(frmMain.cboIdx(cboSelIdx.ListIndex).List(i), txtSearch.Text) <> 0 Then
SearchList = i
Exit For
End If
Next i
End Function
Private Sub Form_Load()
Dim i As Integer
' インデックスの選択を可能に
For i = 0 To MAXINDEX
If vIndex(i) Then
cboSelIdx.AddItem vTitles(i)
End If
Next i
cboSelIdx.ListIndex = 0
End Sub
Private Sub txtSearch_Change()
pos = 1
End Sub
|