473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Converting a JS array into a VBArray

Hi,

Can anybody give me a hint as to how to convert a javascript array into a
vbscript array?

BTW-it only needs to work in IE5 & 6

Thanks in advance,
John MacIntyre
VC++ / VB / ASP / Database Developer
http://www.johnmacintyre.ca
Here's some sample code I threw together to explain the problem.

-----------------------------------------------------
<%@ Language=VBScript %>
<html>
<script language=javascript>
function getJSArray()
{
var retArray new Array();

retArray[0] = new Object();
retArray[0].firstName = "Joe";
retArray[0].lastName = "Doe";
retArray[1] = new Object();
retArray[1].firstName = "Sally";
retArray[1].lastName = "Struthers";

return retArray;
}
</script>
<body>
<%
dim myArray()
dim nLoopCnt
dim oName

myArray = getJSArray()
for nLoopCnt = 0 to 3
oName = myArray(nLoopCnt)
Response.Write "<P>" & oName.firstName & " " & oName.lastName &
"</P>"
next
%>
</body>
</html>

Jul 20 '05 #1
3 11431
On Sun, 28 Sep 2003 20:51:00 -0400, "John MacIntyre"
<Pl****@reply.to.group.thx> wrote:
Hi,

Can anybody give me a hint as to how to convert a javascript array into a
vbscript array?

BTW-it only needs to work in IE5 & 6

Here's some sample code I threw together to explain the problem.

-----------------------------------------------------
<%@ Language=VBScript %>
<html>
<script language=javascript>
function getJSArray()
{
var retArray new Array();

retArray[0] = new Object();
retArray[0].firstName = "Joe";
retArray[0].lastName = "Doe";
retArray[1] = new Object();
retArray[1].firstName = "Sally";
retArray[1].lastName = "Struthers";

return retArray;
}
</script>
<body>
<%
dim myArray()
dim nLoopCnt
dim oName

myArray = getJSArray()
for nLoopCnt = 0 to 3
oName = myArray(nLoopCnt)
Response.Write "<P>" & oName.firstName & " " & oName.lastName &
"</P>"
next
%>
</body>
</html>


Your example code is running Javascript on the client-side and
VBScript on the server-side. Is that what you're trying to do or are
you writing ASP in both VBScript and JScript?

The only way to pass data from the client-side to the server-side is
to send a GET or POST request, i.e. navigate to a URL with
?something=somedata or submit a form. You could do something like...
var sUrl = "somepage.asp?name1=Joe,Doe&name2=Sally,Struthers" ;
window.location.href = sUrl;
and then loop through the parameters and values on the server-side,
something like...
Dim myArray()
i = 1
While Request("name" & i).Count != 0
myArray(i) = Split(Request("name" & i), ",")

(My VBScript is probably way off. I've tried to stay away from
learning VBScript.)

Regards,
Steve
Jul 20 '05 #2
"Steve van Dongen" <st*****@hotmail.com> wrote in message
news:03********************************@4ax.com...
On Sun, 28 Sep 2003 20:51:00 -0400, "John MacIntyre"
<Pl****@reply.to.group.thx> wrote:
Hi,

Can anybody give me a hint as to how to convert a javascript array into a
vbscript array?

BTW-it only needs to work in IE5 & 6

Here's some sample code I threw together to explain the problem.
-----------------------------------------------------

Your example code is running Javascript on the client-side and
VBScript on the server-side. Is that what you're trying to do or are
you writing ASP in both VBScript and JScript?


You are right .. I forgot runat=server in the sample I provided.

But it still doesn't work.

Thanks in advance,
John MacIntyre
VC++ / VB / ASP / Database Developer
http://www.johnmacintyre.ca

-----------------------------------------------------------------
<%@ Language=VBScript %>
<html>
<script language=javascript runat=server>
function getJSArray()
{
var retArray = new Array();

retArray[0] = new Object();
retArray[0].firstName = "Joe";
retArray[0].lastName = "Doe";
retArray[1] = new Object();
retArray[1].firstName = "Sally";
retArray[1].lastName = "Struthers";

return retArray;
}
</script>
<body>
<%
dim myArray()
dim nLoopCnt
dim oName

