isam.frm(frmMain):
Private Sub cboIdx_Click(Index As Integer)
DispFromIdx Index, cboIdx(Index).ListIndex
End Sub
Public Sub DispFromIdx(idxno As Integer, r As Long)
Dim i As Integer
Dim j As Integer
Dim rec As Long
Dim idxcount As Integer
cboIdx(idxno).ListIndex = r
rec = cboIdx(idxno).ItemData(r)
GetData rec
DispData
' 選ばれた以外のインデックスコンボボックスの位置合わせ
' (本質的なものではない)
idxcount = 0
For i = 0 To MAXINDEX
If vIndex(i) Then ' インデックスになっているか
If i <> idxno Then ' 元で選ばれたもの以外
For j = 0 To cboIdx(idxcount).ListCount - 1
If cboIdx(idxcount).ItemData(j) = rec Then
cboIdx(idxcount).ListIndex = j
Exit For
End If
Next j
End If
idxcount = idxcount + 1
End If
Next i
'lblRec.Caption = "Rec: " & CStr(rec)
lblRec.Caption = "Pri Index (Rec): " & _
CStr(cboIdx(PriIndex).ListIndex) & " (" & CStr(rec) & ")"
End Sub
(略)
frmSearch:
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
|