Results 1 to 6 of 6

Thread: VB Script (yes I know)

  1. #1
    Cable Guy Jonny M's Avatar
    Join Date
    Jul 2003
    Location
    Loughborough Uni
    Posts
    4,263
    Thanks
    0
    Thanked
    4 times in 1 post

    VB Script (yes I know)

    This is part of a bit of a basic programming course here at uni, I have the following code which is meant to replace pictures with others:

    Code:
                <script language="vbs">
                    Sub Window_OnLoad
                        MyInterval = Window.SetInterval("PicRotate",500)
    		End Sub
                    Sub PicRotate
                        Dim p
    		        p = (p+1) MOD 5
                            Select Case p
                                Case 1
                                    pic1.src = "images/hitler.jpg"
                                    pic2.src = "images/polpot.jpg"
                                    pic3.src = "images/saddam.jpg"
                                    pic4.src = "images/mussolini.jpg"
                                    pic5.src = "images/stalin.jpg"
    			    Case 2
                                    pic1.src = "images/polpot.jpg"
                                    pic2.src = "images/saddam.jpg"
                                    pic3.src = "images/mussolini.jpg"
                                    pic4.src = "images/stalin.jpg"
                                    pic5.src = "images/hitler.jpg"
                                Case 3
                                    pic1.src = "images/saddam.jpg"
                                    pic2.src = "images/mussolini.jpg"
                                    pic3.src = "images/stalin.jpg"
                                    pic4.src = "images/hitler.jpg"
                                    pic5.src = "images/polpot.jpg"
                                Case 4
                                    pic1.src = "images/mussolini.jpg"
                                    pic2.src = "images/stalin.jpg"
                                    pic3.src = "images/hitler.jpg"
                                    pic4.src = "images/polpot.jpg"
                                    pic5.src = "images/saddam.jpg"
                                Case 0
                                    pic1.src = "images/stalin.jpg"
                                    pic2.src = "images/hitler.jpg"
                                    pic3.src = "imaes/polpot.jpg"
                                    pic4.src = "images/saddam.jpg"
                                    pic5.src = "images/mussolini.jpg"
                            End Select
                    End Sub
                </script>
    This is meant to loop every 500ms, but the problem is it does it once (case 1), then stops. This I don't understand, as Window.SetInterval("PicRotate",500) is meant to call it every half a second.

    Anyone got any ideas? Oh, and before you comment on the pictures, it's my terrible sense of humour.

  2. #2
    Treasure Hunter extraordinaire herulach's Avatar
    Join Date
    Apr 2005
    Location
    Bolton
    Posts
    5,618
    Thanks
    18
    Thanked
    172 times in 159 posts
    • herulach's system
      • Motherboard:
      • MSI Z97 MPower
      • CPU:
      • i7 4790K
      • Memory:
      • 8GB Vengeance LP
      • Storage:
      • 1TB WD Blue + 250GB 840 EVo
      • Graphics card(s):
      • 2* Palit GTX 970 Jetstream
      • PSU:
      • EVGA Supernova G2 850W
      • Case:
      • CM HAF Stacker 935, 2*360 Rad WC Loop w/EK blocks.
      • Operating System:
      • Windows 8.1
      • Monitor(s):
      • Crossover 290HD & LG L1980Q
      • Internet:
      • 120mb Virgin Media
    Have you tried just outputting a mesagebox or something to verify that it is actually getting called the second time? Popping up the value of p would be my choice.

  3. #3
    Cable Guy Jonny M's Avatar
    Join Date
    Jul 2003
    Location
    Loughborough Uni
    Posts
    4,263
    Thanks
    0
    Thanked
    4 times in 1 post
    Nope it's not getting past Case 1

  4. #4
    IBM
    IBM is offline
    there but for the grace of God, go I IBM's Avatar
    Join Date
    Dec 2003
    Location
    West London
    Posts
    4,187
    Thanks
    149
    Thanked
    244 times in 145 posts
    • IBM's system
      • Motherboard:
      • Asus P5K Deluxe
      • CPU:
      • Intel E6600 Core2Duo 2.40GHz
      • Memory:
      • 2x2GB kit (1GBx2), Ballistix 240-pin DIMM, DDR2 PC2-6400
      • Storage:
      • 150G WD SATA 10k RAPTOR, 500GB WD SATA Enterprise
      • Graphics card(s):
      • Leadtek NVIDIA GeForce PX8800GTS 640MB
      • PSU:
      • CORSAIR HX 620W MODULAR PSU
      • Case:
      • Antec P182 Black Case
      • Monitor(s):
      • Dell 2407WPF A04
      • Internet:
      • domestic zoom
    Doesn't the SetInterval property just delay the inital run of the function you're calling? So after 500 ms the function is called, and then it just stops. Don't you need a loop in there to make sure the images keep changing, and the SetInterval just ensures there's a delay?
    sig removed by Zak33

  5. #5
    Ex-MSFT Paul Adams's Avatar
    Join Date
    Jul 2003
    Location
    %systemroot%
    Posts
    1,926
    Thanks
    29
    Thanked
    77 times in 59 posts
    • Paul Adams's system
      • Motherboard:
      • Asus Maximus VIII
      • CPU:
      • Intel Core i7-6700K
      • Memory:
      • 16GB
      • Storage:
      • 2x250GB SSD / 500GB SSD / 2TB HDD
      • Graphics card(s):
      • nVidia GeForce GTX1080
      • Operating System:
      • Windows 10 x64 Pro
      • Monitor(s):
      • Philips 40" 4K
      • Internet:
      • 500Mbps fiber
    I think the variable p is getting dynamically created when the subroutine is called, then destroyed on exiting - so it is always starting at 0, then being made 1 (0+1 mod 5) and then not being remembered on the next call.

    What happens if you put the variable declaration outside the subroutine, and initialise it?
    i.e.
    Code:
    <script language="vbs">
                    Dim p
                    p = 0
    
                    Sub Window_OnLoad
                        MyInterval = Window.SetInterval("PicRotate",500)
    		End Sub
                    Sub PicRotate
    		        p = (p+1) MOD 5
                            Select Case p
                                Case 1
                                    pic1.src = "images/hitler.jpg"
                                    pic2.src = "images/polpot.jpg"
                                    pic3.src = "images/saddam.jpg"
                                    pic4.src = "images/mussolini.jpg"
                                    pic5.src = "images/stalin.jpg"
    			    Case 2
                                    pic1.src = "images/polpot.jpg"
                                    pic2.src = "images/saddam.jpg"
                                    pic3.src = "images/mussolini.jpg"
                                    pic4.src = "images/stalin.jpg"
                                    pic5.src = "images/hitler.jpg"
                                Case 3
                                    pic1.src = "images/saddam.jpg"
                                    pic2.src = "images/mussolini.jpg"
                                    pic3.src = "images/stalin.jpg"
                                    pic4.src = "images/hitler.jpg"
                                    pic5.src = "images/polpot.jpg"
                                Case 4
                                    pic1.src = "images/mussolini.jpg"
                                    pic2.src = "images/stalin.jpg"
                                    pic3.src = "images/hitler.jpg"
                                    pic4.src = "images/polpot.jpg"
                                    pic5.src = "images/saddam.jpg"
                                Case 0
                                    pic1.src = "images/stalin.jpg"
                                    pic2.src = "images/hitler.jpg"
                                    pic3.src = "imaes/polpot.jpg"
                                    pic4.src = "images/saddam.jpg"
                                    pic5.src = "images/mussolini.jpg"
                            End Select
                    End Sub
                </script>
    ~ I have CDO. It's like OCD except the letters are in alphabetical order, as they should be. ~
    PC: Win10 x64 | Asus Maximus VIII | Core i7-6700K | 16GB DDR3 | 2x250GB SSD | 500GB SSD | 2TB SATA-300 | GeForce GTX1080
    Camera: Canon 60D | Sigma 10-20/4.0-5.6 | Canon 100/2.8 | Tamron 18-270/3.5-6.3

  6. #6
    Cable Guy Jonny M's Avatar
    Join Date
    Jul 2003
    Location
    Loughborough Uni
    Posts
    4,263
    Thanks
    0
    Thanked
    4 times in 1 post
    I think I love you Paul

    Cheers, that was exactly the problem. I'm looking forward to being able to uninstall Visual Studio 6 and forget about anything related to Visual Basic, and moving to C# next semester.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. msn / internet explorer script error
    By grimpy in forum Software
    Replies: 0
    Last Post: 21-05-2005, 07:35 PM
  2. Script to compare number in text files?
    By wasabi in forum Software
    Replies: 5
    Last Post: 09-05-2005, 04:10 PM
  3. Opening a ASP page with POST from a VB programm
    By GAteKeeper in forum Software
    Replies: 15
    Last Post: 25-01-2005, 04:35 PM
  4. USA/Canada ONLY: Free VB .NET 2003 Standard Edition
    By Atomic in forum Retail Therapy and Bargains
    Replies: 2
    Last Post: 31-05-2004, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •