Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merging two different sets of code

Status
Not open for further replies.

gibbo171

Programmer
Dec 13, 2007
33
GB
All

I am still trying (without success) to get a simple slideshow on my local PC that will work on an HTML page but get the images from a folder on my hard drive.

I have got the following code in VB Script to access my files and add them to an array which works on my local Computer

******************************************

GetFileList "C:\Documents and Settings\HP_Owner\Desktop\Slideshow\pics\"

Function GetFileList(folder)

intcount = 0
Dim fileArray()

Set fso = CreateObject("Scripting.fileSystemObject")
Set fold = fso.getFolder(folder)
For Each file in fold.files
ReDim Preserve fileArray(intcount)
fileArray(intcount)=file.Name

'Get Title from File Name Left(fileArray(intCount),Len(fileArray(intCount)-4))

intCount = intCount + 1
Next

Set fold = nothing: set fso = nothing
End Function


********************************************


I also found a really cool simple slide show script searching this forum which uses an array to populate the slide show,

My question is how can I merge the two scripts together so the array is populated from my chosen directory or can I translate the code above into javascript that will work on my computer (No Server)

I would really appreciate some help with this as although I am learning a lot I am getting nowhere

thanks

Gibbo



**********************************

<form><input type="button" value="<- Back" onclick="clearInterval(slideshow); clickphoto(-1);">&nbsp;<input type="button" value="Resume Slideshow" onclick="slideshow=setInterval('swapimage()', 1000);">&nbsp;<input type="button" value="Next ->" onclick="clearInterval(slideshow); clickphoto(1);"></form>
<div id="caption" style="font-family:arial; font-size:13;"></div><br>
<img name="photo">

<script language="javascript">

function clickphoto(direction)
{
pi += direction;
pi %= photo.length;
if (pi ==-1) pi = photo.length - 1;
displayphoto(pi);

}

function swapimage()
{
pi++;
pi %= photo.length;
displayphoto(pi);
}

function displayphoto(photonum)
{
document.images['photo'].src=photo[photonum].name;
caption.innerHTML=(photonum + 1) + ' of ' + photo.length + '<br>&nbsp;';
if (photo[photonum].caption.length > 0)
{
caption.innerHTML+='<b>' + photo[photonum].caption + '</b>';
}
caption.innerHTML+='&nbsp;';
}

function Photo(name, caption)
{
this.name=name;
this.caption=caption;
return this;
}

var photo=new Array(), pi=0;

photo[pi++]=new Photo('./pics/pic01.jpg'
,'Caption1');
photo[pi++]=new Photo('./pics/pic02.jpg','Caption2');
photo[pi++]=new Photo('./pics/pic03.jpg','Caption3');

pi=0;

var caption=document.getElementById('caption');
displayphoto(pi);

var images=new Array();

for (var ii=0;ii<photo.length;ii++)
{
images[ii]=new Image();
images[ii].src=photo[ii].name;
}

var slideshow=setInterval('swapimage()', 10000);

</script>

*************************

 
I have now managed to call a VBScript routine from Javascript but still havnt yet figured out how to pass any variables

<HTML>
<Head>
<Script Language=JavaScript>

function callVB(){

VBFunction();


}


</Script>



<Script Language=VBScript>

Function VBFunction()
Dim Test

folder = "C:\Documents and Settings\HP_Owner\Desktop\Slideshow\pics\"

intcount = 0
Dim fileArray()

set fso = CreateObject("Scripting.fileSystemObject")
set fold = fso.getFolder(folder)

for each file in fold.files
ReDim Preserve fileArray(intcount)
fileArray(intcount)=file.Name
msgbox fileArray(intCount)
intCount = intCount + 1

next
Test = intcount

set fold = nothing: set fso = nothing

End Function


</Script>
 
Got one step further as in I can now pass a variable as follows


<HTML>
<Head>




<Script Language=VBScript>

Dim VarTest



folder = "C:\Documents and Settings\HP_Owner\Desktop\Slideshow\pics\"

intcount = 0
Dim fileArray()

set fso = CreateObject("Scripting.fileSystemObject")
set fold = fso.getFolder(folder)

for each file in fold.files
ReDim Preserve fileArray(intcount)
fileArray(intcount)=file.Name
intCount = intCount + 1

next
VarTest = intcount

set fold = nothing: set fso = nothing

</Script>

<Script Language=JavaScript>


function callalert()

{
alert(VarTest);
}

</Script>


<Body>
<input type=button value="Get Alert" onclick="callalert()">
</Body>
</HTML>

Now just need some help with the last bit please

thanks for looking

Gibbo
 
All

I have now managed to embed a javascript slideshow into a vb script that will run on my local PC, it all works fine except for when i want the images to automatically rotate, anyone got any ideas why this bit wont work for me please

thanks

Gibbo

On Error Resume Next
Dim objFSO, oFO, oFolder, oFile, picDir, IE, Locus
Set objFSO = CreateObject("Scripting.FileSystemObject")
picDir = "C:\Documents and Settings\HP_Owner\Desktop\Slideshow\pics\"

Set oFolder = objFSO.GetFolder(picDir)
Set IE = CreateObject("InternetExplorer.Application")
With IE

.menubar=0
.toolbar=0
.statusBar=0
.navigate "About:Blank"

End With

'wait a while until IE as finished to load
Do while IE.busy
loop

