請問 ReplaceText API 該如何測試,我以下列程式測試總會出現現'這個程式執行作業無效,即將關閉' 的錯誤訊息',
PS:表單內只有一個Text1及兩個Command Button
使用Win98se + vb6 + sp3 程式碼如下:
Option Explicit
'Find/Replace Type Structure
Private Type FINDREPLACE
lStructSize As Long
hwndOwner As Long
hInstance As Long
flags As Long
lpstrFindWhat As String
lpstrReplaceWith As String
wFindWhatLen As Integer
wReplaceWithLen As Integer
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
'Common Dialog DLL Calls
Private Declare Function FindText Lib "comdlg32.dll" _
Alias "FindTextA" (pFindreplace As FINDREPLACE) As Long
Private Declare Function ReplaceText Lib "comdlg32.dll" _
Alias "ReplaceTextA" (pFindreplace As FINDREPLACE) As Long
'Delcaration of the type structure
Dim frText As FINDREPLACE
Private Sub cmdFind_Click()
'Call the find text function
frText.lpstrFindWhat = Text1.SelText
FindText frText
End Sub
Private Sub cmdReplace_Click()
'Call the replace text function
ReplaceText frText
End Sub
Private Sub Form_Load()
'Set the Find/Replace Type properties
With frText
.lpstrReplaceWith = "Replace Text"
.lpstrFindWhat = "Find Text"
.wFindWhatLen = 9
.wReplaceWithLen = 12
.hInstance = App.hInstance
.hwndOwner = Me.hWnd
.lStructSize = LenB(frText)
End With
End Sub