8218 Posted October 8, 2008 Share Posted October 8, 2008 (edited) Hey. Is it possible to use the AutoIT 3 to search either a .txt file or an .ini file after a given word, and then submit another word in the file, depending on the given word? What I'm trying to do is a simple translater that when successfull locates the word from the "database" and sends anoter word (the translated word) Any help would be apprichated Edited October 8, 2008 by 8218 Link to comment Share on other sites More sharing options...
bluelamp Posted October 8, 2008 Share Posted October 8, 2008 Opt("MustDeclareVars",1) Const $FILE = "file.txt" Local $handle,$fcontents $handle = FileOpen($FILE,0) ; read If $handle == -1 Then ; error Exit EndIf $fcontents = FileRead($handle) ; read the contents of the file FileClose($handle) ; close the file handle ; replace all occurences of searchstring with replacestring $fcontents = StringReplace($fcontents,"searchstring","replacestring") $handle = FileOpen($FILE,2) ; write If $handle == -1 Then ; error Exit EndIf FileWrite($handle,$fcontents) ; read the contents of the file FileClose($handle) ; close the file handle Link to comment Share on other sites More sharing options...
8218 Posted October 8, 2008 Author Share Posted October 8, 2008 Sorry, I think did a very bad formulation. What I meant was like a GUIbox with an input box and a "Translate" button that when you click the button, checks the input and sees if it can find the match in the text file. For an example the text file could be Word1 : Translated word1 Word2 : Translated word2 And then when you typed Word1 in the input box and clicked Translate, the Translated word2 would pop up in a msgbox. Thanks on behalf Link to comment Share on other sites More sharing options...
bluelamp Posted October 8, 2008 Share Posted October 8, 2008 Sorry, I think did a very bad formulation. What I meant was like a GUIbox with an input box and a "Translate" button that when you click the button, checks the input and sees if it can find the match in the text file. For an example the text file could be Word1 : Translated word1 Word2 : Translated word2 And then when you typed Word1 in the input box and clicked Translate, the Translated word2 would pop up in a msgbox. Thanks on behalf ok... i think i understood expandcollapse popupOpt("MustDeclareVars",1) Opt("GUIOnEventMode",1) Const $GUI_EVENT_CLOSE = -3 Const $WIDTH = 250 Const $HEIGHT = 90 Const $TITLE = "Translator" Const $TRANSINI = "translation.ini" Const $SECTION = "trans" Enum $LANGA,$LANGB Local $Hwnd,$In_Search main() Func main() $Hwnd = GUICreate($TITLE,$WIDTH,$HEIGHT) GUISetOnEvent(-3,"_EXIT") $In_Search = GUICtrlCreateInput("",20,20,200,20) GUICtrlSetOnEvent(GUICtrlCreateButton("Translate",20,50,200,30),"_TRANSLATE") GUISetState(@SW_SHOW) While 1 Sleep(1000) WEnd EndFunc Func _TRANSLATE() Local $translations,$totranslate $translations = readFile() $totranslate = GUICtrlRead($In_Search) For $i = 1 To $translations[0][0] If $translations[$i][0] == $totranslate Then MsgBox(0,$TITLE,$translations[$i][1],0,$Hwnd) Return EndIf Next MsgBox(48,$TITLE,"Didn´t found a damn thing!",0,$HWnd) EndFunc Func readFile() Local $fcontents,$handle $fcontents = IniReadSection($TRANSINI,$SECTION) If @error Then die("Couldn´t load ""translation.ini""") EndIf Return $fcontents EndFunc Func die($mesg) MsgBox(48,$TITLE,$mesg,0,$Hwnd) Exit EndFunc Func _EXIT() Exit EndFunc The ini looks like this CODE[trans] Hallo=hello Tschüss=bye Wort=word Link to comment Share on other sites More sharing options...
8218 Posted October 8, 2008 Author Share Posted October 8, 2008 Thanks! That was all I needed I guess you're german by the way ? Link to comment Share on other sites More sharing options...
bluelamp Posted October 8, 2008 Share Posted October 8, 2008 I guess you're german by the way ?Yes I am, why do you ask ? Link to comment Share on other sites More sharing options...
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