With IE.document
.Open
.WriteLn "<Head>"
.WriteLn "<Title> Briefing</Title>"
.WriteLn "<SCRIPT LANGUAGE=" & Chr(34) & "JavaScript" & Chr(34) & ">"
.WriteLn "<!-- Begin var rotate_delay = 2000; // delay in milliseconds (5000 = 5 secs)"
.WriteLn "current = 0;"
.WriteLn "function next() {"
.WriteLn "if (document.slideform.slide[current+1]) {"
.WriteLn "document.images.show.src = document.slideform.slide[current+1].value;"
.WriteLn "document.slideform.slide.selectedIndex = ++current;"
.WriteLn "}"
.WriteLn "else first();"
.WriteLn "}"
.WriteLn "function previous() {"
.WriteLn "if (current-1 >= 0) {"
.WriteLn "document.images.show.src = document.slideform.slide[current-1].value;"
.WriteLn "document.slideform.slide.selectedIndex = --current;"
.WriteLn "}"
.WriteLn "else last();"
.WriteLn "}"
.WriteLn "function first() {"
.WriteLn "current = 0;"
.WriteLn "document.images.show.src = document.slideform.slide[0].value;"
.WriteLn "document.slideform.slide.selectedIndex = 0;"
.WriteLn "}"
.WriteLn "function last() {"
.WriteLn "current = document.slideform.slide.length-1;"
.WriteLn "document.images.show.src = document.slideform.slide[current].value;"
.WriteLn "document.slideform.slide.selectedIndex = current;"
.WriteLn "}"
.WriteLn "function ap(text) {"
.WriteLn "document.slideform.slidebutton.value = (text == " & Chr(34) & "Stop" & Chr(34) & ") ? " & Chr(34) & "Start" & Chr(34) & " : " & Chr(34) & "Stop" & Chr(34) & ";"
.WriteLn "rotate();"
.WriteLn "}"
.WriteLn "function change() {"
.WriteLn "current = document.slideform.slide.selectedIndex;"
.WriteLn "document.images.show.src = document.slideform.slide[current].value;"
.WriteLn "}"
.WriteLn "function rotate() {"
.WriteLn "if (document.slideform.slidebutton.value == " & Chr(34) & "Stop" & Chr(34) & ") {"
.WriteLn "current = (current == document.slideform.slide.length-1) ? 0 : current+1;"
.WriteLn "document.images.show.src = document.slideform.slide[current].value;"
.WriteLn "document.slideform.slide.selectedIndex = current;"
.WriteLn "window.setTimeout(" & Chr(34) & "rotate()" & Chr(34) & ", rotate_delay);"
.WriteLn " }"
.WriteLn "}"
.WriteLn "// End -->"
.WriteLn "</script>"
.WriteLn "</HEAD>"
.WriteLn "<BODY>"
.WriteLn "<center>"
.WriteLn "<form name=slideform>"
.WriteLn "<table cellspacing=1 cellpadding=4 bgcolor=" & Chr(34) & "#000000" & Chr(34) & ">"
.WriteLn "<tr>"
.WriteLn "<td align=center bgcolor=" & Chr(34) & "white" & Chr(34) & ">"
.WriteLn "<b>Image Slideshow</b>"
.WriteLn "</td>"
.WriteLn "</tr>"
.WriteLn "<tr>"
.WriteLn "<td align=center bgcolor=" & Chr(34) & "white" & Chr(34) & " width=600 height=400>"
.WriteLn "<img src=" & Chr(34) & " & Chr(34) & " name=" & Chr(34) & "show" & Chr(34) & ">"
.WriteLn "</td>"
.WriteLn "</tr>"
.WriteLn "<tr>"
.WriteLn "<td align=center bgcolor=" & Chr(34) & "#C0C0C0" & Chr(34) & ">"


.WriteLn "<select name=" & Chr(34) & "slide" & Chr(34) & " onChange=" & Chr(34) & "change();" & Chr(34) & ">"


For Each oFile In oFolder.Files
If Right(oFile.Name,3) = "jpg" Or Right(oFile.Name,3) = "gif" Then
Locus = "file://" & Replace(oFile.ParentFolder,"\","/")&"/" & oFile.Name
.WriteLn "<option value =" & Chr(34) & Locus & Chr(34) & ">" & oFile.Name & "</option>"
End If
Next


.WriteLn "</select>"
.WriteLn "</td>"
.WriteLn "</tr>"
.WriteLn "<tr>"
.WriteLn "<td align=center bgcolor=" & Chr(34) & "#C0C0C0" & Chr(34) & ">"
.WriteLn "<input type=button onClick=" & Chr(34) & "first();" & Chr(34) & " value=" & Chr(34) & "|<<" & Chr(34) & " title=" & Chr(34) & "Beginning" & Chr(34) & ">"
.WriteLn "<input type=button onClick=" & Chr(34) & "previous();" & Chr(34) & " value=" & Chr(34) & "<<" & Chr(34) & " title=" & Chr(34) & "Previous" & Chr(34) & ">"
.WriteLn "<input type=button name=" & Chr(34) & "slidebutton" & Chr(34) & " onClick=" & Chr(34) & "ap(this.value);" & Chr(34) & " value=" & Chr(34) & "Start" & Chr(34) & "title=" & Chr(34) & "AutoPlay" & Chr(34) & ">"
.WriteLn "<input type=button onClick=" & Chr(34) & "next();" & Chr(34) & " value=" & Chr(34) & ">>" & Chr(34) & " title=" & Chr(34) & "Next" & Chr(34) & ">"
.WriteLn "<input type=button onClick=" & Chr(34) & "last();" & Chr(34) & " value=" & Chr(34) & ">>|" & Chr(34) & " title=" & Chr(34) & "End" & Chr(34) & ">"
.WriteLn "</td>"
.WriteLn "</tr>"
.WriteLn "</table>"
.WriteLn "</form>"
.WriteLn "</center>"
.WriteLn "</body>"

.Close
End With

IE.Visible = True

Set IE = Nothing
Set objFSO = Nothing
WScript.Quit(0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top