hira さんの "InStr2()"、
Sinryow さんの "Instr3()" を使わさせてもらったのですが、
"InStr()" のときと同じ結果になりました。
"InStr4()" でも同じでした。
これは、検索のやり方がまずいのでしょうか?
コードを載せておきます。
[ここをクリックすると内容が表示されます]
お願いします。コード: 全て選択
'グローバル変数-----------------
Dim hEdit As HWND
Dim IniPath[255] As Byte
Dim nPos As Long, CurPos As Long
Dim Count As Long
Dim Ending_String As long
Dim hBox As HWND
' -------------------------------------
Sub MainWnd_Create(ByRef CreateStruct As CREATESTRUCT)
Dim self As String
Dim drv[255] As Byte, dir[255] As Byte
self=String$(255,Chr$(0))
GetModuleFileName(0,self,255)
_splitpath(self,drv,dir,0,0)
wsprintf(IniPath,"%s%s%s",drv,dir,"history.ini")
hEdit=GetDlgItem(hMainWnd,EditBox1)
End Sub
Sub Find_Create(ByRef CreateStruct As CREATESTRUCT)
Dim i As Long
Dim str[255] As Byte
Dim res_ini As Long
hBox=GetDlgItem(hFind,ComboBox1)
Count=0
End Sub
Sub Find_FindButton_Click()
Dim FindString As String
Dim buffer As String
Dim Length As Long
If SendMessage(hBox,CB_GETLBTEXTLEN,0,0)=0 Then Exit Sub
*START
CurPos=SendMessage(hEdit,EM_GETSEL,0,0)
If CurPos=nPos And nPos>0 Then
nPos++
Else
nPos=CurPos
FindString=GetDlgItemTextStr(hFind,ComboBox1)
buffer=GetDlgItemTextStr(hMainWnd,EditBox1)
nPos = InStr(Count+1, buffer, FindString)-1
If nPos<0 Then
If CurPos>0 And Count>0 Then
If MessageBox(hMainWnd,Ex"ファイルの最後まで検索しました\r\n最初から検索しますか?","Safety Note",MB_YESNO or MB_ICONQUESTION)=IDYES Then
nPos=0
Count=0
Goto *START
End If
Else
MessageBox(hFind, "指定された文字列はありません", NULL, MB_OK or MB_ICONINFORMATION)
End If
nPos=0
Count=0
Exit Sub
End If
Length=nPos + Len(FindString)
Count=Length
SendMessage(GetDlgItem(hMainWnd,EditBox1), EM_SETSEL, nPos,Length)
SendMessage(GetDlgItem(hMainWnd,EditBox1), EM_SCROLLCARET, 0, 0)
SetFocus(GetDlgItem(hMainWnd, EditBox1))
End If
End Sub