mario52 Posted March 1, 2012 Share Posted March 1, 2012 (edited) Hello, I'm facing a problem and after searching few hours I've gone crazy, I think I almost found the logical of what I want to achieve but I miss a bit of experience, I hope you could help me with this problem. I have 4 text files containing various products (foods, battery, drinks and smokes) that I would like to submit to my local server forms. I want the foods to be submited into my foods forms, my drinks into my drinks forms etc. So here is my non working code, to debug I have put a msgbox to see what's the value of content and surpsingly It pop up 5 similar lines everytime and nothing is submited ...: expandcollapse popup#include <file.au3> #Include <INET.au3> #include <IE.au3> ;~ I have 4 text files filled with differents products : food, drinks, smokes and battery that I would like each to be submitted in their respective forms. global $oIE = _IECreate("http://127.0.0.1") DIM $catPath = "C:\" DIM $nbr = 5 ; numbers of products to submit to my forms everytime cause I am limited to avoid issues DIM $products[4][2] $products[0][0] = "foods" $products[0][1] = "http://127.0.0.1/myforms/food" $products[1][0] = "drinks" $products[1][1] = "http://127.0.0.1/myforms/drinks" $products[2][0] = "smokes" $products[2][1] = "http://127.0.0.1/myforms/smokes" $products[3][0] = "battery" $products[3][1] = "http://127.0.0.1/myforms/battery" ; Function to empty each category file and return true or false if the text file is empty or not func _empty() $enOfFi = false For $i=0 To UBound($products)-1 $sourceFile = FileOpen($catPath & '\cat_' & $products[$i][0] & '.txt', 0) Next $tempLine = FileReadLine($sourceFile) if @error = -1 Then $enOfFi = true FileClose($sourceFile) return $enOfFi EndFunc ; extract 5 lines ($nbr) of each products and backup those submited to a text file "Done" func extractcat($nbr) dim $catArray[$nbr] For $i=0 To UBound($products)-1 $backupFile = FileOpen($catPath & '\cat_' & $products[$i][0] & '_Done.txt', 1) Next $enOfFi = False for $i=0 to $nbr-1 if _empty() Then ExitLoop For $j=0 To UBound($products)-1 $sourceFile = FileOpen($catPath & '\cat_' & $products[$j][0] & '.txt', 0) $tempLine = FileReadLine($sourceFile) $catArray[$i] = $tempLine Next FileClose($sourceFile) FileWriteLine($backupFile, $tempLine) _FileWriteToLine($sourceFile, 1, "", 1) next fileClose($backupFile) reDim $catArray[$i] return $catArray endFunc ; Navigate through each category forms to submit 5 products in the right category form While true if _empty() Then exitLoop For $i=0 To UBound($products)-1 _IENavigate($oIE, $products[$i][1]) _IELoadWait($oIE) ExitLoop Next $content = "" $cat = extractcat($nbr) for $j=0 to UBound($cat)-1 $content = $content & $cat[$j] & @CRLF next MsgBox(0,"",$content) ; Debug to see what's worng #cs $oElement = _IEGetObjByName($oIE, "cat") _IEFormElementSetValue($oElement, $content) $oForm = _IEFormGetCollection($oIE, 0) _IEFormSubmit($oForm) _IELoadWait($oIE) #ce wend Thanks for your helpcat_battery.txtcat_drinks.txtcat_foods.txtcat_smokes.txt Edited March 1, 2012 by mario52 Link to comment Share on other sites More sharing options...
mario52 Posted March 2, 2012 Author Share Posted March 2, 2012 I finaly make some progress but still have an error I have rebuild a bit the code to be more simple. But when I run it runs well on the first category and then It pulls an error : (43) : ==> Array variable subscript badly formatted.: ReDim $catArray[$j] ReDim $catArray[^ ERROR Here's my script, a little help would be welcome thanks. expandcollapse popup#include <file.au3> #Include <INET.au3> #include <IE.au3> #include <array.au3> global $oIE = _IECreate("http://127.0.0.1") DIM $catPath = "C:\" DIM $nbr = 5 ; numbers of products to submit to my forms everytime cause I am limited to avoid issues DIM $products[4][2] $products[0][0] = "foods" $products[0][1] = "http://127.0.0.1/myforms/food" $products[1][0] = "drinks" $products[1][1] = "http://127.0.0.1/myforms/drinks" $products[2][0] = "smokes" $products[2][1] = "http://127.0.0.1/myforms/smokes" $products[3][0] = "battery" $products[3][1] = "http://127.0.0.1/myforms/battery" _Extract() Func _Extract() Local $catArray[$nbr] Local $enOfFi = False For $i=0 To UBound($products) -1 If FileExists($catPath & '\cat_' & $products[$i][0] & '.txt') Then $sourceFile = ($catPath & '\cat_' & $products[$i][0] & '.txt') $backupFile = ($catPath & '\cat_' & $products[$i][0] & '_Faits.txt') Else ContinueLoop EndIf While True for $j=0 to $nbr-1 $tempLine = FileReadLine($sourceFile) If @error = -1 Then $enOfFi = true $catArray[$j] = $tempLine _FileWriteToLine($sourceFile, 1, "", 1) FileWriteLine($backupFile, $tempLine) If $enOfFi = true Then ExitLoop Next ReDim $catArray[$j] FileReadLine($sourceFile) If @error = -1 Then $enOfFi = true $urlproduct = $products[$i][1] _SubmitProduct($catArray, $sourceFile, $urlproduct) If $enOfFi = true Then ExitLoop WEnd Next EndFunc Func _SubmitProduct($cat,$psourceFile, $purlproduct) _IENavigate($oIE, $purlproduct) _IELoadWait($oIE) $content = "" for $i=0 to UBound($cat)-1 $content = $content & $cat[$i] & @CRLF next ; Debug msgbox MsgBox(0,$psourceFile,$content) $oElement = _IEGetObjByName($oIE, "cat") _IEFormElementSetValue($oElement, $content) $oForm = _IEFormGetCollection($oIE, 0) _IEFormSubmit($oForm) _IELoadWait($oIE) EndFunc Thank you 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