473,805 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1121
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.Collecti ons
Imports System.Runtime. Serialization.F ormatters.Soap

'************** *************** *************** *************
Public Class Form1 '***
'************** *************** *************** *********
Inherits System.Windows. Forms.Form
Public SGWArt As New classArt

#Region " Windows Form Designer generated code "

Private Sub Form1_Load(ByVa l sender As System.Object,
_
ByVal e As System.EventArg s) Handles MyBase.Load
SGWArt.GetFile( )
SGWArt.Indx = 0
Art2Form(SGWArt .Art)
StatusUpdate()
End Sub

Private Sub Form1_Closing(B yVal sender As Object, _
ByVal e As
System.Componen tModel.CancelEv entArgs) _
Handles MyBase.Closing
SGWArt.Art = Form2Art()
SGWArt.SaveFile ()
SGWArt = Nothing
Beep()
End Sub

Sub StatusUpdate()
StatusBar1.Text = "Object " + CStr(SGWArt.Ind x +
1) + _
" of " + CStr(SGWArt.Art Count)
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.EventArg s) 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.T ext) 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.GetThum bnailImage(MyWi dth,
MyHeight, _
Nothing, New IntPtr)
pbPict.Image = MyImage
Else
pbPict.Image = Nothing
End If
End Sub

Private Sub pbPict_DoubleCl ick(ByVal sender As
Object, _
ByVal e As System.EventArg s) Handles
pbPict.DoubleCl ick
If jpgDialog.ShowD ialog = DialogResult.OK Then
tbDesc.Text = jpgDialog.FileN ame
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(ArtF ileName,
FileMode.Create )
Try
sf.Serialize(fs , ArtList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Cri tical, 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(ArtFileN ame) Then
Dim fs As New FileStream(ArtF ileName,
FileMode.Open)
Dim sf As New SoapFormatter
Try
ArtList = CType(sf.Deseri alize(fs),
ArrayList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Cri tical, 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(Ar tIndex)
End Get
Set(ByVal MyArt As objArt)
'put MyArt into ArtList at current index
ArtList.Item(Ar tIndex) = 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
RestoreDirector y 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
2923
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 I create a function that does this: >>>printCaps "hello" #note no parentheses HELLO
166
8698
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
986
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 problem and mentions a hotfix which is not available on the web site. Has any-one else resolved this problem ? Does any-one know where I can download the Hotfix from ? Any Advice on ways around?
0
1194
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 problem and mentions a hotfix which is not available on the web site. Has any-one else resolved this problem ? Does any-one know where I can download the Hotfix from ? Any Advice on ways around?
26
2218
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 know there must be a better way to do this, but I'm not sure what it is. Here's what I've got so far: for a in myList: for b in myList:
1
1469
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: http://www.google.com/url?sa=D&q=http://www.webmoney.co.uk/heath-home-test/quote/step1_generalquesions.aspx%3Fbid%3D1002 Anybody have any ideas?
10
6646
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 posted in another newsgroup. The web application I'm currently working on will (seemingly) randomly throw an exception when opening a database connection. Not always in the same place. Not always the same SqlConnection object. Not always the...
11
2001
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 applications/ examples? Thanks .
2
1312
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
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10104
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.