Fabian Posted January 10, 2008 Share Posted January 10, 2008 (edited) Why does this script always returns "0" as translated text and why doesn't work the "_IEFormElementOptionselect" function? Can anybody help, plz?expandcollapse popup#include <GUIConstants.au3> #include <File.au3> #include <IE.au3> #include <String.au3> ;#NoTrayIcon Global $cQuote = '"' If NOT _IsOnline() Then MsgBox(16, "Error", "You must have an internet connection.") Exit EndIf $oIE = _IECreate ("http://www.google.com/language_tools?hl=en") $oTranslateForm = _IEFormGetObjByName ($oIE, "text_form") $oSourceEdit = _IEFormElementGetObjByName ($oTranslateForm, "source") $oLangCombo = _IEFormElementGetObjByName ($oTranslateForm, "langpair") $oForm1 = GUICreate("Translator", 396, 292, 193, 115) ;GUISetIcon(@ScriptDir & "\icon.ico") $oLabel1 = GUICtrlCreateLabel("Translate a text", 8, 16, 128, 27) GUICtrlSetFont(-1, 13, 400, 0, "Trebuchet MS") $oEdit1 = GUICtrlCreateEdit("", 8, 48, 377, 177, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $oCombo1 = GUICtrlCreateCombo("", 8, 232, 297, 200) GUICtrlSetData(-1, "Arabic to English|Chinese to English|French to English|German to English|Greek to English|Italian to English|Japanese to English|Korean to English|Portoguese to English|Russian to English|Spanish to English|English to Arabic|English to Chinese|English to French|English to German|English to Greek|English to Italian|English to Japanese |English to Korean|English to Portoguese|English to Russian|English to Spanish") GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $oButton1 = GUICtrlCreateButton("Translate", 312, 232, 75, 23, 0) $oLabel2 = GUICtrlCreateLabel("Google Language Tools", 267, 272, 118, 17, $SS_RIGHT) GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif") GUICtrlSetColor(-1, 0x0000FF) GUICtrlSetCursor($oLabel2, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $oButton1 $sTextToTranslate = GUICtrlRead($oEdit1) $sLang = GUICtrlRead($oCombo1) _IEFormElementSetValue ($oSourceEdit, $sTextToTranslate) _IEFormElementOptionselect ($oLangCombo, $sLang, 1, "byText") _IEFormSubmit ($oTranslateForm) $oSource = _IEDocReadHTML($oIE) $sTranslatedText = _StringBetween($oSource, "<div id=result_box dir=" & $cQuote & "ltr" & $cQuote & ">", "</div>") GUICtrlSetData($oEdit1, $sTranslatedText) Case $oLabel2 ShellExecute("http://www.google.com/language_tools?hl=en") EndSwitch WEnd Func _IsOnline() Return Ceiling(Ping("www.google.com", 250) / 250) EndFunc Edited January 10, 2008 by Fabian embeded-mediaUDF ~~ Embed WMP, Quicktime and Flash in your Au3 appYABC ~~ Yet another Binary Clock Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 10, 2008 Share Posted January 10, 2008 Try it like this: expandcollapse popup#include <GUIConstants.au3> #include <File.au3> #include <IE.au3> #include <String.au3> ;#NoTrayIcon Global $cQuote = '"' $oIE = _IECreate("http://www.google.com/language_tools?hl=en", 0, 1, 1) $oTranslateForm = _IEFormGetObjByName($oIE, "text_form") $sSourceEdit = _IEFormElementGetObjByName($oTranslateForm, "source") $oLangCombo = _IEFormElementGetObjByName($oTranslateForm, "langpair") $hForm1 = GUICreate("Translator", 396, 292, 193, 115) $Label1 = GUICtrlCreateLabel("Translate a text", 8, 16, 128, 27) GUICtrlSetFont(-1, 13, 400, 0, "Trebuchet MS") $Edit1 = GUICtrlCreateEdit("", 8, 48, 377, 177, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Combo1 = GUICtrlCreateCombo("", 8, 232, 297, 200) GUICtrlSetData(-1, "Arabic to English|Chinese to English|French to English|German to English|Greek to English|Italian to English|Japanese to English|Korean to English|Portoguese to English|Russian to English|Spanish to English|English to Arabic|English to Chinese|English to French|English to German|English to Greek|English to Italian|English to Japanese |English to Korean|English to Portoguese|English to Russian|English to Spanish") GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Translate", 312, 232, 75, 23, 0) $Label2 = GUICtrlCreateLabel("Google Language Tools", 267, 272, 118, 17, $SS_RIGHT) GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif") GUICtrlSetColor(-1, 0x0000FF) GUICtrlSetCursor($Label2, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $sTextToTranslate = GUICtrlRead($Edit1) $sLang = GUICtrlRead($Combo1) _IEFormElementSetValue($sSourceEdit, $sTextToTranslate) _IEFormElementOptionselect($oLangCombo, $sLang, 1, "byText") _IEFormSubmit($oTranslateForm) $sSource = _IEDocReadHTML($oIE) $avTranslatedText = _StringBetween($sSource, '<div id=result_box dir=ltr>', '</div>') If Not @error Then GUICtrlSetData($Edit1, $avTranslatedText[0]) EndIf Case $Label2 ShellExecute("http://www.google.com/language_tools?hl=en") EndSwitch WEnd You must have come at this AutoIt stuff from another lanquage. That whole "<div id=result_box dir=" & $cQuote & "ltr" & $cQuote & ">" string is pretty bizzare. Note the working one is just: "<div id=result_box dir=ltr>". There was also some confusion on variable types as indicated by all the "o" prefixes. I straightened some of that out, and _StringBetween() returns an array (if not 0 for failure, which was your previous result). Still a couple of problems. The Edit control doesn't like the unicode of some languages (Arabic, Cyrillic, Greek, etc.). It only runs once, because after it navigates to the new page, all the objects from the old page become invalid. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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