slide show in vb

A

Adam Sandler

Hello,

I'd like to do a slide show in VB. I have one in JavaScript but the
one in JavaScript always counts on the images to be in a given
directory. This doesn't have to be fancy... something like...
Me.Image1.ImageUrl = myArray(i) and automatically repeating. The
reasons for why I want to do it in VB follow.

The images for this slideshow will be retrieved from links on a
webpage. The code for this uses regular expressions to search for the
files... the files conform to a standard naming scheme so any risk is
minimized

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

CONST WEBPAGE =
"http://www.srh.noaa.gov/ridge/RadarImg/N0R/FTG/"

Dim objHTTP
Dim strHTMLSource As String

' Get stuff from other webpage
objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.Open("Get", WEBPAGE, False)
objHTTP.Send()

' Load the target webpage into memory... it's small
strHTMLSource = objHTTP.ResponseText

' Look for files which begin with "FTG"
myMatcher("FTG", strHTMLSource)

End Sub

' myMatcher(what I'm looking for, where to search)
Sub myMatcher(ByVal strMatchPattern, ByVal strSource)

Dim i, j As Integer

Dim myRegEx As Regex = New Regex(strMatchPattern,
RegexOptions.IgnoreCase)
Dim c As MatchCollection = myRegEx.Matches(strSource)

i = 0

' iterate through the collection
Dim m As Match
For Each m In c
ReDim Preserve myArray(i)
myArray(i) = m.Index
i = i + 1
Next

Dim s As String

' Get the most recent 10 file names...
' Accomplished by using the positions found by the pattern
matcher
For j = UBound(myArray) To (UBound(myArray) - 20) Step -1
' remainder division eliminates duplicate file names which
would be sucked up
' from both the link's text and the a href tag
If j Mod 2 = 0 Then
s = Mid(strSource, myArray(j + 1), 26)
Response.Write(s & "<br />") ' for debug...
End If
Next

Once I get the files I'm interested in using, then I figured I could
just loop through the array and provide an asp image object the url
contained in anyArray(i).

u = UBound(myArray)

For i = 0 To (u - 1)
Me.Image1.ImageUrl = myArray(i)
System.Threading.Thread.Sleep(3000)
Next

Doing something like the preceeding loop doesn't work... I really don't
want anymore complexity then something like the loop above and the
images to automatically repeat. Any suggestions?

Thanks!
 
N

Nick Malik [Microsoft]

Your code demonstrates a very practical (and somewhat procedural) approach
to writing code. For you, I'd suggest that the easy answer is to throw in
Application.DoEvents() after each assignment to ImageUrl.

Here's a thread that discussed this issue not that long ago.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=469916&SiteID=1

Hope this helps,
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
A

Adam Sandler

Nick said:
For you, I'd suggest that the easy answer is to throw in
Application.DoEvents() after each assignment to ImageUrl.

Here's a thread that discussed this issue not that long ago.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=469916&SiteID=1

Nick,

Thanks for the reply... I'm confused though. My post was about looping
through paths to images which are contained in an array. I'm not sure
what that has to do with refreshing a page.... could you please
clarify?

Thanks!
 
N

Nick Malik [Microsoft]

You posted code, including:
u = UBound(myArray)
For i = 0 To (u - 1)
Me.Image1.ImageUrl = myArray(i)
System.Threading.Thread.Sleep(3000)
Next
Doing something like the preceeding loop doesn't work

There is no particular reason why this shouldn't work, except that you don't
give the current thread time to actually get and display the image. So I'm
asking you to try adding a DoEvents in the loop before the Thread.Sleep to
see if that helps. I didn't run your code on my box to see if you got
actual URLs in your array. I'm assuming you did.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
A

Adam Sandler

Nick said:
You posted code, including:




There is no particular reason why this shouldn't work

Which is why I'm here ;) I just need a very simple way of rotating
through a collection of images... no effects, nav buttons etc... just
looping through my images.
So I'm asking you to try adding a DoEvents in the loop before the Thread.Sleep to
see if that helps.

I was hoping there was a VB way to preload images. Kinda like in
JavaScript so that mouseovers are not all jacked up when the page is
first visited. Unfortunately, it cannot help... DoEvents is not a
member of System.Web.HTTPApplicationState
I didn't run your code on my box to see if you got actual URLs in your array. I'm
assuming you did.

Here's everything as a sanity check. I've hardcoded some paths until
this gets working. Then I'll change it over to iterating through my
array:

Dim myArray() As String =
{"http://csfdgis/Lightning/Images/DeleteMe/pic1.jpg", _

"http://myServer/Lightning/Images/pic2.jpg", _

"http://myServer/Lightning/Images/pic3.jpg", _

"http://myServer/Lightning/Images/pic4.jpg", _

"http://myServer/Lightning/Images/pic5.jpg"}

Dim i, u As Integer

u = UBound(myArray)

For i = 0 To (u - 1)
Me.Image1.ImageUrl = myArray(i)
' Application.DoEvents()
System.Threading.Thread.Sleep(3000)
Next


Thanks again for your help thus far!
 
N

Nick Malik [Microsoft]

Adam Sandler said:
I was hoping there was a VB way to preload images. Kinda like in
JavaScript so that mouseovers are not all jacked up when the page is
first visited. Unfortunately, it cannot help... DoEvents is not a
member of System.Web.HTTPApplicationState

