Got this assignment in my VB .NET class. The program's basically a picture
viewer that lets you add your pictures to an array so you can cycle through
them once the file's been opened. So you open the file, it displays, then
you can select "add to list" from a menu. Anyway, I'm pretty sure the
filenames are being added to the array, and I can go directly to the first
and last images in the array by using the appropriate menu options, but I
can't get my "next" and "previous" options to work. I figured it'd be a
simple matter of incrementing or decrementing the array counter, and opening
the file who's name is stored at that position. Apparently not.
Here's the relevant code:
Private Sub mnuBrowse_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuBrowse.Click
' Opens an image file to be displayed. Works fine.
With opdPictureBox
.Title = "Select a Car to View"
.InitialDirectory = "C:\CarDealer\pictures"
.CheckFileExists = True
.Filter = "Picture Files (*.jpg)|*.jpg|All Files (*.*)|*.*)"
.ShowDialog()
picDisplay.Image = Image.FromFile(.FileName)
strCarName = .FileName
stbInfo.Text = strCarName
End With
End Sub
Private Sub mnuAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuAdd.Click
' Adds image path and filename to array. seems to work.
strShortList(index) = strCarName
index = index + 1
End Sub
Private Sub mnuPrevious_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPrevious.Click
' Views previous image in array... doesn't work
If i > 0 Then
viewCar = i - 1
picDisplay.Image = Image.FromFile(strShortList(viewCar))
Else
picDisplay.Image = Image.FromFile(strShortList(0))
End If
End Sub
Private Sub mnuNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuNext.Click
' views next image in array... doesn't work
If i < 9 Then
viewCar = i + 1
picDisplay.Image = Image.FromFile(strShortList(viewCar))
Else
picDisplay.Image = Image.FromFile(strShortList(i - 1))
End If
End Sub