What's wrong with my code??

Biohazard

Well-known member
Joined
Nov 23, 2009
Messages
52
Programming Experience
5-10
So it works, shows the images in the sequence like I want it to (Essentially a video clip working via PNG files and loops, however, the first 16 pictures are skiped on the first run, instead it shows a tiny img error picture)

Here is the image sequence function
VB.NET:
    Public Function NumberSeq(ByRef Img As PictureBox, ByRef picNum As Integer, ByVal currentticks As Integer)
        PicNum = currentticks + 1
        If picNum = 1 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\00.png"
        If picNum = 2 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\01.png"
        If picNum = 3 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\02.png"
        If picNum = 4 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\03.png"
        If picNum = 5 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\04.png"
        If picNum = 6 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\05.png"
        If picNum = 7 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\06.png"
        If picNum = 8 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\07.png"
        If picNum = 9 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\08.png"
        If picNum = 10 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\09.png"
        If picNum = 11 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\10.png"
        If picNum = 12 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\11.png"
        If picNum = 13 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\12.png"
        If picNum = 14 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\13.png"
        If picNum = 15 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\00\14.png"
        'Folder2
        If picNum = 16 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\00.png"
        If picNum = 17 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\01.png"
        If picNum = 18 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\02.png"
        If picNum = 19 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\03.png"
        If picNum = 20 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\04.png"
        If picNum = 21 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\05.png"
        If picNum = 22 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\06.png"
        If picNum = 23 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\07.png"
        If picNum = 24 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\08.png"
        If picNum = 25 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\09.png"
        If picNum = 26 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\10.png"
        If picNum = 27 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\11.png"
        If picNum = 28 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\12.png"
        If picNum = 29 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\13.png"
        If picNum = 30 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\01\14.png"
        'Folder3
        If picNum = 31 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\00.png"
        If picNum = 32 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\01.png"
        If picNum = 33 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\02.png"
        If picNum = 34 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\03.png"
        If picNum = 35 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\04.png"
        If picNum = 36 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\05.png"
        If picNum = 37 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\06.png"
        If picNum = 38 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\07.png"
        If picNum = 39 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\08.png"
        If picNum = 40 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\09.png"
        If picNum = 41 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\10.png"
        If picNum = 42 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\11.png"
        If picNum = 43 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\12.png"
        If picNum = 44 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\13.png"
        If picNum = 45 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\02\14.png"
        'Folder 4
        If picNum = 46 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\00.png"
        If picNum = 47 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\01.png"
        If picNum = 48 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\02.png"
        If picNum = 49 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\03.png"
        If picNum = 50 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\04.png"
        If picNum = 51 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\05.png"
        If picNum = 52 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\06.png"
        If picNum = 53 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\07.png"
        If picNum = 54 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\08.png"
        If picNum = 55 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\09.png"
        If picNum = 56 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\10.png"
        If picNum = 57 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\11.png"
        If picNum = 58 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\12.png"
        If picNum = 59 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\13.png"
        If picNum = 60 Then Img.ImageLocation = Application.StartupPath & "\Data\Countdown\03\14.png"
        If picNum = 60 Then picNum = 0
        Return 0
    End Function

Here is the timer sub that calls the function
VB.NET:
Public Class Form1
    Dim intpic As Integer
    Dim currentticks As Integer = 0
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        NumberSeq(PictureBox1, intpic, currentticks)
        currentticks = intpic

    End Sub

End Class

ANY IDEAS???
 
If an error image is displayed it's because the specified image file can't be found.

As for that code, you can get rid of that long list of repetitive code with a little bit of calculation:
VB.NET:
Dim folderNum = (picNum - 1) \ 15
Dim fileNum = (picNum - 1) Mod 15

[COLOR="Red"]If Img.Image IsNot Nothing Then
    Img.Image.Dispose()
End If[/COLOR]

Img.ImageLocation = String.Format("{0}\Data\Countdown\{1:00}\{2:00}.png", Application.StartupPath, folderNum, fileNum)
Note the part that is highlighted. If you don't do that then your app is causing a resource leak. When you're finished with each Image object you need to release its resources back to the system.
 

Latest posts

Back
Top