myArray = getJSArray() '<-- gives 'Type Mismatch' error
for nLoopCnt = 0 to 3
oName = myArray(nLoopCnt)
Response.Write "<P>" & oName.firstName & " " & oName.lastName & "</P>"
next
%>
</body>
</html>

Jul 20 '05 #3
John MacIntyre wrote:
Can anybody give me a hint as to how to convert a javascript array into a
vbscript array?

BTW-it only needs to work in IE5 & 6

Here's some sample code I threw together to explain the problem.
-----------------------------------------------------

.. I forgot runat=server in the sample I provided.

But it still doesn't work.

Javascript arrays are an object type with additional features. My
testing shows that when accessed from VB, they are still objects rather
than VB's idea of an array.

Additionally
a) VB gave errors when attempting to retrieve object properties with
numeric property names (the javascript implementation of arrays), and
b) the Set keyword must be used when assigning obects in VB.

In workaround, I added a getter to the prototype for Array objects in
JScript, to allow retrieval of subscripted entries by function call.
This is called using zero based indexing, of course, taking care not to
exceed array dimensions. So the script tested in IE5 ended up as:

<%@ Language=VBScript %>
<html>
<script language=javascript runat=server>

// Define a getter for Array entries

Array.prototype.get = function(prop)
{
return this[prop];
}

function getJSArray()
{
var retArray = new Array();
retArray[0] = new Object();
retArray[0].firstName = "Joe";
retArray[0].lastName = "Doe";
retArray[1] = new Object();
retArray[1].firstName = "Sally";
retArray[1].lastName = "Struthers";

return retArray;
}
</script>
<body>
<%
dim myArray 'removed array-like declaration
dim nLoopCnt
dim oName

Set myArray = getJSArray() 'use Set for objects
' notice myArray is not a VBScript array:
Response.Write("isArray(myArray) = " & isArray(myArray) & "<BR>")

for nLoopCnt = 0 to 1 'keep lookup in bounds
Set oName = myArray.get(nLoopCnt) 'use .get for numeric lookup, and
'use Set for object assignment
Response.Write "<P>" & oName.firstName & " " & oName.lastName & "</P>"
next
%>
</body>
</html>

By removing the ASP tags, surrounding the VB between <SCRIPT
LANGUAGE="VBSCRIPT"> and </SCRIPT> tags, and changing "Response.Write"
to "Document.Write", it also checks out client side in IE6. I am not a
VBScript expert, however, so am unable say how typical this solution
might be.
HTH

Dom

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
3
by: Dana | last post by:
I have a form with a couple of dropdown fields. the dropdown fields get the value from one table which is a reference table. The table consists of 3 columns - type, id, name. An example would...
2
by: Tomas Deman | last post by:
Hi, I need a fast method for converting an int array to a byte array. At the moment, I'm using this: public static byte Int2ByteArray(int array) { byte lbytRetval = new byte; int lintIdxHi;...
11
by: Laphan | last post by:
Hi All I'm using .getRows() with a local var array instead of doing a recursive loop so that I'm being a good ASP newvbie and closing my object i/o's (the recordset in this case) as quick as...
1
by: Andrew | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hi This VB script prints out a ragged VB array public function display(vbreply) For I = LBound(vbreply) To UBound(vbreply)...
18
by: No Such Luck | last post by:
Hi all: I have an unsigned char array (size 4): unsigned char array; array = 0x00; array = 0x00; array = 0x02; array = 0xe7;
3
by: Pete Davis | last post by:
I've never done this in C# so I don't know what the appropriate way of doing it is. I've got an array of bytes and I need to convert the array into "usable" data. For example, the first 4 bytes...
10
by: thinktwice | last post by:
in my script file , i need call a method of a atl com module(implemented in vc++), which returan an safearray. i don't know how to convert it into array in jscript. i have tried serveral ways to...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.