Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Here is my code...
var a, table1
a = new ActiveXObject("MyProgID");  a.GetDataFromExcel("C:\\Users\\myFolder\\Desktop\\test.xls","Sheet1")
a.Generate()
table1 = a.writeInTable();

Here writeInTable function returns a 2D Object array from DLL written in VB.Net. So I got the Object to table1.
But from table1, I can't access the values but its there. table1 shows values as in this image(Image Attached.)

Actually, I tried many ways like
tab(0)(0)
tab[0][0]
tab["0"]
tab.(0).(0)
tab.[0].[0]
Also with toArray(), (new VBArray(tab)).toArray()....


I don't know what I am wrong..Can anyone help me on this?


Thanks...
Shanmugavel.C
Posted
Comments
[no name] 27-Jun-11 20:29pm    
What values does table1 show? There is no image attached.

Perhaps this can help you achieve your goal.

If you can return a string from a.writeInTable() you can use the javascript eval() function [^] to create a 2d array. Consider this example:

HTML
<html>
<body>
<script type="text/javascript">
JavaScript
// Make a.writeInTable() return a string like this:
// a.writeInTable() ==> "[['Saab','Volvo','BMW'],['Apple','Orange','Lemon']]"
// var mystring = "mytable=" + a.writeInTable();

var mystring = "mytable=[['Saab','Volvo','BMW'],['Apple','Orange','Lemon']]";

// create the 2d array 'mytable'
eval(mystring);

// walk through the array
for (i=0;i<mytable.length;i++)>
{
  for (j=0;j<mytable[i].length;j++)>
  {
    document.write(i+ ',' + j + ': ' + mytable[i][j] + "<br />");
  }
}
HTML
</script>
</body>
</html>


This will show the following result:

0,0: Saab<br />
0,1: Volvo<br />
0,2: BMW<br />
1,0: Apple<br />
1,1: Orange<br />
1,2: Lemon


For more information on 2d arrays take a look at this thread:
http://www.webdeveloper.com/forum/showthread.php?t=90849[^]
 
Share this answer
 
v2
Comments
harish85 29-Jun-11 20:25pm    
my 5 for this! some how we need serialize those array from activex return to JS engine.
There might be two problems with your code.
First, ActiveXObject class does not takes progid instde is takes the ActiveX control name.
Second, The activex object might not be register in your system.

Try to address these problem your code might start working.
 
Share this answer
 
Sorry..
Actully my DLL got registered successfully and able to create instance. Also other functions are working.
Even this function is working but here my problem is what data type to return so that i can use it in my target scripting?

Object or array and how to access that one in my scripting?

Thanks,
Shanmugavel.C
 
Share this answer
 
I don't think you can assign an two dimensional array that way
table1 = a.writeinTable1()
if writeinTable1() is returning a 2D array of objects.

Consider serializing your result from writeinTable(). You might need to pass the output this
way - a11 \t a12 \t a13 \n a21 \t a22 \t a23 \n a31 \t a32 \t a33
where \t and \n are row sep or col sep respectively....

then process them in the javascript using split fns,
- Thanks
 
Share this answer
 
v2
2D array should be declared in a different way in java script

<pre lang="cs">var table1=new Array(3)
for (i=0; i &lt;3; i++)
table1[i]=new Array(3)</pre>
 
Share this answer
 
If I understand correctly you use 'writeInTable' to retrieve data as a 2d array and add this to a table using javacript.

Why don't you create a table in your dll?
Create a function ReturnTable that returns html. You can then simply add this to a container. Take a look here: http://www.easywayserver.com/blog/javascript-innerhtml/[^]

If you want to create a new table then that's all.
If you want to add the rows to an existing table you can easily access the rows and cells, since it is a table object.
 
Share this answer
 
v2
Thanks for the info Ruard...

Actually I am not dealing with webPages. Am working with some automation testing kind stuff. That's why I want to return back to JavaScript varibale from my DLL...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900