Results 1 to 7 of 7

Thread: Search & Replace

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2001
    Posts
    55

    Question Search & Replace

    What I want to do is this. The user will specify the file. The program will specify what to search for and the user will specify what to replace it with.

    Is there any way that I could access the windows api to use the search & replace feature with an open file?

    -Sensimillia

  2. #2
    Member
    Join Date
    May 2001
    Location
    Malaysia
    Posts
    43

    well, if u want to replace a string in a text file, why don't you open the text file and read line by line. then you can search the string you want in that line and replace it with the string you want to replace. after that close the text file...

    1) Open TextFilePath For Input As #1
    2) While EOF(1)=FALSE
    Line Input #1, data
    Replace(expression, find, replacewith[, start[, count[, compare]]])
    wend
    3) Close #1

    Get what I mean?
    Ben Chin

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2001
    Posts
    55
    Thats my problem. How would I just replace 1 line without loading the whole text file change the line and then saving the new text file.

    Is Replce and actual command.

    Is there an overwrite command that can find a specific line.

    If possible I really think that Search & Replce API would be best.

    And Remeber this a really large file so the whole thing might not fit sufficantly into variables all at the same time.
    -Sensimillia

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2001
    Posts
    55
    Ok well it looks like replace is an actually command. Thankz.

    Can you give me a link to more info on this particualr command?

    for some reason the search bar does not work on my comp :0(
    -Sensimillia

  5. #5
    Member
    Join Date
    May 2001
    Location
    Malaysia
    Posts
    43

    Cool

    Replace is a real function in VB. The syntax as I written there :
    ******************************************************************************
    Replace(expression, find, replacewith[, start[, count[, compare]]])
    The parameters are as below :-
    1. expression - Required.String expression containing substring to replace.
    2. find -Required. Substring being searched for.
    3. replacewith -Required. Replacement substring.
    4. start -Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed.
    5. count -Optional. Number of substring substitutions to perform. If omitted, the default value is –1, which means make all possible substitutions.
    6. compare -Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings -section for values.
    *****************************************************************************
    1) Open TextFilePath For Input As #1 'this really open a text file (replace the TextFilePath with actual path)
    2) While EOF(1)=FALSE
    Line Input #1, data 'this will retrieves data line by line from the text file as long as the file in not EOF
    Replace(expression, find, replacewith[, start[, count[, compare]]]) 'do the replacing here
    'save it and do whatever processing you need
    wend
    3) Close #1 'this will close the text file after you use it.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    this is what i can offer you. i don't know any api for search and replace.
    you can e-mail me at [email protected]
    good luck!
    Ben Chin

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2001
    Posts
    55
    I found this. How do I use it? know of any tutorials?

    Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long

    Public Const CC_RGBINIT = &H1
    Public Const CC_FULLOPEN = &H2
    Public Const CC_PREVENTFULLOPEN = &H4
    Public Const CC_SHOWHELP = &H8
    Public Const CC_ENABLEHOOK = &H10
    Public Const CC_ENABLETEMPLATE = &H20
    Public Const CC_ENABLETEMPLATEHANDLE = &H40
    Public Const CC_SOLIDCOLOR = &H80
    Public Const CC_ANYCOLOR = &H100

    Type FINDREPLACE
    lStructSize As Long ' size of this struct 0x20
    hwndOwner As Long ' handle to owner's window
    hInstance As Long ' instance handle of.EXE that
    ' contains cust. dlg. template
    flags As Long ' one or more of the FR_??
    lpstrFindWhat As String ' ptr. to search string
    lpstrReplaceWith As String ' ptr. to replace string
    wFindWhatLen As Integer ' size of find buffer
    wReplaceWithLen As Integer ' size of replace buffer
    lCustData As Long ' data passed to hook fn.
    lpfnHook As Long ' ptr. to hook fn. or NULL
    lpTemplateName As String ' custom template name
    End Type

    **** I don't know of the delow is suppose to be part of it ****

    Public Const FR_DOWN = &H1
    Public Const FR_WHOLEWORD = &H2
    Public Const FR_MATCHCASE = &H4
    Public Const FR_FINDNEXT = &H8
    Public Const FR_REPLACE = &H10
    Public Const FR_REPLACEALL = &H20
    Public Const FR_DIALOGTERM = &H40
    Public Const FR_SHOWHELP = &H80
    Public Const FR_ENABLEHOOK = &H100
    Public Const FR_ENABLETEMPLATE = &H200
    Public Const FR_NOUPDOWN = &H400
    Public Const FR_NOMATCHCASE = &H800
    Public Const FR_NOWHOLEWORD = &H1000
    Public Const FR_ENABLETEMPLATEHANDLE = &H2000
    Public Const FR_HIDEUPDOWN = &H4000
    Public Const FR_HIDEMATCHCASE = &H8000
    Public Const FR_HIDEWHOLEWORD = &H10000
    -Sensimillia

  7. #7
    Member
    Join Date
    May 2001
    Location
    Malaysia
    Posts
    43

    Exclamation

    What actually do you want to do with a ChooseColor API and FindReplace structure?
    The ChooseColor function creates a Color common dialog box that enables the user to select a color.
    FindReplace is simply a types and I can't see any connection between those two.
    Ben Chin

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