Results 1 to 11 of 11

Thread: how to find/replace in .net

  1. #1

    Thread Starter
    Junior Member iqueen's Avatar
    Join Date
    Sep 2003
    Posts
    29

    how to find/replace in .net

    how to use system api ,the follow code is for vb6,how to enable it in vb.net
    http://msdn.microsoft.com/library/de...ialogBoxes.asp
    thanks.

  2. #2

    Thread Starter
    Junior Member iqueen's Avatar
    Join Date
    Sep 2003
    Posts
    29
    My code as follow, I got 3 ERROR as marked.
    'Common Dialog DLL Calls
    Private Declare Function FindText _
    Lib "comdlg32.dll" _
    Alias "FindTextA" (ByVal pFindreplace As FINDREPLACE) _
    As Long
    Private Declare Function ReplaceText _
    Lib "comdlg32.dll" _
    Alias "ReplaceTextA" (ByVal pFindreplace As FINDREPLACE) _
    As Long
    '''''''''''''
    Private Structure FINDREPLACE
    Dim lStructSize As Long
    Dim hwndOwner As Long
    Dim hInstance As Long
    Dim flags As Long
    Dim lpstrFindWhat As String
    Dim lpstrReplaceWith As String
    Dim wFindWhatLen As Integer
    Dim wReplaceWithLen As Integer
    Dim lCustData As Long
    Dim lpfnHook As Long
    Dim lpTemplateName As String
    End Structure
    '''''''''''''''''''
    'Delcaration of the type structure
    Dim frText As FINDREPLACE
    ''''''''''''''''''''''''''
    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
    '''''''''''''ERROR:app is not declared
    .hwndOwner = Me.hWnd
    ''''''''''''ERROR:hWnd is not a member of form
    .lStructSize = LenB(frText)
    ''''''''''''''''''''ERROR:name 'LenB' is not declared
    End With
    End Sub
    '''''''''''''''''''
    Public Function m_find()
    'Call the find text function
    FindText(frText)
    End Function
    Public Function m_replace()
    'Call the replace text function
    ReplaceText(frText)
    End Function
    thanks.

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB6 -->VB.NET

    First rule : change all long types to integer so :

    VB Code:
    1. Long = Integer
    2. Any = Object
    3. App = Application
    4. Me.hWnd = Me.Handle
    5. LenB = Len

  4. #4

    Thread Starter
    Junior Member iqueen's Avatar
    Join Date
    Sep 2003
    Posts
    29
    many thanks
    but where to put line
    any=object

  5. #5

    Thread Starter
    Junior Member iqueen's Avatar
    Join Date
    Sep 2003
    Posts
    29
    .hInstance = Application.?????
    how to write this line,thanks

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by iqueen
    many thanks
    but where to put line
    I can't see it anywhere but if you ever face it , just replace the As Any by As Object because there is no such data type in .NET .

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by iqueen
    .hInstance = Application.?????
    how to write this line,thanks
    What does 'hInstance' do ?

  8. #8

    Thread Starter
    Junior Member iqueen's Avatar
    Join Date
    Sep 2003
    Posts
    29
    In msdn :
    You create and display a Find dialog box by initializing a FINDREPLACE structure and passing the structure to the FindText function. You create and display a Replace dialog box by initializing a FINDREPLACE structure and passing the structure to the ReplaceText function.
    The FINDREPLACE structure contains information that the FindText and ReplaceText functions use to initialize the Find and Replace dialog boxes. The FINDMSGSTRING registered message uses this structure to pass the user's search or replacement input to the owner window of a Find or Replace dialog box.
    Syntax
    typedef struct {
    DWORD lStructSize;
    HWND hwndOwner;
    HINSTANCE hInstance;
    DWORD Flags;
    LPTSTR lpstrFindWhat;
    LPTSTR lpstrReplaceWith;
    WORD wFindWhatLen;
    WORD wReplaceWithLen;
    LPARAM lCustData;
    LPFRHOOKPROC lpfnHook;
    LPCTSTR lpTemplateName;
    } FINDREPLACE, *LPFINDREPLACE;
    how to rewrite it in vb.net

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    That's C++ . The thing is some of C\C++\C# data types have no upgrade or transform path to VB .lp...is a pointer . There is no pointers in VB.NET . If you can find VB version or find another way .

  10. #10

    Thread Starter
    Junior Member iqueen's Avatar
    Join Date
    Sep 2003
    Posts
    29
    Originally posted by Pirate
    That's C++ . The thing is some of C\C++\C# data types have no upgrade or transform path to VB .lp...is a pointer . There is no pointers in VB.NET . If you can find VB version or find another way .
    that means I cannt use system comdlg32.dll in vb.net ?
    then how can I enable find/replace function in my app in richtextbox like system function does.

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Apparently , with this code (below), it would be quite difficult . But the code you posted in the second post might be transformed to work with .NET . Do you have working example in VB6 ?
    VB Code:
    1. typedef struct {
    2. DWORD lStructSize;
    3. HWND hwndOwner;
    4. HINSTANCE hInstance;
    5. DWORD Flags;
    6. LPTSTR lpstrFindWhat;
    7. LPTSTR lpstrReplaceWith;
    8. WORD wFindWhatLen;
    9. WORD wReplaceWithLen;
    10. LPARAM lCustData;
    11. LPFRHOOKPROC lpfnHook;
    12. LPCTSTR lpTemplateName;
    13. } FINDREPLACE, *LPFINDREPLACE;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width