Cor,
Thanks for your response. This is actually the second
time I posted the problem. The first post included the
code and a verbose description of the problem. It was
too long, too complex and I got no response. You are a
brave soul; here is the code I think probably contains my
bug. For brevity I've removed the code not relivant to
the bug.
Thanks again GrandpaB
Imports System.IO
Imports System.Collections
Imports System.Runtime.Serialization.Formatters.Soap
'*********************************************************
Public Class Form1 '***
'*****************************************************
Inherits System.Windows.Forms.Form
Public SGWArt As New classArt
#Region " Windows Form Designer generated code "
Private Sub Form1_Load(ByVal sender As System.Object,
_
ByVal e As System.EventArgs) Handles MyBase.Load
SGWArt.GetFile()
SGWArt.Indx = 0
Art2Form(SGWArt.Art)
StatusUpdate()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As
System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
SGWArt.Art = Form2Art()
SGWArt.SaveFile()
SGWArt = Nothing
Beep()
End Sub
Sub StatusUpdate()
StatusBar1.Text = "Object " + CStr(SGWArt.Indx +
1) + _
" of " + CStr(SGWArt.ArtCount)
End Sub
Sub Art2Form(ByVal MyArt As objArt)
With MyArt
tbTitle.Text = .Title
tbDesc.Text = .Des
pbPict.Text = .Pic
End With
DisplayJPG()
End Sub
Function Form2Art() As objArt
Dim MyArt As New objArt
With MyArt
.Title = tbTitle.Text
.Des = tbDesc.Text
.Pic = pbPict.Text
End With
Form2Art = MyArt
MyArt = Nothing
End Function
Private Sub BtnFirst_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles
BtnFirst.Click
'Save the contents of the form as an art object
and to
'SGWArt.art, set the index to 0, get and display
SGWArt
'atthe current index
SGWArt.Art = Form2Art()
SGWArt.Indx = 0
Art2Form(SGWArt.Art)
StatusUpdate()
End Sub
'Note: There are additional buttons that move to the
previous,
'next and last index. There are also buttons to add and
delete
'art objects. For brevity they're not shown.
Sub DisplayJPG()
Dim MyImage As Image
Dim MyWidth As Integer
Dim MyHeight As Integer
Dim pbArtSize As Integer
If System.IO.File.Exists(tbDesc.Text) Then
MyImage = Image.FromFile(tbDesc.Text)
pbArtSize = pbPict.Width 'Note pbArt must be
square
MyWidth = MyImage.Width
MyHeight = MyImage.Height
'Set the width & height of the thumbnail
If MyWidth > MyHeight Then
MyHeight = pbArtSize * MyHeight / MyWidth
MyWidth = pbArtSize
Else
MyWidth = pbArtSize * MyWidth / MyHeight
MyHeight = pbArtSize
End If
MyImage = MyImage.GetThumbnailImage(MyWidth,
MyHeight, _
Nothing, New IntPtr)
pbPict.Image = MyImage
Else
pbPict.Image = Nothing
End If
End Sub
Private Sub pbPict_DoubleClick(ByVal sender As
Object, _
ByVal e As System.EventArgs) Handles
pbPict.DoubleClick
If jpgDialog.ShowDialog = DialogResult.OK Then
tbDesc.Text = jpgDialog.FileName
DisplayJPG()
End If
End Sub
End Class
'*********************************************************
<[Serializable]()> Public Class objArt '***
'*****************************************************
Public Title As String
Public Des As String
Public Pic As String
End Class
'*********************************************************
Public Class classArt '***
'*****************************************************
Private Shared ArtList As New ArrayList
Private ArtIndex As Integer
Private ArtFileName As String = "art.xml"
Public Sub SaveFile() 'save ArtList to ArtFile
Dim Msg1 As String = "ArtFile was not saved!
Reason: "
Dim Msg2 As String = "Art"
Dim sf As New SoapFormatter
Dim fs As New FileStream(ArtFileName,
FileMode.Create)
Try
sf.Serialize(fs, ArtList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Critical, Msg2)
Finally
fs.Close()
End Try
End Sub
Public Sub GetFile() 'get ArtList from ArtFile
Dim Msg1 As String = "Failed to open ArtList!
Reason: "
Dim Msg2 As String = "Art"
If System.IO.File.Exists(ArtFileName) Then
Dim fs As New FileStream(ArtFileName,
FileMode.Open)
Dim sf As New SoapFormatter
Try
ArtList = CType(sf.Deserialize(fs),
ArrayList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Critical, Msg2)
Finally
fs.Close()
sf = Nothing
fs = Nothing
End Try
Else
AddArt()
End If
End Sub
Public Property Art() As objArt
Get
'return Art object from ArtList at current
index
Return ArtList.Item(ArtIndex)
End Get
Set(ByVal MyArt As objArt)
'put MyArt into ArtList at current index
ArtList.Item(ArtIndex) = MyArt
End Set
End Property
Public ReadOnly Property ArtCount() As Integer
Get
ArtCount = ArtList.Count
End Get
End Property
Public Property Indx() As Integer
Get
'return the current index for ArtList
Indx = ArtIndex
End Get
Set(ByVal Value As Integer)
'set Value as ArtIndex & fix errors
0<=Indx<ArtList.count
If Value < 0 Then Value = 0
If Value >= ArtList.Count Then Value =
ArtList.Count - 1
ArtIndex = Value
End Set
End Property
End Class