Page 1 of 2

idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 9:15 am
by NewGuy
Hey there

i have been trying to figure out how to implement a banner system in my VB apps ... something like whats in MSN or other simular apps. - but with no success

the idea is that it should be dynamic .. and self updateable

I was playing with the idea that the app. was "born" with ex. 5 banners .. and when the app. was started up, it would test to see there was internet access .. and if there was.. it would go to a website ex:

http://www.myhomepage.com/banners

and download the banners from that homepage .. and start to display them in the app.

on the homepage there would be a range of banners, witch i would have given a number, ex. between 1 to 200

if no internet is present .. it just shows the banners that it was born with .. or the latest banners it dowloaded last time there was internet

and of cource in the VB app .. there also needs to be implemented a banner rotator/presentation

any ideas/suggestions for a super banner system ? :) ... i love VB and still in the starting pit

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 9:50 am
by CodenStuff
Hello NewGuy,

I think the quickest way would be to add a webbrowser control to your form and point it to your banner page URL (get a simple javascript banner rotation script and add it to the page).

Or a webrequest to read the page source then grab the images/links and maybe use a timer to loop through the banners and display them in a picturebox.

How are you currently doing it?

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 11:06 am
by NewGuy
Hi .. and thanks for a quick answer

i was thinking about the webbrowser control too .... i have been playing with that .. but i found a few things that makes webbrowser control maybe not the best way to go in my opinion :-)
1) Takes more resources
2) Looks a bit clumsy - and i guess it won't even display images if the feature is turned off in IE ?
3) Slow

the idea was not to show banners directly from the homepage - but to show the local included banner files .. maybe in a picture control ? .. and then download/add new banners, if new ones are available on the webpage

this way i rule out the nessesity to be on internet

the download of new banners should be "hidden" from the end user

i dont have much actual code right now, sorry ... just getting to know this awsome program :-) keeps me up at night ;)

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 12:18 pm
by Codex
You can make a text file, and add a direct link to a banner on each new line, and then you can use a timer to loop through them, each 2 minutes, display the next banner from next new line, using picturebox1.imagelocation = link

I can make a fast example for you.

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 1:11 pm
by NewGuy
ahhh ok .... yeah ... a text file .. cool idea

thank you ... i would love to see a example of that ... seems like a easy way to go for a novice like me :)

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 4:21 pm
by Zulf
Download text file.
Read url.
Go to url.
Download banner.
Show banner.

You can also use this for auto-updating:

Download text file.
Read file version.
Check if file version is greater than app version.
If result is yes:
Download new files (exe, dll, images, etc..)
If result is no:
Ignore.

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 8:19 pm
by MrAksel
I'll make a DLL for you check back on this post later, I'll edit and post the attachment .

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 10:22 pm
by Axel
Why don't you just make functions instead of dlls or whatever? Much easier to use and much more "pro" if you will

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sat Jun 04, 2011 10:41 pm
by NewGuy
Axel wrote:
Why don't you just make functions instead of dlls or whatever? Much easier to use and much more "pro" if you will
i am open for suggestions .. i have no pref ... could you maybe be so kind as to give a example of this ?

thank you !

Re: idea for a app. banner rotator w/ automatic Internet updates

Posted: Sun Jun 05, 2011 1:43 pm
by mandai
You could use this:
Code: Select all
    Dim imageList As String()

    Sub refreshBanners()

        Dim wc As WebClient = New WebClient()
        Dim banners As List(Of Image) = New List(Of Image)

        For i As Integer = 0 To imageList.Length - 1 'downloads and stores the images in memory
            Dim imagebytes As Byte()
            Try
                imagebytes = wc.DownloadData(imageList(i))
            Catch ex As Exception
                MsgBox("Error downloading banner " & imageList(i) & ": " & ex.Message)
                Continue For
            End Try

            Dim ms As MemoryStream = New MemoryStream(imagebytes)

            Dim img As Image
            Try
                img = Image.FromStream(ms)
            Catch ex As Exception
                MsgBox("Error getting image from " & imageList(i))
                Continue For
            Finally
                ms.Close()
            End Try

            picBanner.Image = img
            banners.Add(img)

            Thread.Sleep(10000) 'starting delay per banner
        Next

        If banners.Count = 0 Then Return

        While True 'loops through downloaded images

            For i As Integer = 0 To banners.Count - 1
                picBanner.Image = banners(i)
                Thread.Sleep(10000) 'delay per banner
            Next
        End While
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim wc As WebClient = New WebClient()
        imageList = wc.DownloadString("http://localhost/banners.txt").Split(vbCr)
        For i As Integer = 0 To imageList.Length - 1
            imageList(i) = imageList(i).Replace(vbLf, "")
        Next

        Dim t As Thread = New Thread(AddressOf refreshBanners)
        t.IsBackground = True
        t.Start()
    End Sub
Where banners.txt could be something like this:
Code: Select all
http://localhost/banners/banner1.png
http://localhost/banners/banner2.png