Hi all,

Hopefully someone can help me with this one as I've been trying to figure it out for the past several hours with no luck.

The idea is to scan a folder of images and then let the user navigate back and forth through the images using a couple of buttons.

The problem is, I can only get it to return a single image, and not the whole lot. It's looks to me as though the images are getting assigned to the same index in the array.

Does anyone see where I'm going wrong?

Public Class frm_PicViewer

    Dim i As Integer
    Dim lastImage As Integer
    Dim imagecount As Integer
    Dim fileName(i) As String
    Dim imgname(i) As System.Drawing.Image

    Private Sub frm_PicViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim di As New IO.DirectoryInfo("D:\Images\Miscellaneous\")
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo
        For Each dra In diar1

            If dra.Name.Contains("jpg") Or dra.Name.Contains("gif") Or dra.Name.Contains("png") Or dra.Name.Contains("bmp") Then

                imgname(i) = System.Drawing.Image.FromFile(dra.FullName)

            End If

        Next dra
        pctDisplay.Image = New Bitmap(imgname(i))

    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

        If i = lastImage Then
            MsgBox("This is the last Image")
        Else
            i = i + 1
            pctDisplay.Image = Bitmap.FromFile(fileName(i))
        End If

    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click

        If i = 0 Then
            MsgBox("This is the first Image")
        Else
            i = i - 1
            pctDisplay.Image = Bitmap.FromFile(fileName(i))
            MsgBox(i)
        End If

    End Sub
End Class

Hope someone can help as it's driving me insane.

Thanks
TheMightySpud

imgname(i) = System.Drawing.Image.FromFile(dra.FullName)

You have to increase i-variable within the loop

I've tried adding the line

i=i+1

inside the loop with the same result. it's very weird as the program really doesn't reem to like me doing that. :-/

TheMightySpud

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.