Jump to content

Javascript array to autoit array


mary
 Share

Recommended Posts

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
Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

  • 6 years later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...