Wb-FreeKill Posted January 5, 2005 Posted January 5, 2005 I have a funcktion searching for at word in a .htm file, but i also want to write the whole line were it found that specific word in a msgbox, how do i do that...?
ezzetabi Posted January 5, 2005 Posted January 5, 2005 (edited) Crazyness attack. Ignore this message. Check if the file uses @crlf, @cr or @lf and put the value in a variant, eg $endl . Pass the file counting the $endl in the file until your word. Using FileReadLine read the line where the counter arrived ( plus one, since the first line is 1) Edited January 6, 2005 by ezzetabi
Wb-FreeKill Posted January 5, 2005 Author Posted January 5, 2005 damn sry, i think you have to help me a bit more, ill give you my code: expandcollapse popup#include <GUIConstants.au3> global $sText global $search GUICreate("Dictionary search", 300, 225) GUISetState(@SW_SHOW) $search = GUIctrlcreateinput("Food",10,30, 150, 25) $button = GUICtrlCreateButton("Start Search", 10, 60, 70, 23) while 1 sleep(50) $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE then exitloop endif if $msg = $button then $sFileName = 'c:\fil.htm';Filename here $sText = FileRead($sFilename,FileGetSize($sfilename)) If StringInStr($sText,GUIctrlRead($search)) Then MsgBox(0,'',"'" & GUIctrlRead($search) & "'" & " was found in the file!") $fileline = FileReadLine ("c:\fil.htm", 8) msgbox(0,"test",$fileline) If $sText = -1 Then MsgBox(0, "Error", "Word not found") endif endif wend i hope you understand what i want to do.. Theres another problem, i can't get the "Word not found" to work?
ezzetabi Posted January 5, 2005 Posted January 5, 2005 (edited) What I did while you answered... Forget this ugly code.... If you have WinXP/2000 system you can probably test outright, change the $sWord in a nonsense to see the error message. An advice for the future. BEFORE make functions that works, AFTER make the GUI for them. Edited January 6, 2005 by ezzetabi
Wb-FreeKill Posted January 5, 2005 Author Posted January 5, 2005 Thx alot... but it dont seem to work with .htm files? only ini and txt
Wb-FreeKill Posted January 5, 2005 Author Posted January 5, 2005 Or maybe its because of the BIG file its searching in, 6 MB... im trying to make a Dictionary search
ezzetabi Posted January 6, 2005 Posted January 6, 2005 (edited) ... Rereading my own code (and advice) I think I was crazy... Sorry. Use this one... It should works as expected also in large files... Opt ('MustDeclareVars', 1) Local $sFileName = 'c:\boot.ini' Local $sWord = 'XP' Local $sLine, $c = 1, $found = 0 Local $iHandle $iHandle = FileOpen($sFileName, 0) If $iHandle <> - 1 Then While 1 $sLine = FileReadLine($iHandle) Select Case @error ExitLoop Case StringInStr($sLine, $sWord) $found = 1 ExitLoop Case Else $c = $c + 1 EndSelect Wend FileClose($iHandle) If $found Then MsgBox(0, '','Line: -' & $c &' - '& $sLine) Else MsgBox(0, '', 'Not found') EndIf Else MsgBox(0, '', 'File not found') EndIf Edit: I tested with a 56Mb text file and it worked... (I copied many times a long text and added a unique word at the end...) Edited January 6, 2005 by ezzetabi
Wb-FreeKill Posted January 6, 2005 Author Posted January 6, 2005 thx, works much better! but i have a problem, again... The Dictionary search program im making, get the "words" from to .htm files Danish-English / English - Danish... But in order to use the files, i have to have a txt file were the text stands as in the .htm file..: as in htm file, WHEN openeda (et -'er) A, a; [har man sagt a, må man også sige b] in for a penny, in for a pound; [a!] se ah; [a conto, a meta] etc, søges på alfabetisk plads; [fra a til z] from A to Z. á præp (som hver indeholder) of, of ... each, each containing ( fx 2 cases of 25 bottles (each), 2 cases each containing 25 bottles); (om pris) at ( fx 5 bottles at 50 p. each); (omtrentlig angivelse) or ( fx 3 or 4 days), to ( fx 30 to 40 people); [á 15] (i boldspil) fifteen all; [á la], søges på alfabetisk plads. ab præp : as .htm file as > AutoIt < sees it <html><title>Danish-English dictionary.</title><body><p> <b>a </b><i>(et -'er) </i>A, a;<br><!--*ex--> [<i>har man sagt a</i>, <i>må man også sige b</i>] in for a penny, in for a pound;<br> [<i>a</i>!] se <i>ah</i>;<br> [<i>a conto</i>, <i>a meta</i>] <i>etc</i>, søges på alfabetisk plads;<br> [<i>fra a til z</i>] from A to Z.<br> <b>á </b><i>præp<br> </i>(<i>som hver indeholder</i>) of, of ... each, each containing ( <i>fx </i>2 cases of 25 bottles (each), 2 cases each containing 25 bottles);<br> (<i>om pris</i>) at ( <i>fx </i>5 bottles at 50 p. each);<br> (<i>omtrentlig angivelse</i>) or ( <i>fx </i>3 or 4 days), to ( <i>fx </i>30 to 40 people);<br><!--*ex--> [<i>á 15</i>]<br> (<i>i boldspil</i>) fifteen all;<br> [<i>á la</i>], søges på alfabetisk plads.<br> <b>ab </b><i>præp<br> </i>(<i>merk</i>) ex ( <i>fx </i>ex ship, ex warehouse)I cant use the 2'end eksample, because the text hassent been convertet to htmlThe only way to overcome this problem is to copy/paste the OPENED htm file into a text file, so it looks just like the same. But the .htm file is that huge, that it is completly imposible for the computer to handle!What can i do then?Can i get AutoIt sees it like the htm file was opened, i hope you guys understod what i want to do, did my best
ezzetabi Posted January 6, 2005 Posted January 6, 2005 When you find the line you should check the string that is between two <p>,</p> or <br> or any combo... And remove all tags with a string replace. RegExp may help (not sure, but is should) removing every <anyword>.
Wb-FreeKill Posted January 6, 2005 Author Posted January 6, 2005 When you find the line you should check the string that is between two<p>,</p> or <br> or any combo... And remove all tags with a string replace. RegExp may help (not sure, but is should) removing every <anyword>.<{POST_SNAPBACK}>Im not sure that enough, theres more html expressions than just <"">, it would never look good...can't i get AutoIt read a htm file, when the txt have been convertet to html? or do i have to copy/paste the converted html text in to a txt file? if thats the only way to make it look good
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now