No. Doevents is not part of System.Web. It is
System.Windows.Forms.Application.DoEvents()

The code you wrote won't work in ASP.Net. Not even close. Is that what you
are trying to do? You never mentioned that you were writing an ASP.Net app,
so I assumed you were writing a VB rich client. Let me know if I've been
barking up the wrong tree.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
A

Adam Sandler

Nick said:
You never mentioned that you were writing an ASP.Net app,
so I assumed you were writing a VB rich client.

I apologize... I assumed I was in the aspnet newsgroup.

As far as what I'm trying to do is find a VB way to make a simple
slideshow... by taking a collection and iterating through it. Nothing
more and nothing less.

If that collection is an array of strings and each string is a URL,
then I can throw array into the ImageUrl property a asp Image
component.

I already have something working in JavaScript. I'd like to convert it
to VB (and that is where I'm havuing the obvious difficulty)...

document.images.myImage.src = wxImages[imageCounter].src

// go until the last images is reached and then reset(start
over)
if (imageCounter < wxImages.length - 1)
imageCounter++
else
imageCounter = 0
 
N

Nick Malik [Microsoft]

Adam Sandler said:
I apologize... I assumed I was in the aspnet newsgroup.

My bad. I answer questions in different groups. Please forgive.
As far as what I'm trying to do is find a VB way to make a simple
slideshow... by taking a collection and iterating through it. Nothing
more and nothing less.

From a web client, it makes more sense to do this client side using
Javascript. Feeding it from the server doesn't make sense in the stateless
web model.
If that collection is an array of strings and each string is a URL,
then I can throw array into the ImageUrl property a asp Image
component.


And why would your client come back to the server to get the new image?
Once it has an image, it's done. You'd need to put code into the client
telling it to come back for the next image. Then, on the server side,
simply keep state and move an array index for each call. Doesn't make
sense, though. Better to have the client "aware" of the list of images and
to iterate from there.
I already have something working in JavaScript.

stop there. you are done.
I'd like to convert it
to VB (and that is where I'm havuing the obvious difficulty)...

because it is a bad idea, unless there are requirements that you have not
shared that make it worth doing.


Sorry I couldn't help you to achieve this idea.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
A

Adam Sandler

Nick said:
From a web client, it makes more sense to do this client side using
Javascript. Feeding it from the server doesn't make sense in the stateless
web model.

My goal is indeed to have the client side do the processing... sorry
for any confusion.
And why would your client come back to the server to get the new image?

The client isn't going back to the server... it's going to an external
website. The list of images I'm getting is created on the client side
and the images themselves update every four minutes. So I have to
account for different file names because they have a time stamp as a
part of the file name. I find the file names I need via some regular
expression code I wrote.
Once it has an image, it's done. You'd need to put code into the client
telling it to come back for the next image.

Which I already have -- I put the regular expression method in the
page_load to build my array with the list of maching file names.
Better to have the client "aware" of the list of images and
to iterate from there.

I thought I was doing that -- everything is on the client side; please
let me know where I put server side code in so I can correct it.
stop there. you are done.

because it is a bad idea, unless there are requirements that you have not
shared that make it worth doing.

The reason why I'd like to convert the simple JavaScript slideshow
(posted previously) is that my matcher and array are in VB (the regular
expression stuff I mentioned above).

So unless there's a way to pass VB as a parameter to a JavaScript
argument, I'd prefer to convert my JavaScript example to VB. I have no
freaking clue how I would even attempt to use something which simulates
regular expressions in JavaScript and searching the web hasn't been
fruitful.

As far as the reason why some of my code is in VB and some in
JavaScript. I'm trying merging things I've done on other projects
which worked well by themselves into working together on my latest
task.

Thanks for the help thus far!
 
N

Nick Malik [Microsoft]

I am sorry for my confusion. You've got me confused again. VB in the
ASP.NET environment ONLY runs on a server. It never runs on a client. The
only way that VB.Net runs on a client is in a rich client environment
(windows app or click-once app).

Of course, VBScript runs in IE, if that's what you are doing, but I don't
think it is. I don't think you have regular expressions in VBScript.

Here's what I _think_ you want:

User requests a page. HTML page downloads. This includes Javascript. The
Javascript immediately calls back to the server for data.
Server code executes: The server code figures out the list of URLs you want.
The server code is written in VB.Net and runs in the ASP.Net
environment.
The server code returns a list of URLs in JSON or XML format.
Client code receives the data and stores it in a data island or an array.
Whatever you are comfortable using.
Client code runs a timer in Javascript. Gets the next image using the list
of URLs returned by the server.

This is called the AJAX model, but Microsoft provides controls under the
moniker of Atlas. See http://atlas.asp.net for detailed information on
these controls and on the Ajax programming model using ASP.Net

I hope this helps.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
A

Adam Sandler

Nick said:
See http://atlas.asp.net for detailed information on
these controls and on the Ajax programming model using ASP.Net

I hope this helps.

It does... I was wondering if I would have to go down the AJAX road.
Sorry for the confusion... I'm getting fed a lot of new stuff all at
once and not being very elegant about it -- add AJAX to the list now!
At any rate, thanks for your patience and assistance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top