Passing a VBscript array to java Array (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


lyners -> Passing a VBscript array to java Array (8/26/2003 14:01:11)

I am trying to pass an array I created in VBscript to an array in java script.

What I have done is created code that accesses a table. I take the data from the table and put it in an array. Now I need to use javascript to do what I need to do, but I must use the array I created in the vbscript. I do not know how to do this, or I am having a very difficult time trying to figure it out.

here Is the code

<%
' =============================
' Get Data from Table
' =============================
' Set variables
DIM myDSN, mySQL, conntemp, rstemp, aMonthValues
' The next lines are for Access DBs - rename the DB name to match yours
' Use this next one for Access 97
' myDSN=" DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("/fpdb/myDatabase.mdb" )
' Uncomment the next one for Access 2K / XP
myDSN =" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("../capfin/fpdb/capital.mdb" )

' Put your SQL next
mySQL="SELECT 'Project_Images/'+[FileName] AS Expr1 FROM Project_Info " & _
      "INNER JOIN Files ON (Project_Info.Phase = Files.Phase) AND " & _
      "(Project_Info.Sub_Project = Files.Sub_Project) AND " & _
      "(Project_Info.Project = Files.Project)"
' Build & connect
set conntemp=Server.CreateObject("ADODB.Connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
If  rstemp.eof then
   picture(0) = "project_Images/blank.jpg"
end if

' grab records
picture=rstemp.getrows

Call Cleanup

SUB Cleanup
   rstemp.close
   set rstemp=nothing
   conntemp.close
   set conntemp=nothing
END SUB

for i = 0 to ubound(picture,2)
	response.write "<p>" & picture(i) & "</p>
next 1
' =========================
' End of get Data
' =========================
%>

<script>

// (C) 2002 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header.

// ==============================
// Set the following variables...
// ==============================

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 3000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var Picture = new Array(); // don't change this
//var Caption = new Array(); // don't change this

// Specify the image files...
Picture = <%picture%> 

// =====================================
// Do not edit anything below this line!
// =====================================

var tss;
var iss;
var jss = 0;
var pss = Picture.length-1;

var preLoad = new Array();
for (iss = 0; iss < pss+1; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = Picture[iss];}

function runSlideShow(){
if (document.all){
document.images.PictureBox.style.filter="blendTrans(duration=2)";
document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
document.images.PictureBox.filters.blendTrans.Apply();}
document.images.PictureBox.src = preLoad[jss].src;
if (document.all) document.images.PictureBox.filters.blendTrans.Play();
jss = jss + 1;
if (jss > (pss)) jss=1;
tss = setTimeout('runSlideShow()', SlideShowSpeed);
}
</script>


What do I need to do to use the array I created in the vbscript to use it in the Java?

Thanks ahead of time!




rdouglass -> RE: Passing a VBscript array to java Array (8/26/2003 15:59:12)

The basic rule of thumb that I use is that JavaScript runs at the client and VBScript in ASP runs at the server. So what I try to do is to make VBScript response.write the JavaScript code. Here is an example of one I use. Again, I don't actually pass the VBScript array to the JavaScript, I use the VBScript array to write out the JavaScript.


****************************
<%
Response.write("<script>" & vbcrlf)
Response.write("<!--" & vbcrlf)

Response.write("var content=new Array()" & vbcrlf)

Response.write("content[0]='<font face=" & CHR(034) & "Verdana" & CHR(034) & " size=" & CHR(034) & "2" & CHR(034) & "><b>Our New Look!</b></font><br><br><font face=" & CHR(034) & "Verdana" & CHR(034) & " size=" & CHR(034) & "1" & CHR(034) & ">This area is used to display the next 3 events for the user being selected.<br><br>Hold the cursor over a name to see the next 3 events.</font>'" & vbcrlf)

'next line is an external function
buildUserArray(1)

numrows=ubound(alldata,2)

myIDList = ""
FOR rowcounter= 0 TO (numrows)
myIDList = myIDList & alldata(3,rowcounter) & ","
NEXT
myIDList = left(myIDList,(len(myIDList)-1))

set conntempIDList=server.createobject("adodb.connection")
conntempIDList.open myDSN
mySQLIDList = ("SELECT * FROM tblItems WHERE (UserOut = true) ORDER BY ItemStart ASC")
set rstempIDList=conntempIDList.execute(mySQLIDList)

IF rstempIDList.eof THEN
Response.write("No IDs in list!")
rstempIDList.close
set rstempIDList=nothing
conntempIDList.close
set conntempIDList=nothing

ELSE

' Now lets grab all the records
alldataIDList=rstempIDList.getrows
rstempIDList.close
set rstempIDList=nothing
conntempIDList.close
set conntempIDList=nothing
END IF

FOR rowcounter= 0 TO (numrows)
'lastname=alldata(0,rowcounter)
'firstname=alldata(1,rowcounter)

Response.write("content[" & alldata(3,rowcounter) &"]='<font face=" & CHR(034) & "Verdana" & CHR(034) & " size=" & CHR(034) & "2" & CHR(034) & "><b>" & alldata(0,rowcounter)& ", " & alldata(1,rowcounter) & "</b></font><br><br>")
Response.write("<font face=" & CHR(034) & "Verdana" & CHR(034) & " size=" & CHR(034) & "1" & CHR(034) & ">" & nextThreeEvents(alldata(3,rowcounter)))
Response.write("</font>'" & vbcrlf)
NEXT

Response.write("function regenerate(){" & vbcrlf)
Response.write("window.location.reload()" & vbcrlf)
Response.write("}" & vbcrlf)
Response.write("function regenerate2(){" & vbcrlf)
Response.write("if (document.layers){" & vbcrlf)
Response.write("appear()" & vbcrlf)
Response.write("setTimeout(" & CHR(034) & "window.onresize=regenerate" & CHR(034) & ",450)" & vbcrlf)
Response.write("}" & vbcrlf)
Response.write("}" & vbcrlf)

Response.write("function changetext(whichcontent){" & vbcrlf)

Response.write("if (document.all||document.getElementById){" & vbcrlf)
Response.write("cross_el=document.getElementById? document.getElementById(" & CHR(034) & "descriptions" & CHR(034) & "):document.all.descriptions" & vbcrlf)
Response.write("cross_el.innerHTML='<font face=" & CHR(034) & "Verdana" & CHR(034) & " size=" & CHR(034) & "1" & CHR(034) & ">'+whichcontent+'</font>'" & vbcrlf)
Response.write("}" & vbcrlf)
Response.write("else if (document.layers){" & vbcrlf)
Response.write("document.d1.document.d2.document.write('<font face=" & CHR(034) & "Verdana" & CHR(034) & " size=" & CHR(034) & "1" & CHR(034) & ">'+whichcontent+'</font>')" & vbcrlf)
Response.write("document.d1.document.d2.document.close()" & vbcrlf)
Response.write("}" & vbcrlf)

Response.write("}" & vbcrlf)

Response.write("function appear(){" & vbcrlf)
Response.write("document.d1.visibility='show'" & vbcrlf)
Response.write("}" & vbcrlf)

Response.write("window.onload=regenerate2" & vbcrlf)


Response.write("//-->" & vbcrlf)
Response.write("</script>" & vbcrlf)
%>
**********************

It ends up being a big excersize in loops and response.writes...[:D]

Does that help any????




lyners -> RE: Passing a VBscript array to java Array (8/26/2003 17:08:23)

In short. Awesome [:D] I've used that type of coding when doing Zebra II language, but I didn't think about it here. I have everything working, but I need an extra set of eyes. I am getting a "Subscript out of range: 'Picture'" when running this.

My ubound returns 3, which is what it is suppose to do. Do you see a problem with my for loop?

myDSN =" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("../capfin/fpdb/capital.mdb" )

' Put your SQL next
mySQL="SELECT 'Project_Images/'+[FileName] AS Expr1 FROM Files"
' Build & connect
set conntemp=Server.CreateObject("ADODB.Connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
If  rstemp.eof then
   picture(0) = "project_Images/blank.jpg"
else
	' grab records
	picture=rstemp.getrows
end if

Call Cleanup

SUB Cleanup
   rstemp.close
   set rstemp=nothing
   conntemp.close
   set conntemp=nothing
END SUB

' =========================
' End of get Data
' =========================

'==========================
'Create javascript through vb
'==========================

response.write "<p>" & ubound(picture,2) & "</p>"
response.write("<script>" & vbcrlf)
response.write("var SlideShowSpeed = 3000;" & vbcrlf)
response.write("var CrossFadeDuration = 3;" & vbcrlf)
response.write("var Picture = new Array();" & vbcrlf)
for i = 1 to ubound(picture,2)
	response.write("Picture[" & i &"]  = '" & picture(i) & "'" & vbcrlf)	
next
response.write("var tss;" & vbcrlf)
response.write("var iss;" & vbcrlf)
response.write("var jss = 0;" & vbcrlf)
response.write("var pss = Picture.length-1;" & vbcrlf)
response.write("var preLoad = new Array();" & vbcrlf)
response.write("var preLoad = new Array();" & vbcrlf)
response.write("for (iss = 0; iss < pss+1; iss++){" & vbcrlf)
response.write("preLoad[iss] = new Image();" & vbcrlf)
response.write("function runSlideShow(){" & vbcrlf)
response.write("if (document.all){" & vbcrlf)
response.write("document.images.PictureBox.style.filter='blendTrans(duration=2)';" & vbcrlf)
response.write("document.images.PictureBox.style.filter='blendTrans(duration=CrossFadeDuration)';" & vbcrlf)
response.write("document.images.PictureBox.filters.blendTrans.Apply();}" & vbcrlf)
response.write("document.images.PictureBox.src = preLoad[jss].src;" & vbcrlf)
response.write("if (document.all) document.images.PictureBox.filters.blendTrans.Play();" & vbcrlf)
response.write("jss = jss + 1;" & vbcrlf)
response.write("if (jss > (pss)) jss=1;" & vbcrlf)
response.write("tss = setTimeout('runSlideShow()', SlideShowSpeed);" & vbcrlf)
response.write("}" & vbcrlf)
response.write("</script>" & vbcrlf)
%>



And to make sure this is legal, the java code for the picture rotate came from Codelifter.com [;)]

Thanks!




Spooky -> RE: Passing a VBscript array to java Array (8/27/2003 0:42:37)

Any reason you are using "for i = 1 to ubound(picture,2)" for a 0 based array?
Id assume for i = 0 to ubound(picture,2)




lyners -> RE: Passing a VBscript array to java Array (8/27/2003 10:08:23)

No, that was part of testing what was happening with my picture array. I still am getting subscript out of range error on it. I will make it 0 again, but that still won't fix my problem. I bet this is something simple that I just don't see.




lyners -> RE: Passing a VBscript array to java Array (8/27/2003 12:00:47)

Figured it out.

When using getrows, the array that is retrieved must be accessed by using array(column,row). You cannot just say array(row), which I was trying. So my answer for the above problem was;

picture(0,i)

And the rest is history. [:)]

Thanks for all the help!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.140625