Sign in to follow this  
Followers 0
mary

Javascript array to autoit array

7 posts in this topic

#1 ·  Posted (edited)

Hi!

Trying to convert a javascript array to an autoit array, I found that javascript and autoit use the same syntaxe to get elements. here an exemple

------javascript_file.JS---------------------------------

Function Js_Func(arg1, arg2, arg3) {

{

return Js_Func.arguments; // this return all arguments in an array

}

Js_Func(15, "text with coma , be carfull!" , null) ;

------javascript_file.JS---------------------------------

Now if you try to execute this js code with com ( obj "ScriptControl"), like this

$jsfile="javascript_file.JS"

$code = fileread($jsfile, filegetsize($jsfile))

$js = ObjCreate("ScriptControl")

$js.language = "Jscript"

$javascript_array = $js.Eval($code)

$js = ""

consoleWrite($javascript_array[1]) ; ===> here i get error

consoleWrite($javascript_array.item(1) ); === here i get error some thing like "...the request property is failed..."

please help

thinks a lot

Edited by mary

Share this post


Link to post
Share on other sites



I haven't got a clue what you were trying to do with that code.

If you Eval something, it reads the string and finds the variable that is named in the string. I don't know anything about the ScriptControl object, but I can see you are using Eval wrong.

Share this post


Link to post
Share on other sites

$Js.Eval($code) ? here a call a javascript Eval function and not autoit eval !

anyway, there is a lot confusing when you use an other language witch is similar syntaxe with autoit.

For exemple:

With autoit . MyArray[1] ;===> return the first item of MyArray = It is the same with javascript !!! so when you get an array object from autoit you may have error when you call Myarray[1]

excuse my poor english

Share this post


Link to post
Share on other sites

Not sure how to pass an array as a construct back to AutoIt, so you can certainly do something like this:

$js = ObjCreate("ScriptControl")
$js.language = "Jscript"
$js.Eval("var myArray = new Array(1, 2, 3);")
Local $myArray[3]
$myArray[0] = $js.Eval("myArray[0];")
$myArray[1] = $js.Eval("myArray[1];")
$myArray[2] = $js.Eval("myArray[2];")

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

A Javascript Array is actually an object and

$x = $js.Eval("myArray;")

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thinks a lot Dale !! (Frensh kiss !)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi

A more OO alternative to 

Full javascript arrays in auto it

see this post
 
 

 

$myArray[0] = $js.Eval("myArray[0];")

 add a item(n) method to the js array object

Add this to your web page

Array.prototype.item =function( i ) { return this }  ;

 

ConsoleWrite("$myArray[0] = " & $myArray.item(0) & @CR) ; a way to access the array YES!
 
 
and
 
Edited by ozmike

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0