473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Elusive Bug

I have a baffling application bug. Any clues you could
offer to help me squash this bug would be greatly
appreciated.

My application saves the contents of the form, as an
object to arrayList. The form contains buttons so that I
can navigate through all the objects and also add and
delete objects. When the application is opened or
closed, an XML file, using the SoapFormatter is read or
written to the hard drive. The application works well.
ALMOST.

One of the controls on the form is a picture box. Double
clicking the picture box opens the OpenFile dialog so
that a JPEG can be displayed in the picture box. After
invoking the OpenFile dialog I can navigate to other
objects in the arrayList and return. The file name for
the JPEG image has been has been saved in the arrayList
and the picture displays as designed.

However, when I close the application the arrayList is
NOT written to the hard drive if I had invoked the
OpenFile dialog.. If I manually edit the textbox that
contains the JPEG file name, the JPEG image changes and
the file IS written to the hard drive.

This mystery has had me bamboozled for a couple of weeks;
thanks in advance for any suggestions.

GrandpaB

Nov 21 '05 #1
9 1102
GrandPa,

For me it seems if you use for a simple problem a difficult solution.

Can you explain to us why to make it more clear why you do that or show some
code.

The reason for this is, that when a solution sounds difficult than helping
is even more difficult.

Cor
Nov 21 '05 #2
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

Nov 21 '05 #3
Grandpa,

I looked at your code, however first, why do you want to use SOAP, what is
the special reason thay you do not serialize your graph (what I did not see
in your code) using the bytearray?

Cor
Nov 21 '05 #4
Cor,

Thanks again for looking at the code. Being new to
VB.Net I used the first example that I found that
appeared to solve the problem. Because SOAP wrote an XML
file it also allowed me to open the file in my browser
and easily observe what was being written.

If there is a better way to create a file, I'm willing to
learn and to try it. However it does not seem as if SOAP
is the cause of the bug. I am not familiar with the
bytearray, but I will read about it and the graph term
that you used.

GrandpaB
Nov 21 '05 #5
GrandpaB.

I did a long time not something with office, however can you look at this
"Graphic" sample I once made for images and datasets (which is directly
XML).

http://groups-beta.google.com/group/...441bf975e8834d

I stopped with Soap after that the first version from Microsoft WSDL was
completly renewed, I have expiriences when Mifrosoft does that. In VSNet
webservices everything about that is completly automaticly done.

Do you want information about Soap than one of the webservices newsgroup is
in my opinion a better place. I have seldom seen it in this newsgroup.

Cor
Nov 21 '05 #6
Cor,

Again thanks for your insights. The application that I'm
try to debug does not store the JPEG image in the data
file. What is stored is the filename and path of the
image.

If I double click the picture box, pbPict, I can load a
new filename and path into the textbox, tbDesc through
the OpenFile dialog, jpgDialog. The selected JPEG image
is displayed in pbPict. However, when I close the
application the arrayList, ArtList, is not saved to the
hard drive. If type the filename and path into the
textbox, tbDesc, ArtList is saved to the hard drive when
the application closes.

I am beginning to look at your code on the google site,
but I believe it adds the image to the output file. My
appliction only needs the filename and path saved in the
output file.

Thanks, GrandpaB
Nov 21 '05 #7
Cor,

I have rewritten the application and reduced it to the
bare essentials that create the error and still the error
remains. I have then tried using the binaryFormatter
instead of the SoapFormatter and I get the same error. I
strongly suspect that this is a valid .NET 2003 bug!

I have made a new post on this newsgroup as a possible
bug.

Thanks for your help, GrandpaB
Nov 21 '05 #8
GrandPa,

Than it is even easier when you use that.

Cor
Nov 21 '05 #9
Thanks to a MVP who identified the problem.

When my application opened the OpenFileDialog it changed
the default directory. Then when the application closed
and wrote the data file it was written to the directory
last used in the OpenFileDialog. The fix, suggested by
the MVP, was to change the OpenFileDialog
RestoreDirectory property from False to True. Now the
original default directory is restored when the dialog
closes.

Thanks, to all who offered suggestions to help solve this
problem.

GrandpaB
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: dan | last post by:
I really have two related questions. 1) Is it possible (without recompiling and changing the core Python behavior) to write functions that utilize the same syntax as built-in functions? IE, can...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
0
by: Geraldine | last post by:
When I run my asp.net application on a web farm I get the following error "The viewstate is invalid for this page and might be corrupted" Microsoft Knowledge Base artice 323744 talks of this...
0
by: Geraldine | last post by:
When I run my asp.net application on a web farm I get the following error "The viewstate is invalid for this page and might be corrupted" Microsoft Knowledge Base artice 323744 talks of this...
26
by: Swroteb | last post by:
Hi there, I've got a reasonably sized list of objects that I'd like to pull out all combinations of five elements from. Right now I have a way to do this that's quite slow, but manageable. I...
1
by: Chris Ashley | last post by:
I seem to be getting an elusive Javascript error on all my ASPX pages... apparently it's on line 4, char 1, but I don't see anything there. Example: ...
10
by: Jeff Shepler | last post by:
This is probably not the right newsgroup for this, but this is the only one I read and there are a lot of smart people that "live" here. Please don't berate me if you think this should have been...
11
by: Jang | last post by:
Does anyone have an example of well written JavaScript applications that they know about? I would prefer the code to be readable. I particularly like YUI's code. Does anyone have any more...
2
by: kurt sune | last post by:
I am having trouble with hover and <p>. I have reduced the problem to this: Given a HTML-page like this: <body> <a>Number1</a> <div id="content">
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.